Misc 1.14 update cleanup.

This commit is contained in:
Steveice10 2019-05-27 18:12:36 -07:00
parent 385c8fe342
commit d9feb4ad66
7 changed files with 147 additions and 103 deletions

View file

@ -15,13 +15,14 @@ import java.util.Objects;
public class BlockStorage {
private static final BlockState AIR = new BlockState(0);
private int blockCount = 0;
private int blockCount;
private int bitsPerEntry;
private List<BlockState> states;
private FlexibleStorage storage;
public BlockStorage() {
this.blockCount = 0;
this.bitsPerEntry = 4;
this.states = new ArrayList<BlockState>();
@ -112,15 +113,15 @@ public class BlockStorage {
id = this.bitsPerEntry <= 8 ? this.states.indexOf(state) : stateToRaw(state);
}
int index = index(x, y, z);
int curr = this.storage.get(index)
int ind = index(x, y, z);
int curr = this.storage.get(ind);
if(state.getId() != AIR.getId() && curr == AIR.getId()) {
this.blockCount++;
} else if(state.getId() == AIR.getId() && curr != AIR.getId()) {
this.blockCount--;
}
this.storage.set(index(x, y, z), id);
this.storage.set(ind, id);
}
public boolean isEmpty() {

View file

@ -4,6 +4,7 @@ import com.github.steveice10.mc.protocol.util.ObjectUtil;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import java.util.Arrays;
import java.util.Objects;
public class Column {
private int x;
@ -11,15 +12,15 @@ public class Column {
private Chunk chunks[];
private int biomeData[];
private CompoundTag tileEntities[];
private CompoundTag heightmaps;
private CompoundTag heightMaps;
private boolean skylight;
public Column(int x, int z, Chunk chunks[], CompoundTag[] tileEntities, CompoundTag heightmaps) {
this(x, z, chunks, null, tileEntities, heightmaps);
public Column(int x, int z, Chunk chunks[], CompoundTag[] tileEntities, CompoundTag heightMaps) {
this(x, z, chunks, null, tileEntities, heightMaps);
}
public Column(int x, int z, Chunk chunks[], int biomeData[], CompoundTag[] tileEntities, CompoundTag heightmaps) {
public Column(int x, int z, Chunk chunks[], int biomeData[], CompoundTag[] tileEntities, CompoundTag heightMaps) {
if(chunks.length != 16) {
throw new IllegalArgumentException("Chunk array length must be 16.");
}
@ -33,7 +34,7 @@ public class Column {
this.chunks = chunks;
this.biomeData = biomeData;
this.tileEntities = tileEntities != null ? tileEntities : new CompoundTag[0];
this.heightmaps = heightmaps;
this.heightMaps = heightMaps;
}
public int getX() {
@ -64,8 +65,8 @@ public class Column {
return this.skylight;
}
public CompoundTag getHeightmaps() {
return heightmaps;
public CompoundTag getHeightMaps() {
return this.heightMaps;
}
@Override
@ -78,12 +79,13 @@ public class Column {
this.z == that.z &&
Arrays.equals(this.chunks, that.chunks) &&
Arrays.equals(this.biomeData, that.biomeData) &&
Arrays.equals(this.tileEntities, that.tileEntities);
Arrays.equals(this.tileEntities, that.tileEntities) &&
Objects.equals(this.heightMaps, that.heightMaps);
}
@Override
public int hashCode() {
return ObjectUtil.hashCode(this.x, this.z, this.chunks, this.biomeData, this.tileEntities);
return ObjectUtil.hashCode(this.x, this.z, this.chunks, this.biomeData, this.tileEntities, this.heightMaps);
}
@Override

View file

@ -1,34 +1,32 @@
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
public class VillagerData {
import com.github.steveice10.mc.protocol.util.ObjectUtil;
private int villagerType;
private int villagerProfession;
public class VillagerData {
private int type;
private int profession;
private int level;
public VillagerData() {
}
public VillagerData(int villagerType, int villagerProfession, int level) {
this.villagerType = villagerType;
this.villagerProfession = villagerProfession;
public VillagerData(int type, int profession, int level) {
this.type = type;
this.profession = profession;
this.level = level;
}
public int getVillagerType() {
return villagerType;
public int getType() {
return type;
}
public void setVillagerType(int villagerType) {
this.villagerType = villagerType;
public void setType(int type) {
this.type = type;
}
public int getVillagerProfession() {
return villagerProfession;
public int getProfession() {
return profession;
}
public void setVillagerProfession(int villagerProfession) {
this.villagerProfession = villagerProfession;
public void setProfession(int profession) {
this.profession = profession;
}
public int getLevel() {
@ -38,4 +36,25 @@ public class VillagerData {
public void setLevel(int level) {
this.level = level;
}
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(!(o instanceof VillagerData)) return false;
VillagerData that = (VillagerData) o;
return this.type == that.type &&
this.profession == that.profession &&
this.level == that.level;
}
@Override
public int hashCode() {
return ObjectUtil.hashCode(this.type, this.profession, this.level);
}
@Override
public String toString() {
return ObjectUtil.toString(this);
}
}

View file

@ -1,103 +1,93 @@
package com.github.steveice10.mc.protocol.data.game.window;
import java.io.IOException;
import java.util.Objects;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.util.NetUtil;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.mc.protocol.util.ObjectUtil;
public class VillagerTrade {
private ItemStack input1Item;
private ItemStack input2Item;
private ItemStack outputItem;
private ItemStack firstInput;
private ItemStack secondInput;
private ItemStack output;
private boolean tradeDisabled;
private int numberOfUses;
private int maxNumberOfUses;
private int numUses;
private int maxUses;
private int xp;
private int specialPrice;
private float priceMultiplier;
public VillagerTrade() {
}
public VillagerTrade(ItemStack input1Item, ItemStack input2Item, ItemStack outputItem, boolean tradeDisabled, int numberOfUses, int maxNumberOfUses, int xp, int specialPrice, float priceMultiplier) {
this.input1Item = input1Item;
this.input2Item = input2Item;
this.outputItem = outputItem;
public VillagerTrade(ItemStack firstInput, ItemStack secondInput, ItemStack output, boolean tradeDisabled, int numUses, int maxUses, int xp, int specialPrice, float priceMultiplier) {
this.firstInput = firstInput;
this.secondInput = secondInput;
this.output = output;
this.tradeDisabled = tradeDisabled;
this.numberOfUses = numberOfUses;
this.maxNumberOfUses = maxNumberOfUses;
this.numUses = numUses;
this.maxUses = maxUses;
this.xp = xp;
this.specialPrice = specialPrice;
this.priceMultiplier = priceMultiplier;
}
public ItemStack getInput1Item() {
return input1Item;
public ItemStack getFirstInput() {
return this.firstInput;
}
public ItemStack getInput2Item() {
return input2Item;
public ItemStack getSecondInput() {
return this.secondInput;
}
public ItemStack getOutputItem() {
return outputItem;
public ItemStack getOutput() {
return this.output;
}
public boolean isTradeDisabled() {
return tradeDisabled;
return this.tradeDisabled;
}
public int getNumberOfUses() {
return numberOfUses;
public int getNumUses() {
return this.numUses;
}
public int getMaxNumberOfUses() {
return maxNumberOfUses;
public int getMaxUses() {
return this.maxUses;
}
public int getXp() {
return xp;
return this.xp;
}
public int getSpecialPrice() {
return specialPrice;
return this.specialPrice;
}
public float getPriceMultiplier() {
return priceMultiplier;
return this.priceMultiplier;
}
public void read(NetInput in) throws IOException {
this.input1Item = NetUtil.readItem(in);
this.outputItem = NetUtil.readItem(in);
boolean hasSecondItem = in.readBoolean();
if (hasSecondItem) {
this.input2Item = NetUtil.readItem(in);
}
this.tradeDisabled = in.readBoolean();
this.numberOfUses = in.readInt();
this.maxNumberOfUses = in.readInt();
this.xp = in.readInt();
this.specialPrice = in.readInt();
this.priceMultiplier = in.readFloat();
@Override
public boolean equals(Object o) {
if(this == o) return true;
if(!(o instanceof VillagerTrade)) return false;
VillagerTrade that = (VillagerTrade) o;
return Objects.equals(this.firstInput, that.firstInput) &&
Objects.equals(this.secondInput, that.secondInput) &&
Objects.equals(this.output, that.output) &&
this.tradeDisabled == that.tradeDisabled &&
this.numUses == that.numUses &&
this.maxUses == that.maxUses &&
this.xp == that.xp &&
this.specialPrice == that.specialPrice &&
Float.floatToIntBits(this.priceMultiplier) == Float.floatToIntBits(that.priceMultiplier);
}
public void write(NetOutput out) throws IOException {
NetUtil.writeItem(out, this.input1Item);
NetUtil.writeItem(out, this.outputItem);
boolean hasSecondItem = this.input2Item != null;
out.writeBoolean(hasSecondItem);
if (hasSecondItem) {
NetUtil.writeItem(out, this.input2Item);
}
out.writeBoolean(this.tradeDisabled);
out.writeInt(this.numberOfUses);
out.writeInt(this.maxNumberOfUses);
out.writeInt(this.xp);
out.writeInt(this.specialPrice);
out.writeFloat(this.priceMultiplier);
@Override
public int hashCode() {
return ObjectUtil.hashCode(this.firstInput, this.secondInput, this.output, this.tradeDisabled, this.numUses, this.maxUses, this.xp, this.specialPrice, this.priceMultiplier);
}
@Override
public String toString() {
return ObjectUtil.toString(this);
}
}

View file

@ -2,8 +2,10 @@ package com.github.steveice10.mc.protocol.packet.ingame.server.window;
import java.io.IOException;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
import com.github.steveice10.mc.protocol.packet.MinecraftPacket;
import com.github.steveice10.mc.protocol.util.NetUtil;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
@ -49,12 +51,28 @@ public class ServerTradeListPacket extends MinecraftPacket {
@Override
public void read(NetInput in) throws IOException {
this.windowId = in.readVarInt();
byte size = in.readByte();
this.trades = new VillagerTrade[size];
for (int i = 0; i < trades.length; i++) {
trades[i] = new VillagerTrade();
trades[i].read(in);
for(int i = 0; i < trades.length; i++) {
ItemStack firstInput = NetUtil.readItem(in);
ItemStack output = NetUtil.readItem(in);
ItemStack secondInput = null;
if(in.readBoolean()) {
secondInput = NetUtil.readItem(in);
}
boolean tradeDisabled = in.readBoolean();
int numUses = in.readInt();
int maxUses = in.readInt();
int xp = in.readInt();
int specialPrice = in.readInt();
float priceMultiplier = in.readFloat();
this.trades[i] = new VillagerTrade(firstInput, secondInput, output, tradeDisabled, numUses, maxUses, xp, specialPrice, priceMultiplier);
}
this.villagerLevel = in.readVarInt();
this.experience = in.readVarInt();
this.isRegularVillager = in.readBoolean();
@ -63,10 +81,28 @@ public class ServerTradeListPacket extends MinecraftPacket {
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(this.windowId);
out.writeByte(this.trades.length);
for (int i = 0; i < trades.length; i++) {
this.trades[i].write(out);
for(int i = 0; i < this.trades.length; i++) {
VillagerTrade trade = this.trades[i];
NetUtil.writeItem(out, trade.getFirstInput());
NetUtil.writeItem(out, trade.getOutput());
boolean hasSecondItem = trade.getSecondInput() != null;
out.writeBoolean(hasSecondItem);
if(hasSecondItem) {
NetUtil.writeItem(out, trade.getSecondInput());
}
out.writeBoolean(trade.isTradeDisabled());
out.writeInt(trade.getNumUses());
out.writeInt(trade.getMaxUses());
out.writeInt(trade.getXp());
out.writeInt(trade.getSpecialPrice());
out.writeFloat(trade.getPriceMultiplier());
}
out.writeVarInt(this.villagerLevel);
out.writeVarInt(this.experience);
out.writeBoolean(this.isRegularVillager);

View file

@ -52,7 +52,7 @@ public class ServerChunkDataPacket extends MinecraftPacket {
out.writeInt(this.column.getZ());
out.writeBoolean(this.column.hasBiomeData());
out.writeVarInt(mask);
NetUtil.writeNBT(out, this.column.getHeightmaps());
NetUtil.writeNBT(out, this.column.getHeightMaps());
out.writeVarInt(byteOut.size());
out.writeBytes(byteOut.toByteArray(), byteOut.size());
out.writeVarInt(this.column.getTileEntities().length);

View file

@ -234,11 +234,7 @@ public class NetUtil {
value = readParticle(in);
break;
case VILLAGER_DATA:
VillagerData villagerData = new VillagerData();
villagerData.setVillagerType(in.readVarInt());
villagerData.setVillagerProfession(in.readVarInt());
villagerData.setLevel(in.readVarInt());
value = villagerData;
value = new VillagerData(in.readVarInt(), in.readVarInt(), in.readVarInt());
break;
case OPTIONAL_VARINT:
int i = in.readVarInt();
@ -323,8 +319,8 @@ public class NetUtil {
break;
case VILLAGER_DATA:
VillagerData villagerData = (VillagerData) meta.getValue();
out.writeVarInt(villagerData.getVillagerType());
out.writeVarInt(villagerData.getVillagerProfession());
out.writeVarInt(villagerData.getType());
out.writeVarInt(villagerData.getProfession());
out.writeVarInt(villagerData.getLevel());
break;
case OPTIONAL_VARINT: