Notify the parent container of a lot more thoroughly when the slot is changed (i.e. items taken from it).

And then make use of that to invalidate the validation state of the crafting pattern in the Molecular Assembler when the pattern is changed.
This commit is contained in:
Sebastian Hartte
2020-06-17 00:23:46 +02:00
parent 52da8bdb67
commit c6437465b7
3 changed files with 41 additions and 16 deletions
@@ -21,6 +21,7 @@ package appeng.container.implementations;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;
@@ -33,6 +34,7 @@ import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.container.ContainerLocator;
import appeng.container.guisync.GuiSync;
import appeng.container.interfaces.IProgressProvider;
import appeng.container.slot.AppEngSlot;
import appeng.container.slot.SlotMolecularAssemblerPattern;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
@@ -60,6 +62,8 @@ public class ContainerMolecularAssembler extends ContainerUpgradeable implements
@GuiSync(4)
public int craftProgress = 0;
private Slot encodedPatternSlot;
public ContainerMolecularAssembler(int id, final PlayerInventory ip, final TileMolecularAssembler te) {
super(TYPE, id, ip, te);
this.tma = te;
@@ -108,8 +112,9 @@ public class ContainerMolecularAssembler extends ContainerUpgradeable implements
offX = 126;
offY = 16;
this.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10,
offX, offY, this.getPlayerInventory()));
encodedPatternSlot = this
.addSlot(new SlotRestrictedInput(SlotRestrictedInput.PlacableItemType.ENCODED_CRAFTING_PATTERN, mac, 10,
offX, offY, this.getPlayerInventory()));
this.addSlot(new SlotOutput(mac, 9, offX, offY + 32, -1));
offX = 122;
@@ -161,4 +166,19 @@ public class ContainerMolecularAssembler extends ContainerUpgradeable implements
public int getMaxProgress() {
return MAX_CRAFT_PROGRESS;
}
@Override
public void onSlotChange(Slot s) {
// If the pattern changes, the crafting grid slots lose validity
if (s == encodedPatternSlot) {
for (Slot otherSlot : inventorySlots) {
if (otherSlot != s && otherSlot instanceof AppEngSlot) {
((AppEngSlot) otherSlot).setIsValid(AppEngSlot.CalculatedValidity.NotAvailable);
}
}
}
}
}
@@ -43,7 +43,7 @@ public class AppEngSlot extends Slot {
private boolean isPlayerSide = false;
private AEBaseContainer myContainer = null;
private int IIcon = -1;
private hasCalculatedValidness isValid;
private CalculatedValidity isValid;
private boolean isDisplay = false;
public AppEngSlot(final IItemHandler inv, final int idx, final int x, final int y) {
@@ -53,7 +53,7 @@ public class AppEngSlot extends Slot {
this.defX = x;
this.defY = y;
this.setIsValid(hasCalculatedValidness.NotAvailable);
this.setIsValid(CalculatedValidity.NotAvailable);
}
public Slot setNotDraggable() {
@@ -105,10 +105,13 @@ public class AppEngSlot extends Slot {
public void putStack(final ItemStack stack) {
if (this.isSlotEnabled()) {
ItemHandlerUtil.setStackInSlot(this.itemHandler, this.index, stack);
this.onSlotChanged();
}
}
if (this.getContainer() != null) {
this.getContainer().onSlotChange(this);
}
private void notifyContainerSlotChanged() {
if (this.getContainer() != null) {
this.getContainer().onSlotChange(this);
}
}
@@ -118,7 +121,9 @@ public class AppEngSlot extends Slot {
@Override
public void onSlotChanged() {
this.setIsValid(hasCalculatedValidness.NotAvailable);
super.onSlotChanged();
this.setIsValid(CalculatedValidity.NotAvailable);
notifyContainerSlotChanged();
}
@Override
@@ -220,11 +225,11 @@ public class AppEngSlot extends Slot {
this.isPlayerSide = isPlayerSide;
}
public hasCalculatedValidness getIsValid() {
public CalculatedValidity getIsValid() {
return this.isValid;
}
public void setIsValid(final hasCalculatedValidness isValid) {
public void setIsValid(final CalculatedValidity isValid) {
this.isValid = isValid;
}
@@ -236,7 +241,7 @@ public class AppEngSlot extends Slot {
this.myContainer = myContainer;
}
public enum hasCalculatedValidness {
public enum CalculatedValidity {
NotAvailable, Valid, Invalid
}
}