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

remove deprecated methods and constructor on item and position, inline some uses of position

Dieser Commit ist enthalten in:
creeper123123321 2019-11-24 17:55:46 -03:00
Ursprung 9308fc7712
Commit 1e8d04a07d
27 geänderte Dateien mit 84 neuen und 145 gelöschten Zeilen

Datei anzeigen

@ -22,7 +22,7 @@ public class BlockListener extends ViaBukkitListener {
Block b = e.getBlockPlaced();
getUserConnection(e.getPlayer())
.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) {
if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null);
return new Item((short) itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null);
if (itemInHand == null) return new Item(0, (byte) 0, (short) 0, 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;
@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();
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
World world = player.getWorld();
int x = position.getPosX() >> 4;
int z = position.getPosZ() >> 4;
int x = bx >> 4;
int z = bx >> 4;
if (world.isChunkLoaded(x, z)) {
Chunk c = getChunk(world, x, z);
Block b = c.getBlock(position.getPosX(), position.getPosY(), position.getPosZ());
Block b = c.getBlock(bx, by, bz);
return b.getTypeId() << 4 | b.getData();
}
}

Datei anzeigen

@ -10,59 +10,22 @@ import lombok.ToString;
@ToString
@EqualsAndHashCode
public class Position {
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();
}
private int x;
private short y;
private int z;
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;
this(toCopy.getX(), toCopy.getY(), toCopy.getZ());
}
public Position getRelative(BlockFace face) {
return new Position(posX + face.getModX(), (short) (posY + face.getModY()), posZ + face.getModZ());
return new Position(x + face.getModX(), (short) (y + face.getModY()), z + face.getModZ());
}
public Position shift(BlockFace face) {
this.posX += face.getModX();
this.posY += face.getModY();
this.posZ += face.getModZ();
this.x += face.getModX();
this.y += face.getModY();
this.z += face.getModZ();
return this;
}
}

Datei anzeigen

@ -17,24 +17,6 @@ public class Item {
private short data;
private CompoundTag tag;
@Deprecated
public short getId() {
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;
}
public Item(Item toCopy) {
this(toCopy.getIdentifier(), toCopy.getAmount(), toCopy.getData(), toCopy.getTag());
}

Datei anzeigen

@ -22,8 +22,8 @@ public class Position1_14Type extends Type<Position> {
@Override
public void write(ByteBuf buffer, Position object) {
buffer.writeLong((((long) object.getPosX() & 0x3ffffff) << 38)
| (object.getPosY() & 0xfff)
| ((object.getPosZ() & 0x3ffffff) << 12));
buffer.writeLong((((long) object.getX() & 0x3ffffff) << 38)
| (object.getY() & 0xfff)
| ((object.getZ() & 0x3ffffff) << 12));
}
}

Datei anzeigen

@ -22,8 +22,8 @@ public class PositionType extends Type<Position> {
@Override
public void write(ByteBuf buffer, Position object) {
buffer.writeLong((((long) object.getPosX() & 0x3ffffff) << 38)
| ((object.getPosY() & 0xfff) << 26)
| (object.getPosZ() & 0x3ffffff));
buffer.writeLong((((long) object.getX() & 0x3ffffff) << 38)
| ((object.getY() & 0xfff) << 26)
| (object.getZ() & 0x3ffffff));
}
}

Datei anzeigen

@ -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.getPosX());
wrapper.write(Type.INT, (int) position.getPosY());
wrapper.write(Type.INT, position.getPosZ());
wrapper.write(Type.INT, position.getX());
wrapper.write(Type.INT, (int) position.getY());
wrapper.write(Type.INT, position.getZ());
}
};

Datei anzeigen

@ -31,7 +31,7 @@ public class ConnectionData {
BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class);
for (BlockFace face : BlockFace.values()) {
Position pos = position.getRelative(face);
int blockState = connectionProvider.getBlockdata(user, pos);
int blockState = connectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
ConnectionHandler handler = connectionHandlerMap.get(blockState);
if (handler == null) continue;
@ -124,24 +124,24 @@ public class ConnectionData {
}
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);
if (handler == null) return;
int newBlockState = handler.connect(user, pos, blockState);
records.add(new BlockChangeRecord((short) (((pos.getPosX() & 0xF) << 4) | (pos.getPosZ() & 0xF)), pos.getPosY(), newBlockState));
records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY(), newBlockState));
}
public static BlockConnectionProvider getProvider() {
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 (ConnectionData.isWelcome(blockState)) {
ConnectionData.getProvider().storeBlock(userConnection, position, blockState);
ConnectionData.getProvider().storeBlock(userConnection, x, y, z, blockState);
} else {
ConnectionData.getProvider().removeBlock(userConnection, position);
ConnectionData.getProvider().removeBlock(userConnection, x, y, z);
}
}

Datei anzeigen

@ -9,7 +9,7 @@ public abstract class ConnectionHandler {
public abstract int connect(UserConnection user, Position position, int blockState);
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) {

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;
public class BlockConnectionProvider implements Provider {
public int getBlockdata(UserConnection connection, Position position) {
int oldId = getWorldBlockData(connection, position);
public int getBlockData(UserConnection connection, int x, int y, int z) {
int oldId = getWorldBlockData(connection, x, y, z);
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;
}
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) {
}

Datei anzeigen

@ -1,24 +1,23 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.providers;
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;
public class PacketBlockConnectionProvider extends BlockConnectionProvider {
@Override
public void storeBlock(UserConnection connection, Position position, int blockState) {
connection.get(BlockConnectionStorage.class).store(position, blockState);
public void storeBlock(UserConnection connection, int x, int y, int z, int blockState) {
connection.get(BlockConnectionStorage.class).store(x, y, z, blockState);
}
@Override
public void removeBlock(UserConnection connection, Position position) {
connection.get(BlockConnectionStorage.class).remove(position);
public void removeBlock(UserConnection connection, int x, int y, int z) {
connection.get(BlockConnectionStorage.class).remove(x, y, z);
}
@Override
public int getBlockdata(UserConnection connection, Position position) {
return connection.get(BlockConnectionStorage.class).get(position);
public int getBlockData(UserConnection connection, int x, int y, int z) {
return connection.get(BlockConnectionStorage.class).get(x, y, z);
}
@Override

Datei anzeigen

@ -127,9 +127,9 @@ public class ParticleRewriter {
public Particle handler(Particle particle, Integer[] data) {
Item item;
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)
item = new Item(data[0].shortValue(), (byte) 1, data[1].shortValue(), null);
item = new Item(data[0], (byte) 1, data[1].shortValue(), null);
else
return particle;

Datei anzeigen

@ -177,7 +177,7 @@ public class WorldPackets {
UserConnection userConnection = wrapper.user();
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);
}
wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
@ -216,7 +216,7 @@ public class WorldPackets {
(record.getHorizontal() & 15) + (chunkZ * 16));
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));
}
@ -226,9 +226,9 @@ public class WorldPackets {
int blockState = 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));
ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
if (handler != null) {
@ -242,9 +242,9 @@ public class WorldPackets {
for (BlockChangeRecord record : records) {
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));
ConnectionData.update(userConnection, position);
}
}
@ -393,7 +393,7 @@ public class WorldPackets {
int y = (int) tag.get("y").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
if (storage.contains(position))
storage.get(position).setReplacement(newId);

Datei anzeigen

@ -18,7 +18,7 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
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)) {
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
public int transform(UserConnection user, CompoundTag tag) {
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)) {
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
public int transform(UserConnection user, CompoundTag tag) {
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)) {
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);
}
public void store(Position position, int blockState) {
public void store(int x, int y, int z, int blockState) {
Short mapping = reverseBlockMappings.get((short) blockState);
if (mapping == null) return;
blockState = mapping;
long pair = getChunkSectionIndex(position);
long pair = getChunkSectionIndex(x, y, z);
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);
NibbleArray nibbleArray = map.getValue();
if (nibbleArray != null) nibbleArray.set(blockIndex, blockState);
}
public int get(Position position) {
long pair = getChunkSectionIndex(position);
public int get(int x, int y, int z) {
long pair = getChunkSectionIndex(x, y, z);
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
if (map == null) return 0;
short blockPosition = encodeBlockPos(position);
short blockPosition = encodeBlockPos(x, y, z);
NibbleArray nibbleArray = map.getValue();
return WorldPackets.toNewId(
((map.getKey()[blockPosition] & 0xFF) << 4)
| (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
| (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
);
}
public void remove(Position position) {
long pair = getChunkSectionIndex(position);
public void remove(int x, int y, int z) {
long pair = getChunkSectionIndex(x, y, z);
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
if (map == null) return;
int blockIndex = encodeBlockPos(position);
int blockIndex = encodeBlockPos(x, y, z);
NibbleArray nibbleArray = map.getValue();
if (nibbleArray != null) {
nibbleArray.set(blockIndex, 0);
@ -112,7 +112,7 @@ public class BlockConnectionStorage extends StoredObject {
}
private long getChunkSectionIndex(Position position) {
return getChunkSectionIndex(position.getPosX(), position.getPosY(), position.getPosZ());
return getChunkSectionIndex(position.getX(), position.getY(), position.getZ());
}
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.getPosX(), pos.getPosY(), pos.getPosZ());
return encodeBlockPos(pos.getX(), pos.getY(), pos.getZ());
}
private <T> Map<Long, T> createLongObjectMap() {

Datei anzeigen

@ -45,7 +45,7 @@ public class BlockEntity {
int y = (int) tag.get("y").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);
} catch (Exception e) {

Datei anzeigen

@ -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.getPosX()));
tag.put(new IntTag("y", position.getPosY()));
tag.put(new IntTag("z", position.getPosZ()));
tag.put(new IntTag("x", position.getX()));
tag.put(new IntTag("y", position.getY()));
tag.put(new IntTag("z", position.getZ()));
for (int i = 0; i < lines.length; 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 {
wrapper.write(Type.VAR_INT, entityID);
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
// TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS
Metadata potion = new Metadata(5, MetaType1_9.Slot, item);

Datei anzeigen

@ -303,7 +303,7 @@ public class WorldPackets {
if (hand == 0) {
if (!tracker.isBlocking()) {
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);
}
wrapper.cancel();
@ -363,9 +363,9 @@ public class WorldPackets {
if (face == 255)
return;
Position p = wrapper.get(Type.POSITION, 0);
int x = p.getPosX();
short y = p.getPosY();
int z = p.getPosZ();
int x = p.getX();
short y = p.getY();
int z = p.getZ();
switch (face) {
case 0:
y--;

Datei anzeigen

@ -6,6 +6,6 @@ import us.myles.ViaVersion.api.platform.providers.Provider;
public class HandItemProvider implements Provider {
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

@ -44,8 +44,8 @@ public class CommandBlockStorage extends StoredObject {
}
private Pair<Integer, Integer> getChunkCoords(Position position) {
int chunkX = Math.floorDiv(position.getPosX(), 16);
int chunkZ = Math.floorDiv(position.getPosZ(), 16);
int chunkX = Math.floorDiv(position.getX(), 16);
int chunkZ = Math.floorDiv(position.getZ(), 16);
return new Pair<>(chunkX, chunkZ);
}

Datei anzeigen

@ -153,7 +153,7 @@ public class EntityTracker1_9 extends EntityTracker {
if (entityId != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) {
if ((data & 0x10) == 0x10) {
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);
} else {
setSecondHand(entityId, null);

Datei anzeigen

@ -23,7 +23,7 @@ public class BlockListener extends ViaSpongeListener {
Location loc = e.getTransactions().get(0).getFinal().getLocation().get();
getUserConnection(player.getUniqueId())
.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) {
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) {
try {
GET_DAMAGE = itemInHand.getClass().getDeclaredField("field_77991_e");
@ -87,7 +87,7 @@ public class HandItemCache implements Runnable {
e.printStackTrace();
}
}
return new Item((short) id, (byte) itemInHand.getQuantity(), (short) damage, null);
return new Item(id, (byte) itemInHand.getQuantity(), (short) damage, null);
}
}