Update CraftingBookDataPacket

This commit is contained in:
Paul Heidenreich 2019-04-28 12:46:08 +02:00
parent 29b54275f2
commit 0e28d84a26

View file

@ -9,12 +9,17 @@ import com.github.steveice10.packetlib.io.NetOutput;
import java.io.IOException;
public class ClientCraftingBookDataPacket extends MinecraftPacket {
private CraftingBookDataType type;
private String recipeId;
private boolean craftingBookOpen;
private boolean filterCraftingActive;
private boolean smeltingBookOpen;
private boolean filterSmeltingActive;
private boolean blastingBookOpen;
private boolean filterBlastingActive;
private boolean smokingBookOpen;
private boolean filterSmokingActive;
@SuppressWarnings("unused")
private ClientCraftingBookDataPacket() {
@ -25,11 +30,16 @@ public class ClientCraftingBookDataPacket extends MinecraftPacket {
this.recipeId = recipeId;
}
public ClientCraftingBookDataPacket(boolean craftingBookOpen, boolean filterCraftingActive,
boolean smeltingBookOpen, boolean filterSmeltingActive) {
public ClientCraftingBookDataPacket(boolean craftingBookOpen, boolean filterCraftingActive, boolean smeltingBookOpen, boolean filterSmeltingActive, boolean blastingBookOpen, boolean filterBlastingActive, boolean smokingBookOpen, boolean filterSmokingActive) {
this.type = CraftingBookDataType.CRAFTING_BOOK_STATUS;
this.craftingBookOpen = craftingBookOpen;
this.filterCraftingActive = filterCraftingActive;
this.smeltingBookOpen = smeltingBookOpen;
this.filterSmeltingActive = filterSmeltingActive;
this.blastingBookOpen = blastingBookOpen;
this.filterBlastingActive = filterBlastingActive;
this.smokingBookOpen = smokingBookOpen;
this.filterSmokingActive = filterSmokingActive;
}
public CraftingBookDataType getType() {
@ -37,7 +47,7 @@ public class ClientCraftingBookDataPacket extends MinecraftPacket {
}
private void ensureType(CraftingBookDataType type, String what) {
if(this.type != type) {
if (this.type != type) {
throw new IllegalStateException(what + " is only set when type is " + type + " but it is " + this.type);
}
}
@ -67,9 +77,29 @@ public class ClientCraftingBookDataPacket extends MinecraftPacket {
return filterSmeltingActive;
}
public boolean isBlastingBookOpen() {
ensureType(CraftingBookDataType.CRAFTING_BOOK_STATUS, "blastingBookOpen");
return blastingBookOpen;
}
public boolean isFilterBlastingActive() {
ensureType(CraftingBookDataType.CRAFTING_BOOK_STATUS, "filterBlastingActive");
return filterBlastingActive;
}
public boolean isSmokingBookOpen() {
ensureType(CraftingBookDataType.CRAFTING_BOOK_STATUS, "smokingBookOpen");
return smokingBookOpen;
}
public boolean isFilterSmokingActive() {
ensureType(CraftingBookDataType.CRAFTING_BOOK_STATUS, "filterSmokingActive");
return filterSmokingActive;
}
@Override
public void read(NetInput in) throws IOException {
switch(this.type = MagicValues.key(CraftingBookDataType.class, in.readVarInt())) {
switch (this.type = MagicValues.key(CraftingBookDataType.class, in.readVarInt())) {
case DISPLAYED_RECIPE:
this.recipeId = in.readString();
break;
@ -78,6 +108,10 @@ public class ClientCraftingBookDataPacket extends MinecraftPacket {
this.filterCraftingActive = in.readBoolean();
this.smeltingBookOpen = in.readBoolean();
this.filterSmeltingActive = in.readBoolean();
this.blastingBookOpen = in.readBoolean();
this.filterBlastingActive = in.readBoolean();
this.smokingBookOpen = in.readBoolean();
this.filterSmokingActive = in.readBoolean();
break;
default:
throw new IOException("Unknown crafting book data type: " + this.type);
@ -87,7 +121,7 @@ public class ClientCraftingBookDataPacket extends MinecraftPacket {
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(MagicValues.value(Integer.class, this.type));
switch(this.type) {
switch (this.type) {
case DISPLAYED_RECIPE:
out.writeString(this.recipeId);
break;
@ -96,6 +130,10 @@ public class ClientCraftingBookDataPacket extends MinecraftPacket {
out.writeBoolean(this.filterCraftingActive);
out.writeBoolean(this.smeltingBookOpen);
out.writeBoolean(this.filterSmeltingActive);
out.writeBoolean(this.blastingBookOpen);
out.writeBoolean(this.filterBlastingActive);
out.writeBoolean(this.smokingBookOpen);
out.writeBoolean(this.filterSmokingActive);
break;
default:
throw new IOException("Unknown crafting book data type: " + this.type);