Skip to content

Commit 4539e5a

Browse files
committed
remove unneeded method
cleanup + clarify variables
1 parent 21c8460 commit 4539e5a

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

src/main/java/gregtech/common/metatileentities/storage/CraftingRecipeMemory.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import net.minecraftforge.items.IItemHandlerModifiable;
1010
import net.minecraftforge.items.ItemStackHandler;
1111

12+
import com.cleanroommc.modularui.network.NetworkUtils;
1213
import com.cleanroommc.modularui.utils.MouseData;
1314
import com.cleanroommc.modularui.value.sync.SyncHandler;
1415
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
1516
import org.jetbrains.annotations.NotNull;
1617
import org.jetbrains.annotations.Nullable;
1718

18-
import java.io.IOException;
1919
import java.util.Map;
2020

2121
public class CraftingRecipeMemory extends SyncHandler {
@@ -161,7 +161,7 @@ public void readOnClient(int id, PacketBuffer buf) {
161161
int index = buf.readByte();
162162
var recipe = memorizedRecipes[index];
163163
if (recipe == null) recipe = new MemorizedRecipe(index);
164-
recipe.recipeResult = readStackSafe(buf);
164+
recipe.recipeResult = NetworkUtils.readItemStack(buf);
165165
recipe.index = index;
166166
memorizedRecipes[index] = recipe;
167167
} else if (id == 4) {
@@ -183,7 +183,7 @@ public void writeRecipes(PacketBuffer buf) {
183183
for (var entry : written.entrySet()) {
184184
var recipe = memorizedRecipes[entry.getKey()];
185185
buf.writeByte(recipe.index);
186-
buf.writeItemStack(recipe.recipeResult);
186+
NetworkUtils.writeItemStack(buf, recipe.recipeResult);
187187
buf.writeInt(recipe.timesUsed);
188188
buf.writeBoolean(recipe.isRecipeLocked());
189189
}
@@ -196,7 +196,7 @@ public void readRecipes(PacketBuffer buf) {
196196
if (!hasRecipe(index))
197197
memorizedRecipes[index] = new MemorizedRecipe(index);
198198

199-
memorizedRecipes[index].recipeResult = readStackSafe(buf);
199+
memorizedRecipes[index].recipeResult = NetworkUtils.readItemStack(buf);
200200
memorizedRecipes[index].timesUsed = buf.readInt();
201201
memorizedRecipes[index].recipeLocked = buf.readBoolean();
202202
}
@@ -223,14 +223,6 @@ public void readOnServer(int id, PacketBuffer buf) {
223223
}
224224
}
225225

226-
private static ItemStack readStackSafe(PacketBuffer buffer) {
227-
ItemStack ret = ItemStack.EMPTY;
228-
try {
229-
ret = buffer.readItemStack();
230-
} catch (IOException ignored) {}
231-
return ret;
232-
}
233-
234226
public static class MemorizedRecipe {
235227

236228
private final ItemStackHandler craftingMatrix = new ItemStackHandler(9);
@@ -264,13 +256,13 @@ private static MemorizedRecipe deserializeNBT(NBTTagCompound tagCompound, int in
264256
private void writeToBuffer(PacketBuffer buffer) {
265257
buffer.writeByte(this.index);
266258
buffer.writeInt(this.timesUsed);
267-
buffer.writeItemStack(this.recipeResult);
259+
NetworkUtils.writeItemStack(buffer, this.recipeResult);
268260
}
269261

270262
private static @NotNull MemorizedRecipe fromBuffer(PacketBuffer buffer) {
271263
var recipe = new MemorizedRecipe(buffer.readByte());
272264
recipe.timesUsed = buffer.readInt();
273-
recipe.recipeResult = readStackSafe(buffer);
265+
recipe.recipeResult = NetworkUtils.readItemStack(buffer);
274266
return recipe;
275267
}
276268

src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package gregtech.common.mui.widget.workbench;
22

3+
import gregtech.api.util.GTUtility;
34
import gregtech.client.utils.RenderUtil;
45
import gregtech.common.metatileentities.storage.CraftingRecipeLogic;
56

@@ -13,6 +14,7 @@
1314
import com.cleanroommc.modularui.drawable.GuiDraw;
1415
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
1516
import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider;
17+
import com.cleanroommc.modularui.network.NetworkUtils;
1618
import com.cleanroommc.modularui.screen.RichTooltip;
1719
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
1820
import com.cleanroommc.modularui.theme.WidgetTheme;
@@ -23,8 +25,6 @@
2325
import org.jetbrains.annotations.NotNull;
2426
import org.jetbrains.annotations.Nullable;
2527

26-
import java.io.IOException;
27-
2828
public class CraftingInputSlot extends Widget<CraftingOutputSlot> implements Interactable,
2929
JeiGhostIngredientSlot<ItemStack>,
3030
JeiIngredientProvider {
@@ -149,21 +149,22 @@ public void init(String key, PanelSyncManager syncHandler) {
149149
@Override
150150
public void readOnClient(int id, PacketBuffer buf) {
151151
if (id == 1) {
152-
boolean c = buf.readBoolean();
153-
var s = readStackSafe(buf);
154-
boolean i = buf.readBoolean();
155-
this.handler.setStackInSlot(this.index, s);
156-
this.listener.onChange(s, c, true, i);
152+
boolean onlyAmt = buf.readBoolean();
153+
var stack = NetworkUtils.readItemStack(buf);
154+
boolean init = buf.readBoolean();
155+
156+
this.handler.setStackInSlot(this.index, stack);
157+
this.listener.onChange(stack, onlyAmt, true, init);
157158
}
158159
}
159160

160161
@Override
161162
public void readOnServer(int id, PacketBuffer buf) {
162163
if (id == 1) {
163-
var b = buf.readBoolean();
164-
var s = readStackSafe(buf);
165-
this.handler.setStackInSlot(this.index, s);
166-
this.listener.onChange(s, b, false, false);
164+
var onlyAmt = buf.readBoolean();
165+
var stack = NetworkUtils.readItemStack(buf);
166+
this.handler.setStackInSlot(this.index, stack);
167+
this.listener.onChange(stack, onlyAmt, false, false);
167168
}
168169
}
169170

@@ -184,23 +185,22 @@ public void detectAndSendChanges(boolean init) {
184185
final boolean finalOnlyAmountChanged = onlyAmountChanged;
185186
syncToClient(1, buffer -> {
186187
buffer.writeBoolean(finalOnlyAmountChanged);
187-
buffer.writeItemStack(itemStack);
188+
NetworkUtils.writeItemStack(buffer, itemStack);
188189
buffer.writeBoolean(init);
189190
});
190191
}
191192
}
192193

193194
public void syncStack() {
194-
final var cursorStack = getSyncManager().getCursorItem().copy();
195-
cursorStack.setCount(1);
195+
final var cursorStack = GTUtility.copy(1, getSyncManager().getCursorItem());
196196
final var curStack = getStack();
197197
final boolean onlyAmt = ItemHandlerHelper.canItemStacksStackRelaxed(curStack, cursorStack);
198198

199199
this.handler.setStackInSlot(this.index, cursorStack);
200200
this.listener.onChange(cursorStack, onlyAmt, true, false);
201201
syncToServer(1, buffer -> {
202202
buffer.writeBoolean(onlyAmt);
203-
buffer.writeItemStack(cursorStack);
203+
NetworkUtils.writeItemStack(buffer, cursorStack);
204204
});
205205
}
206206

@@ -217,13 +217,5 @@ public void setStack(ItemStack stack) {
217217
this.handler.setStackInSlot(this.index, stack);
218218
this.listener.onChange(stack, false, getSyncManager().isClient(), false);
219219
}
220-
221-
private ItemStack readStackSafe(PacketBuffer buffer) {
222-
ItemStack ret = ItemStack.EMPTY;
223-
try {
224-
ret = buffer.readItemStack();
225-
} catch (IOException ignored) {}
226-
return ret;
227-
}
228220
}
229221
}

0 commit comments

Comments
 (0)