mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Random refactors I had forgotten about
This commit is contained in:
parent
5fae98989e
commit
3b906699bc
5 changed files with 38 additions and 27 deletions
|
@ -17,7 +17,7 @@ public class SpawnAttackBehavior extends Behavior {
|
||||||
protected float frequency = 1;
|
protected float frequency = 1;
|
||||||
protected float range = 15;
|
protected float range = 15;
|
||||||
protected Object burst;
|
protected Object burst;
|
||||||
protected long lastAttackAt;;
|
protected long lastAttackAt;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public SpawnAttackBehavior(@JacksonInject Npc entity) {
|
public SpawnAttackBehavior(@JacksonInject Npc entity) {
|
||||||
|
|
|
@ -528,7 +528,7 @@ public class Player extends Entity implements CommandExecutor {
|
||||||
|
|
||||||
if(!(item.getUse(ItemUseType.SWITCHED) instanceof String)) {
|
if(!(item.getUse(ItemUseType.SWITCHED) instanceof String)) {
|
||||||
int mod = zone.getBlock(pX, pY).getFrontMod();
|
int mod = zone.getBlock(pX, pY).getFrontMod();
|
||||||
zone.updateBlock(x, y, Layer.FRONT, item, mod, null, null);
|
zone.updateBlock(x, y, Layer.FRONT, item, mod, null, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
linked = true;
|
linked = true;
|
||||||
|
|
|
@ -171,10 +171,9 @@ public class BlockUseRequest extends PlayerRequest {
|
||||||
if(data == null) {
|
if(data == null) {
|
||||||
if(metaBlock != null) {
|
if(metaBlock != null) {
|
||||||
// TODO timed switches
|
// TODO timed switches
|
||||||
|
|
||||||
zone.updateBlock(x, y, layer, item, mod % 2 == 0 ? mod + 1 : mod - 1, player, null);
|
|
||||||
Map<String, Object> metadata = metaBlock.getMetadata();
|
Map<String, Object> metadata = metaBlock.getMetadata();
|
||||||
List<List<Integer>> positions = MapHelper.getList(metadata, ">", Collections.emptyList());
|
List<List<Integer>> positions = MapHelper.getList(metadata, ">", Collections.emptyList());
|
||||||
|
zone.updateBlock(x, y, layer, item, mod % 2 == 0 ? mod + 1 : mod - 1, player, metadata);
|
||||||
|
|
||||||
for(List<Integer> position : positions) {
|
for(List<Integer> position : positions) {
|
||||||
int sX = position.get(0);
|
int sX = position.get(0);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class CraftRequest extends PlayerRequest {
|
||||||
|
|
||||||
// Check if required crafting helpers are nearby
|
// Check if required crafting helpers are nearby
|
||||||
if(item.requiresWorkshop()) {
|
if(item.requiresWorkshop()) {
|
||||||
List<MetaBlock> workshop = player.getZone().getMetaBlocksWhere(metaBlock
|
List<MetaBlock> workshop = player.getZone().getMetaBlocks(metaBlock
|
||||||
-> MathUtils.inRange(player.getX(), player.getY(), metaBlock.getX(), metaBlock.getY(), 10));
|
-> MathUtils.inRange(player.getX(), player.getY(), metaBlock.getX(), metaBlock.getY(), 10));
|
||||||
|
|
||||||
for(CraftingRequirement craftingHelper : item.getCraftingHelpers()) {
|
for(CraftingRequirement craftingHelper : item.getCraftingHelpers()) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
|
||||||
|
@ -616,7 +617,7 @@ public class Zone {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBlock(int x, int y, Layer layer, int item, int mod, Player owner) {
|
public void updateBlock(int x, int y, Layer layer, int item, int mod, Player owner) {
|
||||||
updateBlock(x, y, layer, ItemRegistry.getItem(item), mod, owner, new HashMap<>());
|
updateBlock(x, y, layer, item, mod, owner, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBlock(int x, int y, Layer layer, int item, int mod, Player owner, Map<String, Object> metadata) {
|
public void updateBlock(int x, int y, Layer layer, int item, int mod, Player owner, Map<String, Object> metadata) {
|
||||||
|
@ -632,7 +633,7 @@ public class Zone {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBlock(int x, int y, Layer layer, Item item, int mod, Player owner) {
|
public void updateBlock(int x, int y, Layer layer, Item item, int mod, Player owner) {
|
||||||
updateBlock(x, y, layer, item, mod, owner, new HashMap<>());
|
updateBlock(x, y, layer, item, mod, owner, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBlock(int x, int y, Layer layer, Item item, int mod, Player owner, Map<String, Object> metadata) {
|
public void updateBlock(int x, int y, Layer layer, Item item, int mod, Player owner, Map<String, Object> metadata) {
|
||||||
|
@ -650,9 +651,13 @@ public class Zone {
|
||||||
updateBlock(x, y, Layer.LIQUID, Item.AIR, 0);
|
updateBlock(x, y, Layer.LIQUID, Item.AIR, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(metadata != null && item.hasMeta()) {
|
if(item.hasMeta()) {
|
||||||
|
if(metadata == null) {
|
||||||
|
setMetaBlock(x, y, item, owner, new HashMap<>());
|
||||||
|
} else {
|
||||||
setMetaBlock(x, y, item, owner, metadata);
|
setMetaBlock(x, y, item, owner, metadata);
|
||||||
} else if(!item.hasMeta() && metaBlocks.containsKey(getBlockIndex(x, y))) {
|
}
|
||||||
|
} else if(metaBlocks.containsKey(getBlockIndex(x, y))) {
|
||||||
setMetaBlock(x, y, 0);
|
setMetaBlock(x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -778,31 +783,38 @@ public class Zone {
|
||||||
return metaBlocks.get(index);
|
return metaBlocks.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MetaBlock> getMetaBlocksWithUse(ItemUseType useType){
|
|
||||||
return getMetaBlocksWhere(block -> block.getItem().hasUse(useType));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MetaBlock> getLocalMetaBlocksInChunk(int chunkIndex) {
|
|
||||||
return getMetaBlocksWhere(block -> block.getItem().getMeta() == MetaType.LOCAL && chunkIndex == getChunkIndex(block.getX(), block.getY()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MetaBlock> getMetaBlocksWhere(Predicate<MetaBlock> predicate) {
|
|
||||||
List<MetaBlock> metaBlocks = new ArrayList<>(this.metaBlocks.values());
|
|
||||||
metaBlocks.removeIf(predicate.negate());
|
|
||||||
return metaBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetaBlock getRandomSpawnBlock() {
|
public MetaBlock getRandomSpawnBlock() {
|
||||||
List<MetaBlock> spawnBlocks = getMetaBlocksWhere(block -> block.getItem().getId() == 891 || block.getItem().getId() == 934);
|
List<MetaBlock> spawnBlocks = getMetaBlocks(block -> block.getItem().getId() == 891 || block.getItem().getId() == 934);
|
||||||
return spawnBlocks.isEmpty() ? null : spawnBlocks.get((int)(Math.random() * spawnBlocks.size()));
|
return spawnBlocks.isEmpty() ? null : spawnBlocks.get((int)(Math.random() * spawnBlocks.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MetaBlock> getMetaBlocksWithUse(ItemUseType useType) {
|
||||||
|
return getMetaBlocks(metaBlock -> metaBlock.getItem().hasUse(useType));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MetaBlock> getMetaBlocksWithItem(Item item) {
|
||||||
|
return getMetaBlocksWithItem(item.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MetaBlock> getMetaBlocksWithItem(int item) {
|
||||||
|
return getMetaBlocks(metaBlock -> metaBlock.getItem().getId() == item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MetaBlock> getMetaBlocks(Predicate<MetaBlock> predicate) {
|
||||||
|
return metaBlocks.values().stream().filter(predicate).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<MetaBlock> getMetaBlocks() {
|
public Collection<MetaBlock> getMetaBlocks() {
|
||||||
return metaBlocks.values();
|
return Collections.unmodifiableCollection(metaBlocks.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MetaBlock> getLocalMetaBlocksInChunk(int chunkIndex) {
|
||||||
|
return getMetaBlocks(block -> block.getItem().getMeta() == MetaType.LOCAL
|
||||||
|
&& chunkIndex == getChunkIndex(block.getX(), block.getY()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<MetaBlock> getGlobalMetaBlocks() {
|
public Collection<MetaBlock> getGlobalMetaBlocks() {
|
||||||
return globalMetaBlocks.values();
|
return Collections.unmodifiableCollection(globalMetaBlocks.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Entity> getEntitiesInRange(float x, float y, float range) {
|
public List<Entity> getEntitiesInRange(float x, float y, float range) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue