mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-01 01:46:39 +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 Optional<List<AxisAlignedBB>> simplifiedEntityColliders;
|
||||||
public AbstractContraptionEntity entity;
|
public AbstractContraptionEntity entity;
|
||||||
public CombinedInvWrapper inventory;
|
public ContraptionInvWrapper inventory;
|
||||||
public CombinedTankWrapper fluidInventory;
|
public CombinedTankWrapper fluidInventory;
|
||||||
public AxisAlignedBB bounds;
|
public AxisAlignedBB bounds;
|
||||||
public BlockPos anchor;
|
public BlockPos anchor;
|
||||||
|
@ -252,7 +252,7 @@ public abstract class Contraption {
|
||||||
.stream()
|
.stream()
|
||||||
.map(MountedStorage::getItemHandler)
|
.map(MountedStorage::getItemHandler)
|
||||||
.collect(Collectors.toList());
|
.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()
|
List<IFluidHandler> fluidHandlers = fluidStorage.values()
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -739,7 +739,7 @@ public abstract class Contraption {
|
||||||
for (MountedFluidStorage mountedStorage : fluidStorage.values())
|
for (MountedFluidStorage mountedStorage : fluidStorage.values())
|
||||||
fluidHandlers[index++] = mountedStorage.getFluidHandler();
|
fluidHandlers[index++] = mountedStorage.getFluidHandler();
|
||||||
|
|
||||||
inventory = new CombinedInvWrapper(handlers);
|
inventory = new ContraptionInvWrapper(handlers);
|
||||||
fluidInventory = new CombinedTankWrapper(fluidHandlers);
|
fluidInventory = new CombinedTankWrapper(fluidHandlers);
|
||||||
|
|
||||||
if (nbt.contains("BoundsFront"))
|
if (nbt.contains("BoundsFront"))
|
||||||
|
@ -1053,8 +1053,10 @@ public abstract class Contraption {
|
||||||
BlockFlags.IS_MOVING | BlockFlags.DEFAULT, 512);
|
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);
|
inventory.setStackInSlot(i, ItemStack.EMPTY);
|
||||||
|
}
|
||||||
for (int i = 0; i < fluidInventory.getTanks(); i++)
|
for (int i = 0; i < fluidInventory.getTanks(); i++)
|
||||||
fluidInventory.drain(fluidInventory.getFluidInTank(i), FluidAction.EXECUTE);
|
fluidInventory.drain(fluidInventory.getFluidInTank(i), FluidAction.EXECUTE);
|
||||||
|
|
||||||
|
@ -1261,4 +1263,24 @@ public abstract class Contraption {
|
||||||
return pos.equals(te.getPos());
|
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) {
|
public void addExtraInventories(Entity cart) {
|
||||||
if (!(cart instanceof IInventory))
|
if (!(cart instanceof IInventory))
|
||||||
return;
|
return;
|
||||||
IItemHandlerModifiable handlerFromInv = new InvWrapper((IInventory) cart);
|
IItemHandlerModifiable handlerFromInv = new ContraptionInvWrapper(true, new InvWrapper((IInventory) cart));
|
||||||
inventory = new CombinedInvWrapper(handlerFromInv, inventory);
|
inventory = new ContraptionInvWrapper(handlerFromInv, inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue