3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 01:00:15 +01:00

Merge pull request #1527 from creeper123123321/primitive_types

Use primitive types in Position and BlockFace, remove world block con…
Dieser Commit ist enthalten in:
Myles 2019-12-13 12:48:36 +00:00 committet von GitHub
Commit d45a370a4d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
31 geänderte Dateien mit 137 neuen und 222 gelöschten Zeilen

Datei anzeigen

@ -22,7 +22,7 @@ public class BlockListener extends ViaBukkitListener {
Block b = e.getBlockPlaced(); Block b = e.getBlockPlaced();
getUserConnection(e.getPlayer()) getUserConnection(e.getPlayer())
.get(EntityTracker1_9.class) .get(EntityTracker1_9.class)
.addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ())); .addBlockInteraction(new Position(b.getX(), (short) b.getY(), b.getZ()));
} }
} }
} }

Datei anzeigen

@ -34,7 +34,7 @@ public class HandItemCache extends BukkitRunnable {
} }
public static Item convert(ItemStack itemInHand) { public static Item convert(ItemStack itemInHand) {
if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null); if (itemInHand == null) return new Item(0, (byte) 0, (short) 0, null);
return new Item((short) itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null); return new Item(itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null);
} }
} }

Datei anzeigen

@ -16,16 +16,16 @@ public class BukkitBlockConnectionProvider extends BlockConnectionProvider {
private Chunk lastChunk; private Chunk lastChunk;
@Override @Override
public int getWorldBlockData(UserConnection user, Position position) { public int getWorldBlockData(UserConnection user, int bx, int by, int bz) {
UUID uuid = user.get(ProtocolInfo.class).getUuid(); UUID uuid = user.get(ProtocolInfo.class).getUuid();
Player player = Bukkit.getPlayer(uuid); Player player = Bukkit.getPlayer(uuid);
if (player != null) { if (player != null) {
World world = player.getWorld(); World world = player.getWorld();
int x = (int) (position.getX() >> 4); int x = bx >> 4;
int z = (int) (position.getZ() >> 4); int z = bz >> 4;
if (world.isChunkLoaded(x, z)) { if (world.isChunkLoaded(x, z)) {
Chunk c = getChunk(world, 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(bx, by, bz);
return b.getTypeId() << 4 | b.getData(); return b.getTypeId() << 4 | b.getData();
} }
} }

Datei anzeigen

@ -9,12 +9,12 @@ import java.util.Map;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum BlockFace { public enum BlockFace {
NORTH(0, 0, -1, EnumAxis.Z), NORTH((byte) 0, (byte) 0, (byte) -1, EnumAxis.Z),
SOUTH(0, 0, 1, EnumAxis.Z), SOUTH((byte) 0, (byte) 0, (byte) 1, EnumAxis.Z),
EAST(1, 0, 0, EnumAxis.X), EAST((byte) 1, (byte) 0, (byte) 0, EnumAxis.X),
WEST(-1, 0, 0, EnumAxis.X), WEST((byte) -1, (byte) 0, (byte) 0, EnumAxis.X),
TOP(0, 1, 0, EnumAxis.Y), TOP((byte) 0, (byte) 1, (byte) 0, EnumAxis.Y),
BOTTOM(0, -1, 0, EnumAxis.Y); BOTTOM((byte) 0, (byte) -1, (byte) 0, EnumAxis.Y);
private static Map<BlockFace, BlockFace> opposites = new HashMap<>(); private static Map<BlockFace, BlockFace> opposites = new HashMap<>();
@ -27,7 +27,7 @@ public enum BlockFace {
opposites.put(BlockFace.BOTTOM, BlockFace.TOP); opposites.put(BlockFace.BOTTOM, BlockFace.TOP);
} }
private int modX, modY, modZ; private byte modX, modY, modZ;
private EnumAxis axis; private EnumAxis axis;
public BlockFace opposite() { public BlockFace opposite() {
@ -35,6 +35,6 @@ public enum BlockFace {
} }
public enum EnumAxis { public enum EnumAxis {
X, Y, Z; X, Y, Z
} }
} }

Datei anzeigen

@ -10,12 +10,16 @@ import lombok.ToString;
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
public class Position { public class Position {
private Long x; private int x;
private Long y; private short y;
private Long z; private int z;
public Position(Position toCopy) {
this(toCopy.getX(), toCopy.getY(), toCopy.getZ());
}
public Position getRelative(BlockFace face) { public Position getRelative(BlockFace face) {
return new Position(this.x + face.getModX(), this.y + face.getModY(), this.z + face.getModZ()); return new Position(x + face.getModX(), (short) (y + face.getModY()), z + face.getModZ());
} }
public Position shift(BlockFace face) { public Position shift(BlockFace face) {

Datei anzeigen

@ -17,21 +17,7 @@ public class Item {
private short data; private short data;
private CompoundTag tag; private CompoundTag tag;
@Deprecated public Item(Item toCopy) {
public short getId() { this(toCopy.getIdentifier(), toCopy.getAmount(), toCopy.getData(), toCopy.getTag());
return (short) identifier;
}
@Deprecated
public void setId(short id) {
identifier = id;
}
@Deprecated
public Item(short id, byte amount, short data, CompoundTag tag) {
this.identifier = id;
this.amount = amount;
this.data = data;
this.tag = tag;
} }
} }

Datei anzeigen

@ -17,11 +17,13 @@ public class Position1_14Type extends Type<Position> {
long y = val << 52 >> 52; long y = val << 52 >> 52;
long z = val << 26 >> 38; long z = val << 26 >> 38;
return new Position(x, y, z); return new Position((int) x, (short) y, (int) z);
} }
@Override @Override
public void write(ByteBuf buffer, Position object) { public void write(ByteBuf buffer, Position object) {
buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | (object.getY() & 0xfff) | ((object.getZ() & 0x3ffffff) << 12)); buffer.writeLong((((long) object.getX() & 0x3ffffff) << 38)
| (object.getY() & 0xfff)
| ((((long) object.getZ()) & 0x3ffffff) << 12));
} }
} }

Datei anzeigen

@ -17,11 +17,13 @@ public class PositionType extends Type<Position> {
// this shifting madness is used to preserve sign // this shifting madness is used to preserve sign
long z = (val << 38) >> 38; // signed long z = (val << 38) >> 38; // signed
return new Position(x, y, z); return new Position((int) x, (short) y, (int) z);
} }
@Override @Override
public void write(ByteBuf buffer, Position object) { public void write(ByteBuf buffer, Position object) {
buffer.writeLong(((object.getX() & 0x3ffffff) << 38) | ((object.getY() & 0xfff) << 26) | (object.getZ() & 0x3ffffff)); buffer.writeLong((((long) object.getX() & 0x3ffffff) << 38)
| ((((long) object.getY()) & 0xfff) << 26)
| (object.getZ() & 0x3ffffff));
} }
} }

Datei anzeigen

@ -45,9 +45,9 @@ public class Protocol1_13To1_12_2 extends Protocol {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.read(Type.POSITION); Position position = wrapper.read(Type.POSITION);
wrapper.write(Type.INT, position.getX().intValue()); wrapper.write(Type.INT, position.getX());
wrapper.write(Type.INT, position.getY().intValue()); wrapper.write(Type.INT, (int) position.getY());
wrapper.write(Type.INT, position.getZ().intValue()); wrapper.write(Type.INT, position.getZ());
} }
}; };
@ -513,14 +513,11 @@ public class Protocol1_13To1_12_2 extends Protocol {
Item[] clone = ingredient.clone(); // Clone because array and item is mutable Item[] clone = ingredient.clone(); // Clone because array and item is mutable
for (int i = 0; i < clone.length; i++) { for (int i = 0; i < clone.length; i++) {
if (clone[i] == null) continue; if (clone[i] == null) continue;
clone[i] = new Item(clone[i].getId(), clone[i].getAmount(), clone[i] = new Item(clone[i]);
(short) 0, null);
} }
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone); wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
} }
wrapper.write(Type.FLAT_ITEM, new Item( wrapper.write(Type.FLAT_ITEM, new Item(entry.getValue().getResult()));
entry.getValue().getResult().getId(),
entry.getValue().getResult().getAmount(), (short) 0, null));
break; break;
} }
case "crafting_shaped": { case "crafting_shaped": {
@ -531,14 +528,11 @@ public class Protocol1_13To1_12_2 extends Protocol {
Item[] clone = ingredient.clone(); // Clone because array and item is mutable Item[] clone = ingredient.clone(); // Clone because array and item is mutable
for (int i = 0; i < clone.length; i++) { for (int i = 0; i < clone.length; i++) {
if (clone[i] == null) continue; if (clone[i] == null) continue;
clone[i] = new Item(clone[i].getId(), clone[i].getAmount(), clone[i] = new Item(clone[i]);
(short) 0, null);
} }
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone); wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
} }
wrapper.write(Type.FLAT_ITEM, new Item( wrapper.write(Type.FLAT_ITEM, new Item(entry.getValue().getResult()));
entry.getValue().getResult().getId(),
entry.getValue().getResult().getAmount(), (short) 0, null));
break; break;
} }
case "smelting": { case "smelting": {
@ -546,13 +540,10 @@ public class Protocol1_13To1_12_2 extends Protocol {
Item[] clone = entry.getValue().getIngredient().clone(); // Clone because array and item is mutable Item[] clone = entry.getValue().getIngredient().clone(); // Clone because array and item is mutable
for (int i = 0; i < clone.length; i++) { for (int i = 0; i < clone.length; i++) {
if (clone[i] == null) continue; if (clone[i] == null) continue;
clone[i] = new Item(clone[i].getId(), clone[i].getAmount(), clone[i] = new Item(clone[i]);
(short) 0, null);
} }
wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone); wrapper.write(Type.FLAT_ITEM_ARRAY_VAR_INT, clone);
wrapper.write(Type.FLAT_ITEM, new Item( wrapper.write(Type.FLAT_ITEM, new Item(entry.getValue().getResult()));
entry.getValue().getResult().getId(),
entry.getValue().getResult().getAmount(), (short) 0, null));
wrapper.write(Type.FLOAT, entry.getValue().getExperience()); wrapper.write(Type.FLOAT, entry.getValue().getExperience());
wrapper.write(Type.VAR_INT, entry.getValue().getCookingTime()); wrapper.write(Type.VAR_INT, entry.getValue().getCookingTime());
break; break;

Datei anzeigen

@ -30,12 +30,8 @@ public class ConnectionData {
public static void update(UserConnection user, Position position) { public static void update(UserConnection user, Position position) {
BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class); BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class);
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
Position pos = new Position( Position pos = position.getRelative(face);
position.getX() + face.getModX(), int blockState = connectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
position.getY() + face.getModY(),
position.getZ() + face.getModZ()
);
int blockState = connectionProvider.getBlockdata(user, pos);
ConnectionHandler handler = connectionHandlerMap.get(blockState); ConnectionHandler handler = connectionHandlerMap.get(blockState);
if (handler == null) continue; if (handler == null) continue;
@ -64,9 +60,9 @@ public class ConnectionData {
int blockPosZ = chunkDeltaZ == 1 ? 0 : 15; int blockPosZ = chunkDeltaZ == 1 ? 0 : 15;
updateBlock(user, updateBlock(user,
new Position( new Position(
(long) ((chunkX + chunkDeltaX) << 4) + blockPosX, ((chunkX + chunkDeltaX) << 4) + blockPosX,
(long) blockY, (short) blockY,
(long) ((chunkZ + chunkDeltaZ) << 4) + blockPosZ ((chunkZ + chunkDeltaZ) << 4) + blockPosZ
), ),
updates updates
); );
@ -102,9 +98,9 @@ public class ConnectionData {
for (int blockZ = zStart; blockZ < zEnd; blockZ++) { for (int blockZ = zStart; blockZ < zEnd; blockZ++) {
updateBlock(user, updateBlock(user,
new Position( new Position(
(long) ((chunkX + chunkDeltaX) << 4) + blockX, ((chunkX + chunkDeltaX) << 4) + blockX,
(long) blockY, (short) blockY,
(long) ((chunkZ + chunkDeltaZ) << 4) + blockZ), ((chunkZ + chunkDeltaZ) << 4) + blockZ),
updates updates
); );
} }
@ -128,24 +124,24 @@ public class ConnectionData {
} }
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) { public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos); int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
ConnectionHandler handler = getConnectionHandler(blockState); ConnectionHandler handler = getConnectionHandler(blockState);
if (handler == null) return; if (handler == null) return;
int newBlockState = handler.connect(user, pos, blockState); 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.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY(), newBlockState));
} }
public static BlockConnectionProvider getProvider() { public static BlockConnectionProvider getProvider() {
return Via.getManager().getProviders().get(BlockConnectionProvider.class); return Via.getManager().getProviders().get(BlockConnectionProvider.class);
} }
public static void updateBlockStorage(UserConnection userConnection, Position position, int blockState) { public static void updateBlockStorage(UserConnection userConnection, int x, int y, int z, int blockState) {
if (!needStoreBlocks()) return; if (!needStoreBlocks()) return;
if (ConnectionData.isWelcome(blockState)) { if (ConnectionData.isWelcome(blockState)) {
ConnectionData.getProvider().storeBlock(userConnection, position, blockState); ConnectionData.getProvider().storeBlock(userConnection, x, y, z, blockState);
} else { } else {
ConnectionData.getProvider().removeBlock(userConnection, position); ConnectionData.getProvider().removeBlock(userConnection, x, y, z);
} }
} }
@ -186,7 +182,11 @@ public class ConnectionData {
ConnectionHandler handler = ConnectionData.getConnectionHandler(block); ConnectionHandler handler = ConnectionData.getConnectionHandler(block);
if (handler != null) { 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),
(int) (zOff + z)
), block);
section.setFlatBlock(x, y, z, block); section.setFlatBlock(x, y, z, block);
} }
} }
@ -282,7 +282,7 @@ public class ConnectionData {
} }
public static int getId(String key) { 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) { public static String getKey(int id) {

Datei anzeigen

@ -9,7 +9,7 @@ public abstract class ConnectionHandler {
public abstract int connect(UserConnection user, Position position, int blockState); public abstract int connect(UserConnection user, Position position, int blockState);
public int getBlockData(UserConnection user, Position position) { public int getBlockData(UserConnection user, Position position) {
return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, position); return Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockData(user, position.getX(), position.getY(), position.getZ());
} }
public boolean canConnect(int id) { public boolean canConnect(int id) {

Datei anzeigen

@ -6,28 +6,23 @@ import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
public class BlockConnectionProvider implements Provider { public class BlockConnectionProvider implements Provider {
public int getBlockData(UserConnection connection, int x, int y, int z) {
public int getBlockdata(UserConnection connection, Position position) { int oldId = getWorldBlockData(connection, x, y, z);
int oldId = getWorldBlockData(connection, position);
return MappingData.blockMappings.getNewId(oldId); return MappingData.blockMappings.getNewId(oldId);
} }
public int getWorldBlockData(UserConnection connection, Position position) { public int getWorldBlockData(UserConnection connection, int x, int y, int z) {
return -1; return -1;
} }
public void storeBlock(UserConnection connection, Position position, int blockState) { public void storeBlock(UserConnection connection, int x, int y, int z, int blockState) {
} }
public void removeBlock(UserConnection connection, Position position) { public void removeBlock(UserConnection connection, int x, int y, int z) {
} }
public void storeBlock(UserConnection connection, long x, long y, long z, int blockState) {
storeBlock(connection, new Position(x, y, z), blockState);
}
public void clearStorage(UserConnection connection) { public void clearStorage(UserConnection connection) {
} }

Datei anzeigen

@ -1,24 +1,23 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockConnectionStorage; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockConnectionStorage;
public class PacketBlockConnectionProvider extends BlockConnectionProvider { public class PacketBlockConnectionProvider extends BlockConnectionProvider {
@Override @Override
public void storeBlock(UserConnection connection, Position position, int blockState) { public void storeBlock(UserConnection connection, int x, int y, int z, int blockState) {
connection.get(BlockConnectionStorage.class).store(position, blockState); connection.get(BlockConnectionStorage.class).store(x, y, z, blockState);
} }
@Override @Override
public void removeBlock(UserConnection connection, Position position) { public void removeBlock(UserConnection connection, int x, int y, int z) {
connection.get(BlockConnectionStorage.class).remove(position); connection.get(BlockConnectionStorage.class).remove(x, y, z);
} }
@Override @Override
public int getBlockdata(UserConnection connection, Position position) { public int getBlockData(UserConnection connection, int x, int y, int z) {
return connection.get(BlockConnectionStorage.class).get(position); return connection.get(BlockConnectionStorage.class).get(x, y, z);
} }
@Override @Override

Datei anzeigen

@ -128,9 +128,9 @@ public class ParticleRewriter {
public Particle handler(Particle particle, Integer[] data) { public Particle handler(Particle particle, Integer[] data) {
Item item; Item item;
if (data.length == 1) if (data.length == 1)
item = new Item(data[0].shortValue(), (byte) 1, (short) 0, null); item = new Item(data[0], (byte) 1, (short) 0, null);
else if (data.length == 2) else if (data.length == 2)
item = new Item(data[0].shortValue(), (byte) 1, data[1].shortValue(), null); item = new Item(data[0], (byte) 1, data[1].shortValue(), null);
else else
return particle; return particle;

Datei anzeigen

@ -152,7 +152,7 @@ public class WorldPackets {
if (blockId == 73) { // Note block if (blockId == 73) { // Note block
PacketWrapper blockChange = wrapper.create(0x0B); // block change 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.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
blockChange.send(Protocol1_13To1_12_2.class, true, true); blockChange.send(Protocol1_13To1_12_2.class, true, true);
} }
@ -177,7 +177,7 @@ public class WorldPackets {
UserConnection userConnection = wrapper.user(); UserConnection userConnection = wrapper.user();
if (Via.getConfig().isServersideBlockConnections()) { if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position, newId); ConnectionData.updateBlockStorage(userConnection, position.getX(), position.getY(), position.getZ(), newId);
newId = ConnectionData.connect(userConnection, position, newId); newId = ConnectionData.connect(userConnection, position, newId);
} }
wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId)); wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
@ -211,12 +211,12 @@ public class WorldPackets {
for (BlockChangeRecord record : records) { for (BlockChangeRecord record : records) {
int newBlock = toNewId(record.getBlockId()); int newBlock = toNewId(record.getBlockId());
Position position = new Position( Position position = new Position(
(long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), (record.getHorizontal() >> 4 & 15) + (chunkX * 16),
(long) record.getY(), record.getY(),
(long) (record.getHorizontal() & 15) + (chunkZ * 16)); (record.getHorizontal() & 15) + (chunkZ * 16));
if (Via.getConfig().isServersideBlockConnections()) { if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position, newBlock); ConnectionData.updateBlockStorage(userConnection, position.getX(), position.getY(), position.getZ(), newBlock);
} }
record.setBlockId(checkStorage(wrapper.user(), position, newBlock)); record.setBlockId(checkStorage(wrapper.user(), position, newBlock));
} }
@ -226,9 +226,9 @@ public class WorldPackets {
int blockState = record.getBlockId(); int blockState = record.getBlockId();
Position position = new Position( Position position = new Position(
(long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), (record.getHorizontal() >> 4 & 15) + (chunkX * 16),
(long) record.getY(), record.getY(),
(long) (record.getHorizontal() & 15) + (chunkZ * 16)); (record.getHorizontal() & 15) + (chunkZ * 16));
ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState); ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
if (handler != null) { if (handler != null) {
@ -242,9 +242,9 @@ public class WorldPackets {
for (BlockChangeRecord record : records) { for (BlockChangeRecord record : records) {
Position position = new Position( Position position = new Position(
(long) (record.getHorizontal() >> 4 & 15) + (chunkX * 16), (record.getHorizontal() >> 4 & 15) + (chunkX * 16),
(long) record.getY(), record.getY(),
(long) (record.getHorizontal() & 15) + (chunkZ * 16)); (record.getHorizontal() & 15) + (chunkZ * 16));
ConnectionData.update(userConnection, position); ConnectionData.update(userConnection, position);
} }
} }
@ -339,9 +339,9 @@ public class WorldPackets {
int block = section.getFlatBlock(x, y, z); int block = section.getFlatBlock(x, y, z);
if (storage.isWelcome(block)) { if (storage.isWelcome(block)) {
storage.store(new Position( storage.store(new Position(
(long) (x + (chunk.getX() << 4)), (x + (chunk.getX() << 4)),
(long) (y + (i << 4)), (short) (y + (i << 4)),
(long) (z + (chunk.getZ() << 4)) (z + (chunk.getZ() << 4))
), block); ), block);
} }
} }
@ -355,9 +355,9 @@ public class WorldPackets {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z); int block = section.getFlatBlock(x, y, z);
if (ConnectionData.isWelcome(block)) { if (ConnectionData.isWelcome(block)) {
ConnectionData.getProvider().storeBlock(wrapper.user(), (long) (x + (chunk.getX() << 4)), ConnectionData.getProvider().storeBlock(wrapper.user(), x + (chunk.getX() << 4),
(long) (y + (i << 4)), y + (i << 4),
(long) (z + (chunk.getZ() << 4)), z + (chunk.getZ() << 4),
block); block);
} }
} }
@ -393,7 +393,7 @@ public class WorldPackets {
int y = (int) tag.get("y").getValue(); int y = (int) tag.get("y").getValue();
int z = (int) tag.get("z").getValue(); int z = (int) tag.get("z").getValue();
Position position = new Position((long) x, (long) y, (long) z); Position position = new Position(x, (short) y, z);
// Store the replacement blocks for blockupdates // Store the replacement blocks for blockupdates
if (storage.contains(position)) if (storage.contains(position))
storage.get(position).setReplacement(newId); storage.get(position).setReplacement(newId);

Datei anzeigen

@ -18,7 +18,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
@Override @Override
public int transform(UserConnection user, CompoundTag tag) { public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class); BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
if (!storage.contains(position)) { if (!storage.contains(position)) {
Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag); Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag);

Datei anzeigen

@ -13,7 +13,7 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler {
@Override @Override
public int transform(UserConnection user, CompoundTag tag) { public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class); BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
if (!storage.contains(position)) { if (!storage.contains(position)) {
Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag); Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag);

Datei anzeigen

@ -15,7 +15,7 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler {
@Override @Override
public int transform(UserConnection user, CompoundTag tag) { public int transform(UserConnection user, CompoundTag tag) {
BlockStorage storage = user.get(BlockStorage.class); BlockStorage storage = user.get(BlockStorage.class);
Position position = new Position(getLong(tag.get("x")), getLong(tag.get("y")), getLong(tag.get("z"))); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z")));
if (!storage.contains(position)) { if (!storage.contains(position)) {
Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag); Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag);

Datei anzeigen

@ -37,35 +37,35 @@ public class BlockConnectionStorage extends StoredObject {
super(user); super(user);
} }
public void store(Position position, int blockState) { public void store(int x, int y, int z, int blockState) {
Short mapping = reverseBlockMappings.get((short) blockState); Short mapping = reverseBlockMappings.get((short) blockState);
if (mapping == null) return; if (mapping == null) return;
blockState = mapping; blockState = mapping;
long pair = getChunkSectionIndex(position); long pair = getChunkSectionIndex(x, y, z);
Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0); Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
int blockIndex = encodeBlockPos(position); int blockIndex = encodeBlockPos(x, y, z);
map.getKey()[blockIndex] = (byte) (blockState >> 4); map.getKey()[blockIndex] = (byte) (blockState >> 4);
NibbleArray nibbleArray = map.getValue(); NibbleArray nibbleArray = map.getValue();
if (nibbleArray != null) nibbleArray.set(blockIndex, blockState); if (nibbleArray != null) nibbleArray.set(blockIndex, blockState);
} }
public int get(Position position) { public int get(int x, int y, int z) {
long pair = getChunkSectionIndex(position); long pair = getChunkSectionIndex(x, y, z);
Pair<byte[], NibbleArray> map = blockStorage.get(pair); Pair<byte[], NibbleArray> map = blockStorage.get(pair);
if (map == null) return 0; if (map == null) return 0;
short blockPosition = encodeBlockPos(position); short blockPosition = encodeBlockPos(x, y, z);
NibbleArray nibbleArray = map.getValue(); NibbleArray nibbleArray = map.getValue();
return WorldPackets.toNewId( return WorldPackets.toNewId(
((map.getKey()[blockPosition] & 0xFF) << 4) ((map.getKey()[blockPosition] & 0xFF) << 4)
| (nibbleArray == null ? 0 : nibbleArray.get(blockPosition)) | (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
); );
} }
public void remove(Position position) { public void remove(int x, int y, int z) {
long pair = getChunkSectionIndex(position); long pair = getChunkSectionIndex(x, y, z);
Pair<byte[], NibbleArray> map = blockStorage.get(pair); Pair<byte[], NibbleArray> map = blockStorage.get(pair);
if (map == null) return; if (map == null) return;
int blockIndex = encodeBlockPos(position); int blockIndex = encodeBlockPos(x, y, z);
NibbleArray nibbleArray = map.getValue(); NibbleArray nibbleArray = map.getValue();
if (nibbleArray != null) { if (nibbleArray != null) {
nibbleArray.set(blockIndex, 0); nibbleArray.set(blockIndex, 0);
@ -112,7 +112,7 @@ public class BlockConnectionStorage extends StoredObject {
} }
private long getChunkSectionIndex(Position position) { private long getChunkSectionIndex(Position position) {
return getChunkSectionIndex(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); return getChunkSectionIndex(position.getX(), position.getY(), position.getZ());
} }
private short encodeBlockPos(int x, int y, int z) { private short encodeBlockPos(int x, int y, int z) {
@ -120,7 +120,7 @@ public class BlockConnectionStorage extends StoredObject {
} }
private short encodeBlockPos(Position pos) { private short encodeBlockPos(Position pos) {
return encodeBlockPos(pos.getX().intValue(), pos.getY().intValue(), pos.getZ().intValue()); return encodeBlockPos(pos.getX(), pos.getY(), pos.getZ());
} }
private <T> Map<Long, T> createLongObjectMap() { private <T> Map<Long, T> createLongObjectMap() {

Datei anzeigen

@ -45,7 +45,7 @@ public class BlockEntity {
int y = (int) tag.get("y").getValue(); int y = (int) tag.get("y").getValue();
int z = (int) tag.get("z").getValue(); int z = (int) tag.get("z").getValue();
Position pos = new Position((long) x, (long) y, (long) z); Position pos = new Position(x, (short) y, z);
updateBlockEntity(pos, (short) newId, tag, connection); updateBlockEntity(pos, (short) newId, tag, connection);
} catch (Exception e) { } catch (Exception e) {

Datei anzeigen

@ -55,9 +55,9 @@ public class Protocol1_9_3To1_9_1_2 extends Protocol {
//Create nbt //Create nbt
CompoundTag tag = new CompoundTag(""); CompoundTag tag = new CompoundTag("");
tag.put(new StringTag("id", "Sign")); tag.put(new StringTag("id", "Sign"));
tag.put(new IntTag("x", position.getX().intValue())); tag.put(new IntTag("x", position.getX()));
tag.put(new IntTag("y", position.getY().intValue())); tag.put(new IntTag("y", position.getY()));
tag.put(new IntTag("z", position.getZ().intValue())); tag.put(new IntTag("z", position.getZ()));
for (int i = 0; i < lines.length; i++) for (int i = 0; i < lines.length; i++)
tag.put(new StringTag("Text" + (i + 1), lines[i])); tag.put(new StringTag("Text" + (i + 1), lines[i]));

Datei anzeigen

@ -103,7 +103,7 @@ public class SpawnPackets {
public void write(PacketWrapper wrapper) throws Exception { public void write(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, entityID);
List<Metadata> meta = new ArrayList<>(); List<Metadata> meta = new ArrayList<>();
Item item = new Item((short) 373, (byte) 1, (short) data, null); // Potion Item item = new Item(373, (byte) 1, (short) data, null); // Potion
ItemRewriter.toClient(item); // Rewrite so that it gets the right nbt ItemRewriter.toClient(item); // Rewrite so that it gets the right nbt
// TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS // TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS
Metadata potion = new Metadata(5, MetaType1_9.Slot, item); Metadata potion = new Metadata(5, MetaType1_9.Slot, item);

Datei anzeigen

@ -299,11 +299,11 @@ public class WorldPackets {
if (Via.getConfig().isShieldBlocking()) { if (Via.getConfig().isShieldBlocking()) {
EntityTracker1_9 tracker = wrapper.user().get(EntityTracker1_9.class); 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 (hand == 0) {
if (!tracker.isBlocking()) { if (!tracker.isBlocking()) {
tracker.setBlocking(true); tracker.setBlocking(true);
Item shield = new Item((short) 442, (byte) 1, (short) 0, null); Item shield = new Item(442, (byte) 1, (short) 0, null);
tracker.setSecondHand(shield); tracker.setSecondHand(shield);
} }
wrapper.cancel(); wrapper.cancel();
@ -363,9 +363,9 @@ public class WorldPackets {
if (face == 255) if (face == 255)
return; return;
Position p = wrapper.get(Type.POSITION, 0); Position p = wrapper.get(Type.POSITION, 0);
long x = p.getX(); int x = p.getX();
long y = p.getY(); short y = p.getY();
long z = p.getZ(); int z = p.getZ();
switch (face) { switch (face) {
case 0: case 0:
y--; y--;

Datei anzeigen

@ -6,6 +6,6 @@ import us.myles.ViaVersion.api.platform.providers.Provider;
public class HandItemProvider implements Provider { public class HandItemProvider implements Provider {
public Item getHandItem(final UserConnection info) { public Item getHandItem(final UserConnection info) {
return new Item((short) 0, (byte) 0, (short) 0, null); return new Item(0, (byte) 0, (short) 0, null);
} }
} }

Datei anzeigen

@ -32,7 +32,7 @@ public class CommandBlockStorage extends StoredObject {
Pair<Integer, Integer> chunkPos = getChunkCoords(position); Pair<Integer, Integer> chunkPos = getChunkCoords(position);
if (!storedCommandBlocks.containsKey(chunkPos)) if (!storedCommandBlocks.containsKey(chunkPos))
storedCommandBlocks.put(chunkPos, new ConcurrentHashMap<Position, CompoundTag>()); storedCommandBlocks.put(chunkPos, new ConcurrentHashMap<>());
Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkPos); Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkPos);
@ -44,8 +44,8 @@ public class CommandBlockStorage extends StoredObject {
} }
private Pair<Integer, Integer> getChunkCoords(Position position) { private Pair<Integer, Integer> getChunkCoords(Position position) {
int chunkX = (int) Math.floor(position.getX() / 16); int chunkX = Math.floorDiv(position.getX(), 16);
int chunkZ = (int) Math.floor(position.getZ() / 16); int chunkZ = Math.floorDiv(position.getZ(), 16);
return new Pair<>(chunkX, chunkZ); return new Pair<>(chunkX, chunkZ);
} }

Datei anzeigen

@ -38,7 +38,11 @@ public class EntityTracker1_9 extends EntityTracker {
private final Map<Integer, BossBar> bossBarMap = new ConcurrentHashMap<>(); private final Map<Integer, BossBar> bossBarMap = new ConcurrentHashMap<>();
private final Set<Integer> validBlocking = Sets.newConcurrentHashSet(); private final Set<Integer> validBlocking = Sets.newConcurrentHashSet();
private final Set<Integer> knownHolograms = Sets.newConcurrentHashSet(); private final Set<Integer> knownHolograms = Sets.newConcurrentHashSet();
private final Cache<Position, Integer> blockInteractions = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(250, TimeUnit.MILLISECONDS).build(); private final Set<Position> blockInteractions = Collections.newSetFromMap(CacheBuilder.newBuilder()
.maximumSize(10)
.expireAfterAccess(250, TimeUnit.MILLISECONDS)
.<Position, Boolean>build()
.asMap());
@Setter @Setter
private boolean blocking = false; private boolean blocking = false;
@Setter @Setter
@ -100,19 +104,11 @@ public class EntityTracker1_9 extends EntityTracker {
} }
public boolean interactedBlockRecently(int x, int y, int z) { public boolean interactedBlockRecently(int x, int y, int z) {
if (blockInteractions.size() == 0) return blockInteractions.contains(new Position(x, (short) y , z));
return false;
for (Position p : blockInteractions.asMap().keySet()) {
if (p.getX() == x)
if (p.getY() == y)
if (p.getZ() == z)
return true;
}
return false;
} }
public void addBlockInteraction(Position p) { public void addBlockInteraction(Position p) {
blockInteractions.put(p, 0); blockInteractions.add(p);
} }
public void handleMetadata(int entityId, List<Metadata> metadataList) { public void handleMetadata(int entityId, List<Metadata> metadataList) {
@ -157,7 +153,7 @@ public class EntityTracker1_9 extends EntityTracker {
if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) { if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
if ((data & 0x10) == 0x10) { if ((data & 0x10) == 0x10) {
if (validBlocking.contains(entityId)) { if (validBlocking.contains(entityId)) {
Item shield = new Item((short) 442, (byte) 1, (short) 0, null); Item shield = new Item(442, (byte) 1, (short) 0, null);
setSecondHand(entityId, shield); setSecondHand(entityId, shield);
} else { } else {
setSecondHand(entityId, null); setSecondHand(entityId, null);

Datei anzeigen

@ -23,7 +23,7 @@ public class BlockListener extends ViaSpongeListener {
Location loc = e.getTransactions().get(0).getFinal().getLocation().get(); Location loc = e.getTransactions().get(0).getFinal().getLocation().get();
getUserConnection(player.getUniqueId()) getUserConnection(player.getUniqueId())
.get(EntityTracker1_9.class) .get(EntityTracker1_9.class)
.addBlockInteraction(new Position((long) loc.getX(), (long) loc.getY(), (long) loc.getZ())); .addBlockInteraction(new Position(loc.getBlockX(), (short) loc.getBlockY(), loc.getBlockZ()));
} }
} }
} }

Datei anzeigen

@ -51,7 +51,7 @@ public class HandItemCache implements Runnable {
} }
public static Item convert(ItemStack itemInHand) { public static Item convert(ItemStack itemInHand) {
if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null); if (itemInHand == null) return new Item(0, (byte) 0, (short) 0, null);
if (GET_DAMAGE == null) { if (GET_DAMAGE == null) {
try { try {
GET_DAMAGE = itemInHand.getClass().getDeclaredField("field_77991_e"); GET_DAMAGE = itemInHand.getClass().getDeclaredField("field_77991_e");
@ -87,7 +87,7 @@ public class HandItemCache implements Runnable {
e.printStackTrace(); e.printStackTrace();
} }
} }
return new Item((short) id, (byte) itemInHand.getQuantity(), (short) damage, null); return new Item(id, (byte) itemInHand.getQuantity(), (short) damage, null);
} }
} }

Datei anzeigen

@ -12,7 +12,9 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class SpongeViaConfig extends AbstractViaConfig { public class SpongeViaConfig extends AbstractViaConfig {
private static final List<String> 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<String> 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; private final PluginContainer pluginContainer;
public SpongeViaConfig(PluginContainer pluginContainer, File configFile) { public SpongeViaConfig(PluginContainer pluginContainer, File configFile) {

Datei anzeigen

@ -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.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; 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.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; 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.HandItemCache;
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.sponge4.Sponge4ArmorListener; 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.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.SpongeViaBulkChunkTranslator;
import us.myles.ViaVersion.sponge.providers.SpongeViaMovementTransmitter; 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() { public void unload() {

Datei anzeigen

@ -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<Object, Integer> 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> player = Sponge.getServer().getPlayer(uuid);
if (player.isPresent()) {
World world = player.get().getWorld();
Optional<Chunk> 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;
}
}