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:
@@ -64,7 +64,7 @@ import appeng.client.me.SlotME;
|
||||
import appeng.client.render.StackSizeRenderer;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.*;
|
||||
import appeng.container.slot.AppEngSlot.hasCalculatedValidness;
|
||||
import appeng.container.slot.AppEngSlot.CalculatedValidity;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
@@ -701,7 +701,8 @@ public abstract class AEBaseGui<T extends AEBaseContainer> extends ContainerScre
|
||||
}
|
||||
|
||||
if (!is.isEmpty() && s instanceof AppEngSlot) {
|
||||
if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.NotAvailable) {
|
||||
AppEngSlot aeSlot = (AppEngSlot) s;
|
||||
if (aeSlot.getIsValid() == CalculatedValidity.NotAvailable) {
|
||||
boolean isValid = s.isItemValid(is) || s instanceof SlotOutput
|
||||
|| s instanceof AppEngCraftingSlot || s instanceof SlotDisabled
|
||||
|| s instanceof SlotInaccessible || s instanceof SlotFake
|
||||
@@ -713,11 +714,10 @@ public abstract class AEBaseGui<T extends AEBaseContainer> extends ContainerScre
|
||||
AELog.debug(err);
|
||||
}
|
||||
}
|
||||
((AppEngSlot) s)
|
||||
.setIsValid(isValid ? hasCalculatedValidness.Valid : hasCalculatedValidness.Invalid);
|
||||
aeSlot.setIsValid(isValid ? CalculatedValidity.Valid : CalculatedValidity.Invalid);
|
||||
}
|
||||
|
||||
if (((AppEngSlot) s).getIsValid() == hasCalculatedValidness.Invalid) {
|
||||
if (aeSlot.getIsValid() == CalculatedValidity.Invalid) {
|
||||
setBlitOffset(100);
|
||||
this.itemRenderer.zLevel = 100.0F;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user