Skip to content

Commit 32cd980

Browse files
fix: AI Comments
1 parent e5f7ae5 commit 32cd980

4 files changed

Lines changed: 39 additions & 13 deletions

File tree

src/main/java/com/tcm/MineTale/block/workbenches/FurnaceWorkbench.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ public class FurnaceWorkbench extends AbstractWorkbench<FurnaceWorkbenchEntity>
2121
private static final boolean IS_WIDE = true;
2222
private static final boolean IS_TALL = true;
2323

24-
public static final MapCodec<FurnaceWorkbench> CODEC = simpleCodec((properties) ->
25-
new FurnaceWorkbench(properties, () -> null));
24+
public static final MapCodec<FurnaceWorkbench> CODEC = simpleCodec(FurnaceWorkbench::new);
2625

2726
/**
2827
* Standard constructor for registration.

src/main/java/com/tcm/MineTale/block/workbenches/entity/AbstractWorkbenchEntity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public AbstractWorkbenchEntity(BlockEntityType<?> type, BlockPos pos, BlockState
3232
// --- CHEST SCANNING ---
3333
public List<Container> getNearbyInventories() {
3434
List<Container> inventories = new ArrayList<>();
35+
if (level == null) {
36+
return inventories;
37+
}
3538
BlockPos.betweenClosed(
3639
worldPosition.offset((int)-scanRadius, -2, (int)-scanRadius),
3740
worldPosition.offset((int)scanRadius, 2, (int)scanRadius)

src/main/java/com/tcm/MineTale/block/workbenches/entity/FurnaceWorkbenchEntity.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public class FurnaceWorkbenchEntity extends AbstractWorkbenchEntity {
2727
// 0 -> Fuel Slots
2828
// 1, 2 -> Input Slot
2929
// 3-6 -> Output Slots
30+
private static final int FUEL_SLOT = 0;
31+
private static final int INPUT_1 = 1;
32+
private static final int INPUT_2 = 2;
33+
private static final int OUTPUT_START = 3;
34+
private static final int OUTPUT_END = 6;
3035
private final SimpleContainer inventory = new SimpleContainer(7);
3136

3237
private int cookTime;
@@ -68,8 +73,10 @@ public void tick(Level level, BlockPos pos, BlockState state) {
6873
if (level.isClientSide()) return;
6974

7075
boolean changed = false;
71-
ItemStack input = inventory.getItem(0);
72-
ItemStack fuel = inventory.getItem(1);
76+
ItemStack fuel = inventory.getItem(FUEL_SLOT);
77+
ItemStack input = !inventory.getItem(INPUT_1).isEmpty()
78+
? inventory.getItem(INPUT_1)
79+
: inventory.getItem(INPUT_2);
7380

7481
// TRAIT: Streamline crafting by pulling from nearby chests if input is empty
7582
if (input.isEmpty() && level.getGameTime() % 20 == 0) {
@@ -130,7 +137,10 @@ private void smeltItem(ItemStack input) {
130137
result = new ItemStack(Items.COPPER_INGOT);
131138
}
132139

133-
ItemStack output = inventory.getItem(2);
140+
int outputSlot = findOutputSlot(result);
141+
if (outputSlot == -1) return;
142+
ItemStack output = inventory.getItem(outputSlot);
143+
134144
if (output.isEmpty()) {
135145
inventory.setItem(2, result.copy());
136146
} else if (ItemStack.isSameItem(output, result)) {
@@ -145,14 +155,27 @@ private void pullFromNearbyChests() {
145155
for (int i = 0; i < chest.getContainerSize(); i++) {
146156
ItemStack stack = chest.getItem(i);
147157
if (isOre(stack) || isWood(stack)) {
148-
inventory.setItem(0, stack.split(1));
158+
int inputSlot = inventory.getItem(INPUT_1).isEmpty() ? INPUT_1 : (inventory.getItem(INPUT_2).isEmpty() ? INPUT_2 : -1);
159+
if (inputSlot == -1) return;
160+
inventory.setItem(inputSlot, stack.split(1));
149161
chest.setChanged();
150162
return;
151163
}
152164
}
153165
}
154166
}
155167

168+
private int findOutputSlot(ItemStack result) {
169+
for (int i = OUTPUT_START; i <= OUTPUT_END; i++) {
170+
ItemStack out = inventory.getItem(i);
171+
if (out.isEmpty() || (ItemStack.isSameItem(out, result)
172+
&& out.getCount() + result.getCount() <= out.getMaxStackSize())) {
173+
return i;
174+
}
175+
}
176+
return -1;
177+
}
178+
156179
// --- Helpers ---
157180
private boolean isOre(ItemStack stack) { return stack.is(Items.RAW_COPPER); /* Add more ores */ }
158181
private boolean isWood(ItemStack stack) { return stack.getItem().toString().contains("log"); }

src/main/java/com/tcm/MineTale/block/workbenches/menu/FurnaceWorkbenchMenu.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.tcm.MineTale.registry.ModMenuTypes;
44

5+
import net.minecraft.tags.ItemTags;
56
import net.minecraft.world.Container;
67
import net.minecraft.world.SimpleContainer;
78
import net.minecraft.world.entity.player.Inventory;
@@ -36,6 +37,7 @@ public FurnaceWorkbenchMenu(int syncId, Inventory playerInventory) {
3637
public FurnaceWorkbenchMenu(int syncId, Inventory playerInventory, Container container, ContainerData data) {
3738
super(ModMenuTypes.FURNACE_WORKBENCH_MENU, syncId);
3839
checkContainerSize(container, containerSize);
40+
checkContainerDataCount(data, 4);
3941
this.container = container;
4042
this.data = data;
4143

@@ -47,8 +49,7 @@ public FurnaceWorkbenchMenu(int syncId, Inventory playerInventory, Container con
4749
this.addSlot(new Slot(container, FUEL_SLOT, 80, 53) {
4850
@Override
4951
public boolean mayPlace(ItemStack stack) {
50-
// Trait: Sticks, Fibres (String), and Logs
51-
return stack.is(Items.STICK) || stack.is(Items.STRING) || stack.getItem().toString().contains("log");
52+
return isFuel(stack);
5253
}
5354
});
5455

@@ -57,10 +58,10 @@ public boolean mayPlace(ItemStack stack) {
5758
this.addSlot(new Slot(container, INPUT_2, 44, 35));
5859

5960
// 3. Four Output Slots (2x2 Grid on the right)
60-
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, 3, 116, 21));
61-
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, 4, 134, 21));
62-
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, 5, 116, 39));
63-
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, 6, 134, 39));
61+
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, OUTPUT_START, 116, 21));
62+
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, OUTPUT_START + 1, 134, 21));
63+
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, OUTPUT_END - 1, 116, 39));
64+
this.addSlot(new FurnaceResultSlot(playerInventory.player, container, OUTPUT_END, 134, 39));
6465

6566
// --- PLAYER INVENTORY ---
6667
addPlayerInventory(playerInventory);
@@ -106,7 +107,7 @@ else if (!this.moveItemStackTo(itemStack2, 1, 3, false)) {
106107
}
107108

108109
private boolean isFuel(ItemStack stack) {
109-
return stack.is(Items.STICK) || stack.is(Items.STRING) || stack.getItem().toString().contains("log");
110+
return stack.is(Items.STICK) || stack.is(Items.STRING) || stack.is(ItemTags.LOGS_THAT_BURN);
110111
}
111112

112113
@Override

0 commit comments

Comments
 (0)