mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
Fix chest minecarts clearing their inventory when disassembled
This commit is contained in:
parent
55abcde5d5
commit
51c0e347b8
2 changed files with 37 additions and 15 deletions
|
@ -119,7 +119,7 @@ public abstract class Contraption {
|
|||
|
||||
public Optional<List<AxisAlignedBB>> simplifiedEntityColliders;
|
||||
public AbstractContraptionEntity entity;
|
||||
public CombinedInvWrapper inventory;
|
||||
public ContraptionInvWrapper inventory;
|
||||
public CombinedTankWrapper fluidInventory;
|
||||
public AxisAlignedBB bounds;
|
||||
public BlockPos anchor;
|
||||
|
@ -252,7 +252,7 @@ public abstract class Contraption {
|
|||
.stream()
|
||||
.map(MountedStorage::getItemHandler)
|
||||
.collect(Collectors.toList());
|
||||
inventory = new CombinedInvWrapper(Arrays.copyOf(list.toArray(), list.size(), IItemHandlerModifiable[].class));
|
||||
inventory = new ContraptionInvWrapper(Arrays.copyOf(list.toArray(), list.size(), IItemHandlerModifiable[].class));
|
||||
|
||||
List<IFluidHandler> fluidHandlers = fluidStorage.values()
|
||||
.stream()
|
||||
|
@ -739,7 +739,7 @@ public abstract class Contraption {
|
|||
for (MountedFluidStorage mountedStorage : fluidStorage.values())
|
||||
fluidHandlers[index++] = mountedStorage.getFluidHandler();
|
||||
|
||||
inventory = new CombinedInvWrapper(handlers);
|
||||
inventory = new ContraptionInvWrapper(handlers);
|
||||
fluidInventory = new CombinedTankWrapper(fluidHandlers);
|
||||
|
||||
if (nbt.contains("BoundsFront"))
|
||||
|
@ -1053,8 +1053,10 @@ public abstract class Contraption {
|
|||
BlockFlags.IS_MOVING | BlockFlags.DEFAULT, 512);
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSlots(); i++)
|
||||
for (int i = 0; i < inventory.getSlots(); i++) {
|
||||
if (!inventory.isSlotExternal(i))
|
||||
inventory.setStackInSlot(i, ItemStack.EMPTY);
|
||||
}
|
||||
for (int i = 0; i < fluidInventory.getTanks(); i++)
|
||||
fluidInventory.drain(fluidInventory.getFluidInTank(i), FluidAction.EXECUTE);
|
||||
|
||||
|
@ -1261,4 +1263,24 @@ public abstract class Contraption {
|
|||
return pos.equals(te.getPos());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ContraptionInvWrapper extends CombinedInvWrapper {
|
||||
protected final boolean isExternal;
|
||||
|
||||
public ContraptionInvWrapper(boolean isExternal, IItemHandlerModifiable... itemHandler) {
|
||||
super(itemHandler);
|
||||
this.isExternal = isExternal;
|
||||
}
|
||||
|
||||
public ContraptionInvWrapper(IItemHandlerModifiable... itemHandler) {
|
||||
this(false, itemHandler);
|
||||
}
|
||||
|
||||
public boolean isSlotExternal(int slot) {
|
||||
if (isExternal)
|
||||
return true;
|
||||
IItemHandlerModifiable handler = getHandlerFromIndex(getIndexForSlot(slot));
|
||||
return handler instanceof ContraptionInvWrapper && ((ContraptionInvWrapper) handler).isSlotExternal(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,8 +159,8 @@ public class MountedContraption extends Contraption {
|
|||
public void addExtraInventories(Entity cart) {
|
||||
if (!(cart instanceof IInventory))
|
||||
return;
|
||||
IItemHandlerModifiable handlerFromInv = new InvWrapper((IInventory) cart);
|
||||
inventory = new CombinedInvWrapper(handlerFromInv, inventory);
|
||||
IItemHandlerModifiable handlerFromInv = new ContraptionInvWrapper(true, new InvWrapper((IInventory) cart));
|
||||
inventory = new ContraptionInvWrapper(handlerFromInv, inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue