diff --git a/gameserver/src/main/java/brainwine/gameserver/behavior/parts/SpawnAttackBehavior.java b/gameserver/src/main/java/brainwine/gameserver/behavior/parts/SpawnAttackBehavior.java index 99010b2..6f7a7fd 100644 --- a/gameserver/src/main/java/brainwine/gameserver/behavior/parts/SpawnAttackBehavior.java +++ b/gameserver/src/main/java/brainwine/gameserver/behavior/parts/SpawnAttackBehavior.java @@ -17,7 +17,7 @@ public class SpawnAttackBehavior extends Behavior { protected float frequency = 1; protected float range = 15; protected Object burst; - protected long lastAttackAt;; + protected long lastAttackAt; @JsonCreator public SpawnAttackBehavior(@JacksonInject Npc entity) { diff --git a/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java b/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java index 4850a9c..f101ee8 100644 --- a/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java +++ b/gameserver/src/main/java/brainwine/gameserver/entity/player/Player.java @@ -528,7 +528,7 @@ public class Player extends Entity implements CommandExecutor { if(!(item.getUse(ItemUseType.SWITCHED) instanceof String)) { 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; diff --git a/gameserver/src/main/java/brainwine/gameserver/server/requests/BlockUseRequest.java b/gameserver/src/main/java/brainwine/gameserver/server/requests/BlockUseRequest.java index 23df2f6..5f15d20 100644 --- a/gameserver/src/main/java/brainwine/gameserver/server/requests/BlockUseRequest.java +++ b/gameserver/src/main/java/brainwine/gameserver/server/requests/BlockUseRequest.java @@ -171,10 +171,9 @@ public class BlockUseRequest extends PlayerRequest { if(data == null) { if(metaBlock != null) { // TODO timed switches - - zone.updateBlock(x, y, layer, item, mod % 2 == 0 ? mod + 1 : mod - 1, player, null); Map metadata = metaBlock.getMetadata(); List> positions = MapHelper.getList(metadata, ">", Collections.emptyList()); + zone.updateBlock(x, y, layer, item, mod % 2 == 0 ? mod + 1 : mod - 1, player, metadata); for(List position : positions) { int sX = position.get(0); diff --git a/gameserver/src/main/java/brainwine/gameserver/server/requests/CraftRequest.java b/gameserver/src/main/java/brainwine/gameserver/server/requests/CraftRequest.java index f0fb48c..2352ee3 100644 --- a/gameserver/src/main/java/brainwine/gameserver/server/requests/CraftRequest.java +++ b/gameserver/src/main/java/brainwine/gameserver/server/requests/CraftRequest.java @@ -46,7 +46,7 @@ public class CraftRequest extends PlayerRequest { // Check if required crafting helpers are nearby if(item.requiresWorkshop()) { - List workshop = player.getZone().getMetaBlocksWhere(metaBlock + List workshop = player.getZone().getMetaBlocks(metaBlock -> MathUtils.inRange(player.getX(), player.getY(), metaBlock.getX(), metaBlock.getY(), 10)); for(CraftingRequirement craftingHelper : item.getCraftingHelpers()) { diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java b/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java index 12362de..070499a 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java @@ -15,6 +15,7 @@ import java.util.Random; import java.util.Set; import java.util.UUID; import java.util.function.Predicate; +import java.util.stream.Collectors; 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) { - 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 metadata) { @@ -632,7 +633,7 @@ public class Zone { } 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 metadata) { @@ -650,9 +651,13 @@ public class Zone { updateBlock(x, y, Layer.LIQUID, Item.AIR, 0); } - if(metadata != null && item.hasMeta()) { - setMetaBlock(x, y, item, owner, metadata); - } else if(!item.hasMeta() && metaBlocks.containsKey(getBlockIndex(x, y))) { + if(item.hasMeta()) { + if(metadata == null) { + setMetaBlock(x, y, item, owner, new HashMap<>()); + } else { + setMetaBlock(x, y, item, owner, metadata); + } + } else if(metaBlocks.containsKey(getBlockIndex(x, y))) { setMetaBlock(x, y, 0); } @@ -778,31 +783,38 @@ public class Zone { return metaBlocks.get(index); } - public List getMetaBlocksWithUse(ItemUseType useType){ - return getMetaBlocksWhere(block -> block.getItem().hasUse(useType)); - } - - public List getLocalMetaBlocksInChunk(int chunkIndex) { - return getMetaBlocksWhere(block -> block.getItem().getMeta() == MetaType.LOCAL && chunkIndex == getChunkIndex(block.getX(), block.getY())); - } - - public List getMetaBlocksWhere(Predicate predicate) { - List metaBlocks = new ArrayList<>(this.metaBlocks.values()); - metaBlocks.removeIf(predicate.negate()); - return metaBlocks; - } - public MetaBlock getRandomSpawnBlock() { - List spawnBlocks = getMetaBlocksWhere(block -> block.getItem().getId() == 891 || block.getItem().getId() == 934); + List spawnBlocks = getMetaBlocks(block -> block.getItem().getId() == 891 || block.getItem().getId() == 934); return spawnBlocks.isEmpty() ? null : spawnBlocks.get((int)(Math.random() * spawnBlocks.size())); } + public List getMetaBlocksWithUse(ItemUseType useType) { + return getMetaBlocks(metaBlock -> metaBlock.getItem().hasUse(useType)); + } + + public List getMetaBlocksWithItem(Item item) { + return getMetaBlocksWithItem(item.getId()); + } + + public List getMetaBlocksWithItem(int item) { + return getMetaBlocks(metaBlock -> metaBlock.getItem().getId() == item); + } + + public List getMetaBlocks(Predicate predicate) { + return metaBlocks.values().stream().filter(predicate).collect(Collectors.toList()); + } + public Collection getMetaBlocks() { - return metaBlocks.values(); + return Collections.unmodifiableCollection(metaBlocks.values()); + } + + public List getLocalMetaBlocksInChunk(int chunkIndex) { + return getMetaBlocks(block -> block.getItem().getMeta() == MetaType.LOCAL + && chunkIndex == getChunkIndex(block.getX(), block.getY())); } public Collection getGlobalMetaBlocks() { - return globalMetaBlocks.values(); + return Collections.unmodifiableCollection(globalMetaBlocks.values()); } public List getEntitiesInRange(float x, float y, float range) {