mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-18 07:53:07 +01:00
items and fluids should be sub-interfaces
This commit is contained in:
parent
b088843aa1
commit
9647046753
4 changed files with 39 additions and 29 deletions
|
@ -117,7 +117,7 @@ public class ConnectivityHandler {
|
||||||
if (beWidth == bestWidth && beWidth*beWidth * be.getHeight() == bestAmount) return bestAmount;
|
if (beWidth == bestWidth && beWidth*beWidth * be.getHeight() == bestAmount) return bestAmount;
|
||||||
|
|
||||||
splitMultiAndInvalidate(be, cache, false);
|
splitMultiAndInvalidate(be, cache, false);
|
||||||
if (be.hasFluid()) be.setTankSize(0, bestAmount);
|
if (be instanceof IMultiTileContainer.Fluid ifluid && ifluid.hasTank()) ifluid.setTankSize(0, bestAmount);
|
||||||
|
|
||||||
tryToFormNewMultiOfWidth(be, bestWidth, cache, false);
|
tryToFormNewMultiOfWidth(be, bestWidth, cache, false);
|
||||||
|
|
||||||
|
@ -140,8 +140,8 @@ public class ConnectivityHandler {
|
||||||
// optional fluid handling
|
// optional fluid handling
|
||||||
IFluidTank beTank = null;
|
IFluidTank beTank = null;
|
||||||
FluidStack fluid = FluidStack.EMPTY;
|
FluidStack fluid = FluidStack.EMPTY;
|
||||||
if (be.hasFluid()) {
|
if (be instanceof IMultiTileContainer.Fluid ifluid && ifluid.hasTank()) {
|
||||||
beTank = be.getTank(0);
|
beTank = ifluid.getTank(0);
|
||||||
fluid = beTank.getFluid();
|
fluid = beTank.getFluid();
|
||||||
}
|
}
|
||||||
Direction.Axis axis = be.getMainConnectionAxis();
|
Direction.Axis axis = be.getMainConnectionAxis();
|
||||||
|
@ -182,8 +182,10 @@ public class ConnectivityHandler {
|
||||||
if (axis == Direction.Axis.X && conPos.getZ() + otherWidth > origin.getZ() + width) break Search;
|
if (axis == Direction.Axis.X && conPos.getZ() + otherWidth > origin.getZ() + width) break Search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FluidStack otherFluid = controller.getFluid(0);
|
if (controller instanceof IMultiTileContainer.Fluid ifluidCon && ifluidCon.hasTank()) {
|
||||||
if (!fluid.isEmpty() && !otherFluid.isEmpty() && !fluid.isFluidEqual(otherFluid)) break Search;
|
FluidStack otherFluid = ifluidCon.getFluid(0);
|
||||||
|
if (!fluid.isEmpty() && !otherFluid.isEmpty() && !fluid.isFluidEqual(otherFluid)) break Search;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
amount += width * width;
|
amount += width * width;
|
||||||
|
@ -208,15 +210,17 @@ public class ConnectivityHandler {
|
||||||
|
|
||||||
extraData = be.modifyExtraData(extraData);
|
extraData = be.modifyExtraData(extraData);
|
||||||
|
|
||||||
if (part.hasFluid()) {
|
if (part instanceof IMultiTileContainer.Fluid ifluidPart && ifluidPart.hasTank()) {
|
||||||
IFluidTank tankAt = part.getTank(0);
|
IFluidTank tankAt = ifluidPart.getTank(0);
|
||||||
FluidStack fluidAt = tankAt.getFluid();
|
FluidStack fluidAt = tankAt.getFluid();
|
||||||
if (!fluidAt.isEmpty()) {
|
if (!fluidAt.isEmpty()) {
|
||||||
// making this generic would be a rather large mess, unfortunately
|
// making this generic would be a rather large mess, unfortunately
|
||||||
if (beTank != null && fluid.isEmpty() && beTank instanceof CreativeFluidTankTileEntity.CreativeSmartFluidTank) {
|
if (beTank != null && fluid.isEmpty() && beTank instanceof CreativeFluidTankTileEntity.CreativeSmartFluidTank) {
|
||||||
((CreativeFluidTankTileEntity.CreativeSmartFluidTank)beTank).setContainedFluid(fluidAt);
|
((CreativeFluidTankTileEntity.CreativeSmartFluidTank)beTank).setContainedFluid(fluidAt);
|
||||||
}
|
}
|
||||||
if (be.hasFluid() && beTank != null) beTank.fill(fluidAt, IFluidHandler.FluidAction.EXECUTE);
|
if (be instanceof IMultiTileContainer.Fluid ifluidBE && ifluidBE.hasTank() && beTank != null) {
|
||||||
|
beTank.fill(fluidAt, IFluidHandler.FluidAction.EXECUTE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tankAt.drain(tankAt.getCapacity(), IFluidHandler.FluidAction.EXECUTE);
|
tankAt.drain(tankAt.getCapacity(), IFluidHandler.FluidAction.EXECUTE);
|
||||||
}
|
}
|
||||||
|
@ -259,11 +263,11 @@ public class ConnectivityHandler {
|
||||||
// fluid handling, if present
|
// fluid handling, if present
|
||||||
FluidStack toDistribute = FluidStack.EMPTY;
|
FluidStack toDistribute = FluidStack.EMPTY;
|
||||||
int maxCapacity = 0;
|
int maxCapacity = 0;
|
||||||
if (be.hasFluid()) {
|
if (be instanceof IMultiTileContainer.Fluid ifluidBE && ifluidBE.hasTank()) {
|
||||||
toDistribute = be.getFluid(0);
|
toDistribute = ifluidBE.getFluid(0);
|
||||||
maxCapacity = be.getTankSize(0);
|
maxCapacity = ifluidBE.getTankSize(0);
|
||||||
if (!toDistribute.isEmpty() && !be.isRemoved()) toDistribute.shrink(maxCapacity);
|
if (!toDistribute.isEmpty() && !be.isRemoved()) toDistribute.shrink(maxCapacity);
|
||||||
be.setTankSize(0, 1);
|
ifluidBE.setTankSize(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int yOffset = 0; yOffset < height; yOffset++) {
|
for (int yOffset = 0; yOffset < height; yOffset++) {
|
||||||
|
@ -284,7 +288,7 @@ public class ConnectivityHandler {
|
||||||
|
|
||||||
if (!toDistribute.isEmpty() && partAt != be) {
|
if (!toDistribute.isEmpty() && partAt != be) {
|
||||||
FluidStack copy = toDistribute.copy();
|
FluidStack copy = toDistribute.copy();
|
||||||
IFluidTank tank = partAt.getTank(0);
|
IFluidTank tank = (partAt instanceof IMultiTileContainer.Fluid ifluidPart ? ifluidPart.getTank(0) : null);
|
||||||
// making this generic would be a rather large mess, unfortunately
|
// making this generic would be a rather large mess, unfortunately
|
||||||
if (tank instanceof CreativeFluidTankTileEntity.CreativeSmartFluidTank creativeTank) {
|
if (tank instanceof CreativeFluidTankTileEntity.CreativeSmartFluidTank creativeTank) {
|
||||||
if (creativeTank.isEmpty()) creativeTank.setContainedFluid(toDistribute);
|
if (creativeTank.isEmpty()) creativeTank.setContainedFluid(toDistribute);
|
||||||
|
@ -293,7 +297,7 @@ public class ConnectivityHandler {
|
||||||
int split = Math.min(maxCapacity, toDistribute.getAmount());
|
int split = Math.min(maxCapacity, toDistribute.getAmount());
|
||||||
copy.setAmount(split);
|
copy.setAmount(split);
|
||||||
toDistribute.shrink(split);
|
toDistribute.shrink(split);
|
||||||
tank.fill(copy, IFluidHandler.FluidAction.EXECUTE);
|
if (tank != null) tank.fill(copy, IFluidHandler.FluidAction.EXECUTE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tryReconnect) {
|
if (tryReconnect) {
|
||||||
|
@ -306,10 +310,10 @@ public class ConnectivityHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (be.hasItems()) {
|
if (be instanceof IMultiTileContainer.Inventory iinv && iinv.hasInventory()) {
|
||||||
be.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).invalidate();
|
be.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).invalidate();
|
||||||
}
|
}
|
||||||
if (be.hasFluid()) {
|
if (be instanceof IMultiTileContainer.Fluid ifluid && ifluid.hasTank()) {
|
||||||
be.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).invalidate();
|
be.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).invalidate();
|
||||||
}
|
}
|
||||||
if (tryReconnect) {
|
if (tryReconnect) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
||||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||||
|
|
||||||
public class FluidTankTileEntity extends SmartTileEntity implements IHaveGoggleInformation, IMultiTileContainer {
|
public class FluidTankTileEntity extends SmartTileEntity implements IHaveGoggleInformation, IMultiTileContainer.Fluid {
|
||||||
|
|
||||||
private static final int MAX_SIZE = 3;
|
private static final int MAX_SIZE = 3;
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ public class FluidTankTileEntity extends SmartTileEntity implements IHaveGoggleI
|
||||||
public void setWidth(int width) { this.width = width; }
|
public void setWidth(int width) { this.width = width; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasFluid() { return true; }
|
public boolean hasTank() { return true; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTankSize(int tank) { return getCapacityMultiplier(); }
|
public int getTankSize(int tank) { return getCapacityMultiplier(); }
|
||||||
|
|
|
@ -26,7 +26,7 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||||
|
|
||||||
public class ItemVaultTileEntity extends SmartTileEntity implements IMultiTileContainer {
|
public class ItemVaultTileEntity extends SmartTileEntity implements IMultiTileContainer.Inventory {
|
||||||
|
|
||||||
protected LazyOptional<IItemHandler> itemCapability;
|
protected LazyOptional<IItemHandler> itemCapability;
|
||||||
|
|
||||||
|
@ -304,5 +304,5 @@ public class ItemVaultTileEntity extends SmartTileEntity implements IMultiTileCo
|
||||||
public void setWidth(int width) { this.radius = width; }
|
public void setWidth(int width) { this.radius = width; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasItems() { return true; }
|
public boolean hasInventory() { return true; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,14 +56,20 @@ public interface IMultiTileContainer {
|
||||||
int getWidth ();
|
int getWidth ();
|
||||||
void setWidth (int width);
|
void setWidth (int width);
|
||||||
|
|
||||||
// optional item handling
|
public interface Inventory extends IMultiTileContainer {
|
||||||
default boolean hasItems () { return false; }
|
default boolean hasInventory() { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
// optional fluid handling
|
public interface Fluid extends IMultiTileContainer {
|
||||||
// done here rather than through the Capability to allow greater flexibility
|
// done here rather than through the Capability to allow greater flexibility
|
||||||
default boolean hasFluid () { return false; }
|
default boolean hasTank() { return false; }
|
||||||
default int getTankSize (int tank) { return 0; }
|
|
||||||
default void setTankSize (int tank, int blocks) {}
|
default int getTankSize(int tank) { return 0; }
|
||||||
default IFluidTank getTank (int tank) { return null; }
|
|
||||||
default FluidStack getFluid (int tank) { return FluidStack.EMPTY; }
|
default void setTankSize(int tank, int blocks) {}
|
||||||
|
|
||||||
|
default IFluidTank getTank(int tank) { return null; }
|
||||||
|
|
||||||
|
default FluidStack getFluid(int tank) { return FluidStack.EMPTY; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue