mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Fix networking for worktable and escritoire
This commit is contained in:
1 parent
4abbc92472
commit
0a0bdfa978
7 files changed
+21
-24
No files matched your search
@@ -2,7 +2,6 @@ package forestry.core.network;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -122,15 +121,9 @@ public class PacketBufferForestry extends PacketBuffer {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends IStreamable> T readStreamable(Class<T> streamableClass) throws IOException {
|
||||
public <T extends IStreamable> T readStreamable(IStreamableFactory<T> factory) throws IOException {
|
||||
if (readBoolean()) {
|
||||
try {
|
||||
T streamable = streamableClass.newInstance();
|
||||
streamable.readData(this);
|
||||
return streamable;
|
||||
} catch (IllegalAccessException | InstantiationException | IOException e) {
|
||||
throw new InvalidObjectException("Failed to read Streamable for class " + streamableClass + " with error " + e);
|
||||
}
|
||||
return factory.create(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -146,14 +139,18 @@ public class PacketBufferForestry extends PacketBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends IStreamable> void readStreamables(List<T> outputList, Class<T> streamableClass) throws IOException {
|
||||
public <T extends IStreamable> void readStreamables(List<T> outputList, IStreamableFactory<T> factory) throws IOException {
|
||||
outputList.clear();
|
||||
int length = readVarInt();
|
||||
if (length > 0) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
T streamable = readStreamable(streamableClass);
|
||||
T streamable = readStreamable(factory);
|
||||
outputList.add(streamable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IStreamableFactory<T extends IStreamable> {
|
||||
T create(PacketBufferForestry data) throws IOException;
|
||||
}
|
||||
}
|
||||
@@ -225,6 +225,6 @@ public class EscritoireGameBoard implements INbtWritable, IStreamable {
|
||||
@Override
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
tokenCount = data.readVarInt();
|
||||
data.readStreamables(gameTokens, EscritoireGameToken.class);
|
||||
data.readStreamables(gameTokens, EscritoireGameToken::new);
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
|
||||
|
||||
private State state = State.UNREVEALED;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public EscritoireGameToken() {
|
||||
// required for IStreamable serialization
|
||||
public EscritoireGameToken(PacketBufferForestry data) throws IOException {
|
||||
readData(data);
|
||||
}
|
||||
|
||||
public EscritoireGameToken(String speciesUid) {
|
||||
|
||||
@@ -53,8 +53,7 @@ public class PacketWorktableRecipeRequest extends ForestryPacket implements IFor
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException {
|
||||
BlockPos pos = data.readBlockPos();
|
||||
MemorizedRecipe recipe = new MemorizedRecipe();
|
||||
recipe.readData(data);
|
||||
MemorizedRecipe recipe = new MemorizedRecipe(data);
|
||||
|
||||
TileEntity tile = player.world.getTileEntity(pos);
|
||||
if (tile instanceof TileWorktable) {
|
||||
|
||||
@@ -52,8 +52,7 @@ public class PacketWorktableRecipeUpdate extends ForestryPacket implements IFore
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException {
|
||||
BlockPos pos = data.readBlockPos();
|
||||
MemorizedRecipe recipe = new MemorizedRecipe();
|
||||
recipe.readData(data);
|
||||
MemorizedRecipe recipe = data.readStreamable(MemorizedRecipe::new);
|
||||
|
||||
TileEntity tile = player.world.getTileEntity(pos);
|
||||
if (tile instanceof TileWorktable) {
|
||||
|
||||
@@ -32,8 +32,12 @@ public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStrea
|
||||
private long lastUsed;
|
||||
private boolean locked;
|
||||
|
||||
public MemorizedRecipe() {
|
||||
// required for IStreamable serialization
|
||||
public MemorizedRecipe(PacketBufferForestry data) throws IOException {
|
||||
readData(data);
|
||||
}
|
||||
|
||||
public MemorizedRecipe(NBTTagCompound nbt) {
|
||||
readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public MemorizedRecipe(InventoryCraftingForestry craftMatrix, NonNullList<ItemStack> recipeOutputs) {
|
||||
|
||||
@@ -53,8 +53,7 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
NBTTagList nbttaglist = nbt.getTagList("RecipeMemory", 10);
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||
NBTTagCompound recipeNbt = nbttaglist.getCompoundTagAt(j);
|
||||
MemorizedRecipe recipe = new MemorizedRecipe();
|
||||
recipe.readFromNBT(recipeNbt);
|
||||
MemorizedRecipe recipe = new MemorizedRecipe(recipeNbt);
|
||||
memorizedRecipes.add(recipe);
|
||||
}
|
||||
}
|
||||
@@ -202,6 +201,6 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
|
||||
@Override
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
data.readStreamables(memorizedRecipes, MemorizedRecipe.class);
|
||||
data.readStreamables(memorizedRecipes, MemorizedRecipe::new);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user