From 3f5500c6371409b3197be480c5281842d53f7c5f Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sun, 9 Feb 2020 13:06:23 +0100 Subject: [PATCH] Remove a bit of magic, use finals --- .../api/minecraft/BlockChangeRecord.java | 31 +++++++-- .../ViaVersion/api/minecraft/BlockFace.java | 36 +++++++--- .../ViaVersion/api/minecraft/EulerAngle.java | 29 +++++--- .../ViaVersion/api/minecraft/Position.java | 63 ++++++++++++----- .../ViaVersion/api/minecraft/Vector.java | 35 ++++++++-- .../api/minecraft/VillagerData.java | 29 +++++--- .../api/minecraft/chunks/BaseChunk.java | 64 ++++++++++++++--- .../api/minecraft/chunks/Chunk1_8.java | 10 +-- .../api/minecraft/chunks/ChunkSection.java | 14 ++-- .../ViaVersion/api/minecraft/item/Item.java | 69 +++++++++++++++++-- 10 files changed, 306 insertions(+), 74 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockChangeRecord.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockChangeRecord.java index 969cb3acf..4ea1fae42 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockChangeRecord.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/BlockChangeRecord.java @@ -1,12 +1,29 @@ package us.myles.ViaVersion.api.minecraft; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor public class BlockChangeRecord { - private short horizontal; - private short y; + private final short horizontal; + private final short y; private int blockId; + + public BlockChangeRecord(short horizontal, short y, int blockId) { + this.horizontal = horizontal; + this.y = y; + this.blockId = blockId; + } + + public short getHorizontal() { + return horizontal; + } + + public short getY() { + return y; + } + + public int getBlockId() { + return blockId; + } + + public void setBlockId(int blockId) { + this.blockId = blockId; + } } 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 c217979cb..739846001 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 @@ -1,13 +1,8 @@ package us.myles.ViaVersion.api.minecraft; -import lombok.AllArgsConstructor; -import lombok.Getter; - import java.util.HashMap; import java.util.Map; -@Getter -@AllArgsConstructor public enum BlockFace { NORTH((byte) 0, (byte) 0, (byte) -1, EnumAxis.Z), SOUTH((byte) 0, (byte) 0, (byte) 1, EnumAxis.Z), @@ -16,7 +11,7 @@ public enum BlockFace { TOP((byte) 0, (byte) 1, (byte) 0, EnumAxis.Y), BOTTOM((byte) 0, (byte) -1, (byte) 0, EnumAxis.Y); - private static Map opposites = new HashMap<>(); + private static final Map opposites = new HashMap<>(); static { opposites.put(BlockFace.NORTH, BlockFace.SOUTH); @@ -27,13 +22,38 @@ public enum BlockFace { opposites.put(BlockFace.BOTTOM, BlockFace.TOP); } - private byte modX, modY, modZ; - private EnumAxis axis; + private final byte modX; + private final byte modY; + private final byte modZ; + private final EnumAxis axis; + + BlockFace(byte modX, byte modY, byte modZ, EnumAxis axis) { + this.modX = modX; + this.modY = modY; + this.modZ = modZ; + this.axis = axis; + } public BlockFace opposite() { return opposites.get(this); } + public byte getModX() { + return modX; + } + + public byte getModY() { + return modY; + } + + public byte getModZ() { + return modZ; + } + + public EnumAxis getAxis() { + return axis; + } + public enum EnumAxis { X, Y, Z } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/EulerAngle.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/EulerAngle.java index 607d41e56..d0d1f7340 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/EulerAngle.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/EulerAngle.java @@ -1,12 +1,25 @@ package us.myles.ViaVersion.api.minecraft; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor public class EulerAngle { - private float x; - private float y; - private float z; + private final float x; + private final float y; + private final float z; + + public EulerAngle(final float x, final float y, final float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public float getX() { + return x; + } + + public float getY() { + return y; + } + + public float getZ() { + return 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 f93b16199..c9498a147 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 @@ -1,18 +1,15 @@ package us.myles.ViaVersion.api.minecraft; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -@AllArgsConstructor -@Getter -@ToString -@EqualsAndHashCode public class Position { - private int x; - private short y; - private int z; + private final int x; + private final short y; + private final int z; + + public Position(int x, short y, int z) { + this.x = x; + this.y = y; + this.z = z; + } public Position(Position toCopy) { this(toCopy.getX(), toCopy.getY(), toCopy.getZ()); @@ -22,10 +19,42 @@ public class Position { return new Position(x + face.getModX(), (short) (y + face.getModY()), z + face.getModZ()); } - public Position shift(BlockFace face) { - this.x += face.getModX(); - this.y += face.getModY(); - this.z += face.getModZ(); - return this; + public int getX() { + return x; + } + + public short getY() { + return y; + } + + public int getZ() { + return z; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Position position = (Position) o; + if (x != position.x) return false; + if (y != position.y) return false; + return z == position.z; + } + + @Override + public int hashCode() { + int result = x; + result = 31 * result + (int) y; + result = 31 * result + z; + return result; + } + + @Override + public String toString() { + return "Position{" + + "x=" + x + + ", y=" + y + + ", z=" + z + + '}'; } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/Vector.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/Vector.java index 78b6b5bdc..205c00d0c 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/Vector.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/Vector.java @@ -1,12 +1,37 @@ package us.myles.ViaVersion.api.minecraft; -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor public class Vector { private int blockX; private int blockY; private int blockZ; + + public Vector(int blockX, int blockY, int blockZ) { + this.blockX = blockX; + this.blockY = blockY; + this.blockZ = blockZ; + } + + public int getBlockX() { + return blockX; + } + + public void setBlockX(int blockX) { + this.blockX = blockX; + } + + public int getBlockY() { + return blockY; + } + + public void setBlockY(int blockY) { + this.blockY = blockY; + } + + public int getBlockZ() { + return blockZ; + } + + public void setBlockZ(int blockZ) { + this.blockZ = blockZ; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/VillagerData.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/VillagerData.java index 656ab9708..fab5f5de0 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/VillagerData.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/VillagerData.java @@ -1,12 +1,25 @@ package us.myles.ViaVersion.api.minecraft; -import lombok.AllArgsConstructor; -import lombok.Data; - -@AllArgsConstructor -@Data public class VillagerData { - private int type; - private int profession; - private int level; + private final int type; + private final int profession; + private final int level; + + public VillagerData(final int type, final int profession, final int level) { + this.type = type; + this.profession = profession; + this.level = level; + } + + public int getType() { + return type; + } + + public int getProfession() { + return profession; + } + + public int getLevel() { + return level; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java index 3c68c1b12..474fb3c7b 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java @@ -2,21 +2,19 @@ package us.myles.ViaVersion.api.minecraft.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import lombok.AllArgsConstructor; -import lombok.Data; import java.util.List; @AllArgsConstructor -@Data public class BaseChunk implements Chunk { - protected int x; - protected int z; - protected boolean groundUp; - protected int bitmask; - protected ChunkSection[] sections; + protected final int x; + protected final int z; + protected final boolean groundUp; + protected final int bitmask; + protected final ChunkSection[] sections; protected int[] biomeData; protected CompoundTag heightMap; - protected List blockEntities; + protected final List blockEntities; public BaseChunk(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, int[] biomeData, List blockEntities) { this.x = x; @@ -32,4 +30,54 @@ public class BaseChunk implements Chunk { public boolean isBiomeData() { return biomeData != null; } + + @Override + public int getX() { + return x; + } + + @Override + public int getZ() { + return z; + } + + @Override + public boolean isGroundUp() { + return groundUp; + } + + @Override + public int getBitmask() { + return bitmask; + } + + @Override + public ChunkSection[] getSections() { + return sections; + } + + @Override + public int[] getBiomeData() { + return biomeData; + } + + @Override + public void setBiomeData(final int[] biomeData) { + this.biomeData = biomeData; + } + + @Override + public CompoundTag getHeightMap() { + return heightMap; + } + + @Override + public void setHeightMap(final CompoundTag heightMap) { + this.heightMap = heightMap; + } + + @Override + public List getBlockEntities() { + return blockEntities; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java index 1a79c1891..cbe74a411 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java @@ -1,14 +1,12 @@ package us.myles.ViaVersion.api.minecraft.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import lombok.Getter; import java.util.ArrayList; import java.util.List; public class Chunk1_8 extends BaseChunk { - @Getter - private boolean unloadPacket = false; + private boolean unloadPacket; public Chunk1_8(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, int[] biomeData, List blockEntities) { super(x, z, groundUp, bitmask, sections, biomeData, blockEntities); @@ -21,7 +19,7 @@ public class Chunk1_8 extends BaseChunk { * @param z coord */ public Chunk1_8(int x, int z) { - this(x, z, true, 0, new ChunkSection[16], null, new ArrayList()); + this(x, z, true, 0, new ChunkSection[16], null, new ArrayList<>()); this.unloadPacket = true; } @@ -38,4 +36,8 @@ public class Chunk1_8 extends BaseChunk { public boolean isBiomeData() { return biomeData != null; } + + public boolean isUnloadPacket() { + return unloadPacket; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index 166f86516..156745f06 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -18,13 +18,11 @@ public class ChunkSection { * Length of the sky and block light nibble arrays. */ public static final int LIGHT_LENGTH = 16 * 16 * 16 / 2; // size * size * size / 2 (nibble bit count) - private List palette = new ArrayList<>(); - private Map inversePalette = new HashMap<>(); + private final List palette = new ArrayList<>(); + private final Map inversePalette = new HashMap<>(); private final int[] blocks; private NibbleArray blockLight; private NibbleArray skyLight; - @Getter - @Setter private int nonAirBlocksCount; public ChunkSection() { @@ -235,4 +233,12 @@ public class ChunkSection { public boolean hasBlockLight() { return blockLight != null; } + + public int getNonAirBlocksCount() { + return nonAirBlocksCount; + } + + public void setNonAirBlocksCount(int nonAirBlocksCount) { + this.nonAirBlocksCount = nonAirBlocksCount; + } } 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 889d29f0e..93e77bfe0 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 @@ -2,14 +2,11 @@ package us.myles.ViaVersion.api.minecraft.item; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.google.gson.annotations.SerializedName; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; -@Getter -@Setter @NoArgsConstructor @AllArgsConstructor -@ToString -@EqualsAndHashCode public class Item { @SerializedName(value = "identifier", alternate = "id") private int identifier; @@ -20,4 +17,66 @@ public class Item { public Item(Item toCopy) { this(toCopy.getIdentifier(), toCopy.getAmount(), toCopy.getData(), toCopy.getTag()); } + + public int getIdentifier() { + return identifier; + } + + public void setIdentifier(int identifier) { + this.identifier = identifier; + } + + public byte getAmount() { + return amount; + } + + public void setAmount(byte amount) { + this.amount = amount; + } + + public short getData() { + return data; + } + + public void setData(short data) { + this.data = data; + } + + public CompoundTag getTag() { + return tag; + } + + public void setTag(CompoundTag tag) { + this.tag = tag; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Item item = (Item) o; + if (identifier != item.identifier) return false; + if (amount != item.amount) return false; + if (data != item.data) return false; + return tag != null ? tag.equals(item.tag) : item.tag == null; + } + + @Override + public int hashCode() { + int result = identifier; + result = 31 * result + (int) amount; + result = 31 * result + (int) data; + result = 31 * result + (tag != null ? tag.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Item{" + + "identifier=" + identifier + + ", amount=" + amount + + ", data=" + data + + ", tag=" + tag + + '}'; + } }