From 062d3759be40f4d8e49626290785e89eb720c4a0 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Fri, 22 Nov 2019 15:13:02 -0300 Subject: [PATCH] Use primitive types in Position and BlockFace, remove world block connections on Sponge, clean code in 1.8 entity tracker, add constructor for cloning Item and Position --- .../BukkitBlockConnectionProvider.java | 6 +- .../ViaVersion/api/minecraft/BlockFace.java | 16 +++--- .../ViaVersion/api/minecraft/Position.java | 55 +++++++++++++++--- .../ViaVersion/api/minecraft/item/Item.java | 4 ++ .../types/minecraft/Position1_14Type.java | 6 +- .../type/types/minecraft/PositionType.java | 6 +- .../Protocol1_13To1_12_2.java | 27 +++------ .../blockconnections/ConnectionData.java | 28 ++++----- .../packets/WorldPackets.java | 20 +++---- .../storage/BlockConnectionStorage.java | 4 +- .../Protocol1_9_3To1_9_1_2.java | 6 +- .../packets/WorldPackets.java | 8 +-- .../storage/CommandBlockStorage.java | 6 +- .../storage/EntityTracker1_9.java | 18 +++--- .../sponge/platform/SpongeViaConfig.java | 9 ++- .../sponge/platform/SpongeViaLoader.java | 5 -- .../SpongeBlockConnectionProvider.java | 57 ------------------- 17 files changed, 131 insertions(+), 150 deletions(-) delete mode 100644 sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java index 7e487c456..7d072ad6e 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/providers/BukkitBlockConnectionProvider.java @@ -21,11 +21,11 @@ public class BukkitBlockConnectionProvider extends BlockConnectionProvider { Player player = Bukkit.getPlayer(uuid); if (player != null) { World world = player.getWorld(); - int x = (int) (position.getX() >> 4); - int z = (int) (position.getZ() >> 4); + int x = position.getPosX() >> 4; + int z = position.getPosZ() >> 4; if (world.isChunkLoaded(x, z)) { Chunk c = getChunk(world, x, z); - Block b = c.getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); + Block b = c.getBlock(position.getPosX(), position.getPosY(), position.getPosZ()); return b.getTypeId() << 4 | b.getData(); } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java index a17129550..c217979cb 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockFace.java @@ -9,12 +9,12 @@ import java.util.Map; @Getter @AllArgsConstructor public enum BlockFace { - NORTH(0, 0, -1, EnumAxis.Z), - SOUTH(0, 0, 1, EnumAxis.Z), - EAST(1, 0, 0, EnumAxis.X), - WEST(-1, 0, 0, EnumAxis.X), - TOP(0, 1, 0, EnumAxis.Y), - BOTTOM(0, -1, 0, EnumAxis.Y); + NORTH((byte) 0, (byte) 0, (byte) -1, EnumAxis.Z), + SOUTH((byte) 0, (byte) 0, (byte) 1, EnumAxis.Z), + EAST((byte) 1, (byte) 0, (byte) 0, EnumAxis.X), + WEST((byte) -1, (byte) 0, (byte) 0, EnumAxis.X), + TOP((byte) 0, (byte) 1, (byte) 0, EnumAxis.Y), + BOTTOM((byte) 0, (byte) -1, (byte) 0, EnumAxis.Y); private static Map opposites = new HashMap<>(); @@ -27,7 +27,7 @@ public enum BlockFace { opposites.put(BlockFace.BOTTOM, BlockFace.TOP); } - private int modX, modY, modZ; + private byte modX, modY, modZ; private EnumAxis axis; public BlockFace opposite() { @@ -35,6 +35,6 @@ public enum BlockFace { } public enum EnumAxis { - X, Y, Z; + X, Y, Z } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java index 77653848a..a9dec12b3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/Position.java @@ -10,18 +10,59 @@ import lombok.ToString; @ToString @EqualsAndHashCode public class Position { - private Long x; - private Long y; - private Long z; + private int posX; + private short posY; + private int posZ; + + @Deprecated + public Position(Long x, Long y, Long z) { + this.posX = x.intValue(); + this.posY = y.shortValue(); + this.posZ = z.intValue(); + } + + public Position(Position toCopy) { + this(toCopy.getPosX(), toCopy.getPosY(), toCopy.getPosZ()); + } + + @Deprecated + public void setX(Long x) { + this.posX = x.intValue(); + } + + @Deprecated + public void setY(Long y) { + this.posY = y.shortValue(); + } + + @Deprecated + public void setZ(Long z) { + this.posZ = z.intValue(); + } + + @Deprecated + public Long getX() { + return (long) this.posX; + } + + @Deprecated + public Long getY() { + return (long) this.posY; + } + + @Deprecated + public Long getZ() { + return (long) this.posZ; + } public Position getRelative(BlockFace face) { - return new Position(this.x + face.getModX(), this.y + face.getModY(), this.z + face.getModZ()); + return new Position(posX + face.getModX(), (short) (posY + face.getModY()), posZ + face.getModZ()); } public Position shift(BlockFace face) { - this.x += face.getModX(); - this.y += face.getModY(); - this.z += face.getModZ(); + this.posX += face.getModX(); + this.posY += face.getModY(); + this.posZ += face.getModZ(); return this; } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java index 8a47bcaa5..be2e260f8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java @@ -34,4 +34,8 @@ public class Item { this.data = data; this.tag = tag; } + + public Item(Item toCopy) { + this(toCopy.getIdentifier(), toCopy.getAmount(), toCopy.getData(), toCopy.getTag()); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java index fe4d2a3f6..f7fda5298 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/Position1_14Type.java @@ -17,11 +17,13 @@ public class Position1_14Type extends Type { long y = val << 52 >> 52; long z = val << 26 >> 38; - return new Position(x, y, z); + return new Position((int) x, (short) y, (int) z); } @Override public void write(ByteBuf buffer, Position object) { - buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | (object.getY() & 0xfff) | ((object.getZ() & 0x3ffffff) << 12)); + buffer.writeLong((((long) object.getPosX() & 0x3ffffff) << 38) + | (object.getPosY() & 0xfff) + | ((object.getPosZ() & 0x3ffffff) << 12)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java index 6079982be..8857579fe 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/minecraft/PositionType.java @@ -17,11 +17,13 @@ public class PositionType extends Type { // this shifting madness is used to preserve sign long z = (val << 38) >> 38; // signed - return new Position(x, y, z); + return new Position((int) x, (short) y, (int) z); } @Override public void write(ByteBuf buffer, Position object) { - buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | ((object.getY() & 0xfff) << 26) | (object.getZ() & 0x3ffffff)); + buffer.writeLong((((long) object.getPosX() & 0x3ffffff) << 38) + | ((object.getPosY() & 0xfff) << 26) + | (object.getPosZ() & 0x3ffffff)); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 61c8eae58..280528218 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -47,9 +47,9 @@ public class Protocol1_13To1_12_2 extends Protocol { @Override public void handle(PacketWrapper wrapper) throws Exception { Position position = wrapper.read(Type.POSITION); - wrapper.write(Type.INT, position.getX().intValue()); - wrapper.write(Type.INT, position.getY().intValue()); - wrapper.write(Type.INT, position.getZ().intValue()); + wrapper.write(Type.INT, position.getPosX()); + wrapper.write(Type.INT, (int) position.getPosY()); + wrapper.write(Type.INT, position.getPosZ()); } }; @@ -515,14 +515,11 @@ public class Protocol1_13To1_12_2 extends Protocol { Item[] clone = ingredient.clone(); // Clone because array and item is mutable for (int i = 0; i < clone.length; i++) { if (clone[i] == null) continue; - clone[i] = new Item(clone[i].getId(), clone[i].getAmount(), - (short) 0, null); + clone[i] = new Item(new Item(clone[i])); } wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone); } - wrapper.write(Type.FLAT_ITEM, new Item( - entry.getValue().getResult().getId(), - entry.getValue().getResult().getAmount(), (short) 0, null)); + wrapper.write(Type.FLAT_ITEM, new Item(entry.getValue().getResult())); break; } case "crafting_shaped": { @@ -533,14 +530,11 @@ public class Protocol1_13To1_12_2 extends Protocol { Item[] clone = ingredient.clone(); // Clone because array and item is mutable for (int i = 0; i < clone.length; i++) { if (clone[i] == null) continue; - clone[i] = new Item(clone[i].getId(), clone[i].getAmount(), - (short) 0, null); + clone[i] = new Item(new Item(clone[i])); } wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone); } - wrapper.write(Type.FLAT_ITEM, new Item( - entry.getValue().getResult().getId(), - entry.getValue().getResult().getAmount(), (short) 0, null)); + wrapper.write(Type.FLAT_ITEM, new Item(entry.getValue().getResult())); break; } case "smelting": { @@ -548,13 +542,10 @@ public class Protocol1_13To1_12_2 extends Protocol { Item[] clone = entry.getValue().getIngredient().clone(); // Clone because array and item is mutable for (int i = 0; i < clone.length; i++) { if (clone[i] == null) continue; - clone[i] = new Item(clone[i].getId(), clone[i].getAmount(), - (short) 0, null); + clone[i] = new Item(clone[i]); } wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone); - wrapper.write(Type.FLAT_ITEM, new Item( - entry.getValue().getResult().getId(), - entry.getValue().getResult().getAmount(), (short) 0, null)); + wrapper.write(Type.FLAT_ITEM, new Item(entry.getValue().getResult())); wrapper.write(Type.FLOAT, entry.getValue().getExperience()); wrapper.write(Type.VAR_INT, entry.getValue().getCookingTime()); break; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 4403a1a05..b25136eae 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -30,11 +30,7 @@ public class ConnectionData { public static void update(UserConnection user, Position position) { BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class); for (BlockFace face : BlockFace.values()) { - Position pos = new Position( - position.getX() + face.getModX(), - position.getY() + face.getModY(), - position.getZ() + face.getModZ() - ); + Position pos = position.getRelative(face); int blockState = connectionProvider.getBlockdata(user, pos); ConnectionHandler handler = connectionHandlerMap.get(blockState); if (handler == null) continue; @@ -64,9 +60,9 @@ public class ConnectionData { int blockPosZ = chunkDeltaZ == 1 ? 0 : 15; updateBlock(user, new Position( - (long) ((chunkX + chunkDeltaX) << 4) + blockPosX, - (long) blockY, - (long) ((chunkZ + chunkDeltaZ) << 4) + blockPosZ + ((chunkX + chunkDeltaX) << 4) + blockPosX, + (short) blockY, + ((chunkZ + chunkDeltaZ) << 4) + blockPosZ ), updates ); @@ -102,9 +98,9 @@ public class ConnectionData { for (int blockZ = zStart; blockZ < zEnd; blockZ++) { updateBlock(user, new Position( - (long) ((chunkX + chunkDeltaX) << 4) + blockX, - (long) blockY, - (long) ((chunkZ + chunkDeltaZ) << 4) + blockZ), + ((chunkX + chunkDeltaX) << 4) + blockX, + (short) blockY, + ((chunkZ + chunkDeltaZ) << 4) + blockZ), updates ); } @@ -133,7 +129,7 @@ public class ConnectionData { if (handler == null) return; int newBlockState = handler.connect(user, pos, blockState); - records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY().shortValue(), newBlockState)); + records.add(new BlockChangeRecord((short) (((pos.getPosX() & 0xF) << 4) | (pos.getPosZ() & 0xF)), pos.getPosY(), newBlockState)); } public static BlockConnectionProvider getProvider() { @@ -186,7 +182,11 @@ public class ConnectionData { ConnectionHandler handler = ConnectionData.getConnectionHandler(block); if (handler != null) { - block = handler.connect(user, new Position(xOff + x, yOff + y, zOff + z), block); + block = handler.connect(user, new Position( + (int) (xOff + x), + (short) (yOff + y), + (short) (zOff + z) + ), block); section.setFlatBlock(x, y, z, block); } } @@ -282,7 +282,7 @@ public class ConnectionData { } public static int getId(String key) { - return keyToId.containsKey(key) ? keyToId.get(key) : -1; + return keyToId.getOrDefault(key, -1); } public static String getKey(int id) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index 06cb00462..2997f62f9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -152,7 +152,7 @@ public class WorldPackets { if (blockId == 73) { // Note block PacketWrapper blockChange = wrapper.create(0x0B); // block change - blockChange.write(Type.POSITION, new Position(pos.getX(), pos.getY(), pos.getZ())); // Clone because position is mutable + blockChange.write(Type.POSITION, new Position(pos)); // Clone because position is mutable blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2)); blockChange.send(Protocol1_13To1_12_2.class, true, true); } @@ -211,9 +211,9 @@ public class WorldPackets { for (BlockChangeRecord record : records) { int newBlock = toNewId(record.getBlockId()); Position position = new Position( - (long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), - (long) record.getY(), - (long) (record.getHorizontal() & 15) + (chunkZ * 16)); + (record.getHorizontal() >> 4 & 15) + (chunkX * 16), + record.getY(), + (record.getHorizontal() & 15) + (chunkZ * 16)); if (Via.getConfig().isServersideBlockConnections()) { ConnectionData.updateBlockStorage(userConnection, position, newBlock); @@ -339,9 +339,9 @@ public class WorldPackets { int block = section.getFlatBlock(x, y, z); if (storage.isWelcome(block)) { storage.store(new Position( - (long) (x + (chunk.getX() << 4)), - (long) (y + (i << 4)), - (long) (z + (chunk.getZ() << 4)) + (x + (chunk.getX() << 4)), + (short) (y + (i << 4)), + (z + (chunk.getZ() << 4)) ), block); } } @@ -355,9 +355,9 @@ public class WorldPackets { for (int x = 0; x < 16; x++) { int block = section.getFlatBlock(x, y, z); if (ConnectionData.isWelcome(block)) { - ConnectionData.getProvider().storeBlock(wrapper.user(), (long) (x + (chunk.getX() << 4)), - (long) (y + (i << 4)), - (long) (z + (chunk.getZ() << 4)), + ConnectionData.getProvider().storeBlock(wrapper.user(), x + (chunk.getX() << 4), + y + (i << 4), + z + (chunk.getZ() << 4), block); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index 96de6245a..1bf5f64b9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -112,7 +112,7 @@ public class BlockConnectionStorage extends StoredObject { } private long getChunkSectionIndex(Position position) { - return getChunkSectionIndex(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); + return getChunkSectionIndex(position.getPosX(), position.getPosY(), position.getPosZ()); } private short encodeBlockPos(int x, int y, int z) { @@ -120,7 +120,7 @@ public class BlockConnectionStorage extends StoredObject { } private short encodeBlockPos(Position pos) { - return encodeBlockPos(pos.getX().intValue(), pos.getY().intValue(), pos.getZ().intValue()); + return encodeBlockPos(pos.getPosX(), pos.getPosY(), pos.getPosZ()); } private Map createLongObjectMap() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java index c33411427..dd88b96f8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java @@ -55,9 +55,9 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol { //Create nbt CompoundTag tag = new CompoundTag(""); tag.put(new StringTag("id", "Sign")); - tag.put(new IntTag("x", position.getX().intValue())); - tag.put(new IntTag("y", position.getY().intValue())); - tag.put(new IntTag("z", position.getZ().intValue())); + tag.put(new IntTag("x", position.getPosX())); + tag.put(new IntTag("y", position.getPosY())); + tag.put(new IntTag("z", position.getPosZ())); for (int i = 0; i < lines.length; i++) tag.put(new StringTag("Text" + (i + 1), lines[i])); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index ee56c4847..5ef4d1be1 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -299,7 +299,7 @@ public class WorldPackets { if (Via.getConfig().isShieldBlocking()) { EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); - if (item != null && Protocol1_9To1_8.isSword(item.getId())) { + if (item != null && Protocol1_9To1_8.isSword(item.getIdentifier())) { if (hand == 0) { if (!tracker.isBlocking()) { tracker.setBlocking(true); @@ -363,9 +363,9 @@ public class WorldPackets { if (face == 255) return; Position p = wrapper.get(Type.POSITION, 0); - long x = p.getX(); - long y = p.getY(); - long z = p.getZ(); + int x = p.getPosX(); + short y = p.getPosY(); + int z = p.getPosZ(); switch (face) { case 0: y--; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java index 161c1e953..dc17ea89e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/CommandBlockStorage.java @@ -32,7 +32,7 @@ public class CommandBlockStorage extends StoredObject { Pair chunkPos = getChunkCoords(position); if (!storedCommandBlocks.containsKey(chunkPos)) - storedCommandBlocks.put(chunkPos, new ConcurrentHashMap()); + storedCommandBlocks.put(chunkPos, new ConcurrentHashMap<>()); Map blocks = storedCommandBlocks.get(chunkPos); @@ -44,8 +44,8 @@ public class CommandBlockStorage extends StoredObject { } private Pair getChunkCoords(Position position) { - int chunkX = (int) Math.floor(position.getX() / 16); - int chunkZ = (int) Math.floor(position.getZ() / 16); + int chunkX = Math.floorDiv(position.getPosX(), 16); + int chunkZ = Math.floorDiv(position.getPosZ(), 16); return new Pair<>(chunkX, chunkZ); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java index 6e8bfed2c..90feeec85 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java @@ -38,7 +38,11 @@ public class EntityTracker1_9 extends EntityTracker { private final Map bossBarMap = new ConcurrentHashMap<>(); private final Set validBlocking = Sets.newConcurrentHashSet(); private final Set knownHolograms = Sets.newConcurrentHashSet(); - private final Cache blockInteractions = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(250, TimeUnit.MILLISECONDS).build(); + private final Set blockInteractions = Collections.newSetFromMap(CacheBuilder.newBuilder() + .maximumSize(10) + .expireAfterAccess(250, TimeUnit.MILLISECONDS) + .build() + .asMap()); @Setter private boolean blocking = false; @Setter @@ -100,19 +104,11 @@ public class EntityTracker1_9 extends EntityTracker { } public boolean interactedBlockRecently(int x, int y, int z) { - if (blockInteractions.size() == 0) - return false; - for (Position p : blockInteractions.asMap().keySet()) { - if (p.getX() == x) - if (p.getY() == y) - if (p.getZ() == z) - return true; - } - return false; + return blockInteractions.contains(new Position(x, (short) y , z)); } public void addBlockInteraction(Position p) { - blockInteractions.put(p, 0); + blockInteractions.add(p); } public void handleMetadata(int entityId, List metadataList) { diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java index 5193ebe3e..497100d60 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaConfig.java @@ -12,7 +12,9 @@ import java.util.Map; import java.util.Optional; public class SpongeViaConfig extends AbstractViaConfig { - private static final List UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "quick-move-action-fix", "change-1_9-hitbox", "change-1_14-hitbox"); + private static final List UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval", + "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", + "quick-move-action-fix", "change-1_9-hitbox", "change-1_14-hitbox", "blockconnection-method"); private final PluginContainer pluginContainer; public SpongeViaConfig(PluginContainer pluginContainer, File configFile) { @@ -59,4 +61,9 @@ public class SpongeViaConfig extends AbstractViaConfig { public boolean is1_14HitboxFix() { return false; } + + @Override + public String getBlockConnectionMethod() { + return "packet"; + } } diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java index e8bdf6e32..9ac1e3ea7 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeViaLoader.java @@ -8,7 +8,6 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; @@ -19,7 +18,6 @@ import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.DeathListener; import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.HandItemCache; import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge4.Sponge4ArmorListener; import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge5.Sponge5ArmorListener; -import us.myles.ViaVersion.sponge.providers.SpongeBlockConnectionProvider; import us.myles.ViaVersion.sponge.providers.SpongeViaBulkChunkTranslator; import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter; @@ -80,9 +78,6 @@ public class SpongeViaLoader implements ViaPlatformLoader { } } }); - if (Via.getConfig().getBlockConnectionMethod().equalsIgnoreCase("world")) { - Via.getManager().getProviders().use(BlockConnectionProvider.class, new SpongeBlockConnectionProvider()); - } } public void unload() { diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java deleted file mode 100644 index d74e330c9..000000000 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/providers/SpongeBlockConnectionProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -package us.myles.ViaVersion.sponge.providers; - -import org.spongepowered.api.Sponge; -import org.spongepowered.api.block.BlockState; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.world.Chunk; -import org.spongepowered.api.world.World; -import us.myles.ViaVersion.api.Via; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.minecraft.Position; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers.BlockConnectionProvider; -import us.myles.ViaVersion.util.ReflectionUtil; - -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -public class SpongeBlockConnectionProvider extends BlockConnectionProvider { - private static Class block; - private static Map blockStateIds; - - static { - try { - block = Class.forName("net.minecraft.block.Block"); - blockStateIds = ReflectionUtil.get( - ReflectionUtil.getStatic(block, "field_176229_d", Object.class), - "field_148749_a", Map.class); - } catch (ClassNotFoundException e) { - Via.getPlatform().getLogger().warning("net.minecraft.block.Block not found! Are you using Lantern?"); - } catch (IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - } - - @Override - public int getWorldBlockData(UserConnection user, Position position) { - if (blockStateIds != null) { - UUID uuid = user.get(ProtocolInfo.class).getUuid(); - Optional player = Sponge.getServer().getPlayer(uuid); - if (player.isPresent()) { - World world = player.get().getWorld(); - Optional chunk = world.getChunkAtBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); - if (chunk.isPresent()) { - BlockState b = chunk.get().getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); - Integer id = blockStateIds.get(b); - if (id == null) { - System.out.println("id not found"); - } else { - return id; - } - } - } - } - return 0; - } -}