mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 00:16:27 +01:00
The magical bucket
- Fixed basins consuming container items with certain output inventories - Potentially fixed item duplication with stale contraption inventories
This commit is contained in:
parent
6b5e223508
commit
32b0a01c3a
3 changed files with 70 additions and 8 deletions
|
@ -63,6 +63,7 @@ import net.minecraft.block.SlimeBlock;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.nbt.ListNBT;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
|
@ -85,6 +86,7 @@ import net.minecraftforge.common.util.Constants.NBT;
|
|||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
|
@ -607,12 +609,12 @@ public abstract class Contraption {
|
|||
int index = 0;
|
||||
for (MountedStorage mountedStorage : storage.values())
|
||||
handlers[index++] = mountedStorage.getItemHandler();
|
||||
|
||||
|
||||
IFluidHandler[] fluidHandlers = new IFluidHandler[fluidStorage.size()];
|
||||
index = 0;
|
||||
for (MountedFluidStorage mountedStorage : fluidStorage.values())
|
||||
fluidHandlers[index++] = mountedStorage.getFluidHandler();
|
||||
|
||||
|
||||
inventory = new CombinedInvWrapper(handlers);
|
||||
fluidInventory = new CombinedTankWrapper(fluidHandlers);
|
||||
|
||||
|
@ -825,6 +827,11 @@ public abstract class Contraption {
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSlots(); i++)
|
||||
inventory.setStackInSlot(i, ItemStack.EMPTY);
|
||||
for (int i = 0; i < fluidInventory.getTanks(); i++)
|
||||
fluidInventory.drain(fluidInventory.getFluidInTank(i), FluidAction.EXECUTE);
|
||||
|
||||
for (Pair<BlockPos, Direction> pair : superglue) {
|
||||
BlockPos targetPos = transform.apply(pair.getKey());
|
||||
Direction targetFacing = transform.transformFacing(pair.getValue());
|
||||
|
|
|
@ -158,6 +158,7 @@ public class BasinBlock extends Block implements ITE<BasinTileEntity>, IWrenchab
|
|||
withTileEntityDo(worldIn, pos, te -> {
|
||||
ItemHelper.dropContents(worldIn, pos, te.inputInventory);
|
||||
ItemHelper.dropContents(worldIn, pos, te.outputInventory);
|
||||
te.spoutputBuffer.forEach(is -> Block.spawnAsEntity(worldIn, pos, is));
|
||||
});
|
||||
worldIn.removeTileEntity(pos);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.processing;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
@ -33,6 +34,7 @@ import com.simibubi.create.foundation.utility.LerpedFloat.Chaser;
|
|||
import com.simibubi.create.foundation.utility.NBTHelper;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
|
@ -82,6 +84,7 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
|
||||
List<Direction> disabledSpoutputs;
|
||||
Direction preferredSpoutput;
|
||||
protected List<ItemStack> spoutputBuffer;
|
||||
|
||||
public static final int OUTPUT_ANIMATION_TIME = 10;
|
||||
List<IntAttached<ItemStack>> visualizedOutputItems;
|
||||
|
@ -106,6 +109,7 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
visualizedOutputFluids = Collections.synchronizedList(new ArrayList<>());
|
||||
disabledSpoutputs = new ArrayList<>();
|
||||
preferredSpoutput = null;
|
||||
spoutputBuffer = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,6 +147,7 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
disabledSpoutputs.clear();
|
||||
ListNBT disabledList = compound.getList("DisabledSpoutput", NBT.TAG_STRING);
|
||||
disabledList.forEach(d -> disabledSpoutputs.add(Direction.valueOf(((StringNBT) d).getString())));
|
||||
spoutputBuffer = NBTHelper.readItemList(compound.getList("Overflow", NBT.TAG_COMPOUND));
|
||||
|
||||
if (!clientPacket)
|
||||
return;
|
||||
|
@ -165,6 +170,7 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
ListNBT disabledList = new ListNBT();
|
||||
disabledSpoutputs.forEach(d -> disabledList.add(StringNBT.of(d.name())));
|
||||
compound.put("DisabledSpoutput", disabledList);
|
||||
compound.put("Overflow", NBTHelper.writeItemList(spoutputBuffer));
|
||||
|
||||
if (!clientPacket)
|
||||
return;
|
||||
|
@ -269,6 +275,10 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
ingredientRotationSpeed.tickChaser();
|
||||
ingredientRotation.setValue(ingredientRotation.getValue() + ingredientRotationSpeed.getValue());
|
||||
}
|
||||
|
||||
if (!spoutputBuffer.isEmpty() && !world.isRemote)
|
||||
tryClearingSpoutputOverflow();
|
||||
|
||||
if (!contentsChanged)
|
||||
return;
|
||||
contentsChanged = false;
|
||||
|
@ -287,6 +297,46 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
}
|
||||
}
|
||||
|
||||
private void tryClearingSpoutputOverflow() {
|
||||
BlockState blockState = getBlockState();
|
||||
if (!(blockState.getBlock() instanceof BasinBlock))
|
||||
return;
|
||||
Direction direction = blockState.get(BasinBlock.FACING);
|
||||
TileEntity te = world.getTileEntity(pos.down()
|
||||
.offset(direction));
|
||||
IItemHandler targetInv = te == null ? null
|
||||
: te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, direction.getOpposite())
|
||||
.orElse(null);
|
||||
boolean update = false;
|
||||
|
||||
for (Iterator<ItemStack> iterator = spoutputBuffer.iterator(); iterator.hasNext();) {
|
||||
ItemStack itemStack = iterator.next();
|
||||
|
||||
if (direction == Direction.DOWN) {
|
||||
Block.spawnAsEntity(world, pos, itemStack);
|
||||
iterator.remove();
|
||||
update = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (targetInv == null)
|
||||
return;
|
||||
if (!ItemHandlerHelper.insertItemStacked(targetInv, itemStack, true)
|
||||
.isEmpty())
|
||||
continue;
|
||||
|
||||
update = true;
|
||||
ItemHandlerHelper.insertItemStacked(targetInv, itemStack.copy(), false);
|
||||
iterator.remove();
|
||||
visualizedOutputItems.add(IntAttached.withZero(itemStack));
|
||||
}
|
||||
|
||||
if (update) {
|
||||
notifyChangeOfContents();
|
||||
sendData();
|
||||
}
|
||||
}
|
||||
|
||||
public float getTotalFluidUnits(float partialTicks) {
|
||||
int renderedFluids = 0;
|
||||
float totalUnits = 0;
|
||||
|
@ -370,6 +420,8 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
|
||||
} else {
|
||||
// Output basin, try moving items to it
|
||||
if (!spoutputBuffer.isEmpty())
|
||||
return false;
|
||||
TileEntity te = world.getTileEntity(pos.down()
|
||||
.offset(direction));
|
||||
if (te == null)
|
||||
|
@ -382,12 +434,14 @@ public class BasinTileEntity extends SmartTileEntity {
|
|||
|
||||
if (targetInv == null && !outputItems.isEmpty())
|
||||
return false;
|
||||
for (ItemStack itemStack : outputItems)
|
||||
if (!ItemHandlerHelper.insertItemStacked(targetInv, itemStack.copy(), simulate)
|
||||
.isEmpty())
|
||||
return false;
|
||||
else if (!simulate)
|
||||
visualizedOutputItems.add(IntAttached.withZero(itemStack));
|
||||
for (ItemStack itemStack : outputItems) {
|
||||
if (simulate) {
|
||||
if (!ItemHandlerHelper.insertItemStacked(targetInv, itemStack.copy(), simulate)
|
||||
.isEmpty())
|
||||
return false;
|
||||
} else
|
||||
spoutputBuffer.add(itemStack.copy());
|
||||
}
|
||||
|
||||
if (outputFluids.isEmpty())
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue