Don't use PacketBuffer#readString since it's client-only. (#4489)

Fixes #4488
This commit is contained in:
shartte
2020-07-22 10:22:28 +02:00
committed by GitHub
parent f7ef6eb772
commit 21aa5ce33b
5 changed files with 17 additions and 5 deletions
@@ -32,6 +32,15 @@ import appeng.core.sync.network.INetworkInfo;
import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.NetworkHandler;
public abstract class BasePacket { public abstract class BasePacket {
/**
* Sadly {@link PacketBuffer#readString()} gets inlined by Proguard which means
* it's not available on the Server. This field has the default string length
* that is used for writeString, which then also should be used for readString
* when it has no special length requirements.
*/
public static final int MAX_STRING_LENGTH = 32767;
private PacketBuffer p; private PacketBuffer p;
public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) { public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) {
@@ -57,8 +57,8 @@ public class ConfigValuePacket extends BasePacket {
private final String Value; private final String Value;
public ConfigValuePacket(final PacketBuffer stream) { public ConfigValuePacket(final PacketBuffer stream) {
this.Name = stream.readString(); this.Name = stream.readString(MAX_STRING_LENGTH);
this.Value = stream.readString(); this.Value = stream.readString(MAX_STRING_LENGTH);
} }
// api // api
@@ -21,6 +21,7 @@ import net.minecraftforge.registries.ForgeRegistryEntry;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.AppEng; import appeng.core.AppEng;
import appeng.core.sync.BasePacket;
public class GrinderRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> public class GrinderRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>>
implements IRecipeSerializer<GrinderRecipe> { implements IRecipeSerializer<GrinderRecipe> {
@@ -70,7 +71,7 @@ public class GrinderRecipeSerializer extends ForgeRegistryEntry<IRecipeSerialize
@Override @Override
public GrinderRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { public GrinderRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
String group = buffer.readString(); String group = buffer.readString(BasePacket.MAX_STRING_LENGTH);
Ingredient ingredient = Ingredient.read(buffer); Ingredient ingredient = Ingredient.read(buffer);
int ingredientCount = buffer.readVarInt(); int ingredientCount = buffer.readVarInt();
ItemStack result = buffer.readItemStack(); ItemStack result = buffer.readItemStack();
@@ -15,6 +15,7 @@ import net.minecraftforge.registries.ForgeRegistryEntry;
import appeng.api.features.InscriberProcessType; import appeng.api.features.InscriberProcessType;
import appeng.core.AppEng; import appeng.core.AppEng;
import appeng.core.sync.BasePacket;
public class InscriberRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>> public class InscriberRecipeSerializer extends ForgeRegistryEntry<IRecipeSerializer<?>>
implements IRecipeSerializer<InscriberRecipe> { implements IRecipeSerializer<InscriberRecipe> {
@@ -67,7 +68,7 @@ public class InscriberRecipeSerializer extends ForgeRegistryEntry<IRecipeSeriali
@Nullable @Nullable
@Override @Override
public InscriberRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { public InscriberRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
String group = buffer.readString(); String group = buffer.readString(BasePacket.MAX_STRING_LENGTH);
Ingredient middle = Ingredient.read(buffer); Ingredient middle = Ingredient.read(buffer);
ItemStack result = buffer.readItemStack(); ItemStack result = buffer.readItemStack();
Ingredient top = Ingredient.read(buffer); Ingredient top = Ingredient.read(buffer);
@@ -65,6 +65,7 @@ import appeng.block.storage.DriveSlotsState;
import appeng.client.render.model.DriveModelData; import appeng.client.render.model.DriveModelData;
import appeng.container.implementations.DriveContainer; import appeng.container.implementations.DriveContainer;
import appeng.core.Api; import appeng.core.Api;
import appeng.core.sync.BasePacket;
import appeng.helpers.IPriorityHost; import appeng.helpers.IPriorityHost;
import appeng.me.GridAccessException; import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource; import appeng.me.helpers.MachineSource;
@@ -188,7 +189,7 @@ public class DriveTileEntity extends AENetworkInvTileEntity implements IChestOrD
int uniqueStrCount = data.readByte(); int uniqueStrCount = data.readByte();
String[] uniqueStrs = new String[uniqueStrCount]; String[] uniqueStrs = new String[uniqueStrCount];
for (int i = 0; i < uniqueStrCount; i++) { for (int i = 0; i < uniqueStrCount; i++) {
uniqueStrs[i] = data.readString(); uniqueStrs[i] = data.readString(BasePacket.MAX_STRING_LENGTH);
} }
boolean changed = false; boolean changed = false;