Skip to content

Commit

Permalink
made it_in slots only accept 1 stack each of an item
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Sep 21, 2023
1 parent a1f909e commit 80ceae4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package muramasa.antimatter.capability.item;

import muramasa.antimatter.capability.IGuiHandler;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.machine.event.ContentEvent;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.function.BiPredicate;

public class FakeTrackedItemHandler<T extends IGuiHandler> extends TrackedItemHandler<T> {
public FakeTrackedItemHandler(T tile, int size, boolean output, boolean input, BiPredicate<IGuiHandler, ItemStack> validator, ContentEvent contentEvent) {
super(tile, size, output, input, validator, contentEvent);
public FakeTrackedItemHandler(T tile, SlotType<?> type, int size, boolean output, boolean input, BiPredicate<IGuiHandler, ItemStack> validator, ContentEvent contentEvent) {
super(tile, type, size, output, input, validator, contentEvent);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import muramasa.antimatter.capability.IGuiHandler;
import muramasa.antimatter.cover.ICover;
import muramasa.antimatter.gui.SlotType;
import muramasa.antimatter.machine.event.ContentEvent;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.util.Utils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
Expand All @@ -19,12 +21,13 @@ public class TrackedItemHandler<T extends IGuiHandler> extends ItemStackHandler
private final BiPredicate<IGuiHandler, ItemStack> validator;
private final int limit;
private final int size;
private final SlotType<?> type;

public TrackedItemHandler(T tile, int size, boolean output, boolean input, BiPredicate<IGuiHandler, ItemStack> validator, ContentEvent contentEvent) {
this(tile, size, output, input, validator, contentEvent, 64);
public TrackedItemHandler(T tile, SlotType<?> type, int size, boolean output, boolean input, BiPredicate<IGuiHandler, ItemStack> validator, ContentEvent contentEvent) {
this(tile, type, size, output, input, validator, contentEvent, 64);
}

public TrackedItemHandler(T tile, int size, boolean output, boolean input, BiPredicate<IGuiHandler, ItemStack> validator, ContentEvent contentEvent, int limit) {
public TrackedItemHandler(T tile, SlotType<?> type, int size, boolean output, boolean input, BiPredicate<IGuiHandler, ItemStack> validator, ContentEvent contentEvent, int limit) {
super(size);
this.tile = tile;
this.output = output;
Expand All @@ -33,6 +36,7 @@ public TrackedItemHandler(T tile, int size, boolean output, boolean input, BiPre
this.validator = validator;
this.limit = limit;
this.size = size;
this.type = type;
}

@Override
Expand All @@ -54,6 +58,13 @@ public void onContentsChanged(int slot) {
@NotNull
@Override
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
if (this.type == SlotType.IT_IN){
for (int i = 0; i < size; i++){
if (i == slot) continue;
if (this.getItem(i).isEmpty()) continue;
if (Utils.equals(this.getItem(i), stack)) return stack;
}
}
if (!input)
return stack;
boolean validate = validator.test(tile, stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public MachineItemHandler(T tile) {
SlotType<?> type = entry.getKey();
int count = tile.getMachineType().getCount(tile.getMachineTier(), entry.getKey());
if (type == SlotType.DISPLAY_SETTABLE || type == SlotType.DISPLAY) {
inventories.put(type, new FakeTrackedItemHandler<>(tile, count, type.output, type.input, type.tester, type.ev));
inventories.put(type, new FakeTrackedItemHandler<>(tile, type, count, type.output, type.input, type.tester, type.ev));
} else {
inventories.put(type, new TrackedItemHandler<>(tile, count, type.output, type.input, type.tester, type.ev));
inventories.put(type, new TrackedItemHandler<>(tile, type, count, type.output, type.input, type.tester, type.ev));
}

}
}
inventories.defaultReturnValue(new TrackedItemHandler<>(tile, 0, false, false, (a, b) -> false, null));
inventories.defaultReturnValue(new TrackedItemHandler<>(tile, SlotType.STORAGE, 0, false, false, (a, b) -> false, null));
}

public Map<SlotType<?>, ExtendedItemContainer> getAll() {
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/muramasa/antimatter/cover/BaseCover.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ private void setInventory(){
SlotType<?> type = entry.getKey();
int count = gui.getSlots().getCount(tier, entry.getKey());
if (type == SlotType.DISPLAY_SETTABLE || type == SlotType.DISPLAY) {
inventories.put(type, new FakeTrackedItemHandler<>(this, count, type.output, type.input, type.tester, type.ev));
inventories.put(type, new FakeTrackedItemHandler<>(this, type, count, type.output, type.input, type.tester, type.ev));
} else {
inventories.put(type, new TrackedItemHandler<>(this, count, type.output, type.input, type.tester, type.ev));
inventories.put(type, new TrackedItemHandler<>(this, type, count, type.output, type.input, type.tester, type.ev));
}

}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 80ceae4

Please sign in to comment.