mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 12:03:44 +01:00
fluid distribution and render fixes
This commit is contained in:
parent
b0950a23cb
commit
aa9c227bee
3 changed files with 68 additions and 15 deletions
|
@ -10,8 +10,10 @@ import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.Direction.Axis;
|
import net.minecraft.util.Direction.Axis;
|
||||||
import net.minecraft.util.Direction.AxisDirection;
|
import net.minecraft.util.Direction.AxisDirection;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.ILightReader;
|
import net.minecraft.world.ILightReader;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -25,17 +27,17 @@ public class FluidPipeBlock extends SixWayBlock {
|
||||||
return state.getBlock() instanceof FluidPipeBlock;
|
return state.getBlock() instanceof FluidPipeBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTank(BlockState state) {
|
public static boolean isTank(BlockState state, IBlockReader world, BlockPos pos, Direction blockFace) {
|
||||||
return state.getBlock() instanceof FluidTankBlock;
|
return state.hasTileEntity() && world.getTileEntity(pos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, blockFace.getOpposite()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: more generic pipe connection handling. Ideally without marker interface
|
// TODO: more generic pipe connection handling. Ideally without marker interface
|
||||||
public static boolean canConnectTo(ILightReader world, BlockPos pos, BlockState neighbour, Direction blockFace) {
|
public static boolean canConnectTo(ILightReader world, BlockPos pos, BlockState neighbour, Direction blockFace) {
|
||||||
if (isPipe(neighbour) || isTank(neighbour))
|
if (isPipe(neighbour) || isTank(neighbour, world, pos, blockFace))
|
||||||
return true;
|
return true;
|
||||||
return neighbour.getBlock() instanceof PumpBlock && blockFace.getAxis() == neighbour.get(PumpBlock.FACING)
|
return neighbour.getBlock() instanceof PumpBlock && blockFace.getAxis() == neighbour.get(PumpBlock.FACING)
|
||||||
.getAxis();
|
.getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldDrawRim(ILightReader world, BlockPos pos, BlockState state, Direction direction) {
|
public static boolean shouldDrawRim(ILightReader world, BlockPos pos, BlockState state, Direction direction) {
|
||||||
if (!isPipe(state))
|
if (!isPipe(state))
|
||||||
|
|
|
@ -168,7 +168,8 @@ public class FluidTankRenderer extends SafeTileEntityRenderer<FluidTankTileEntit
|
||||||
float percent = (float) tank.getFluidAmount() / (float) tank.getCapacity();
|
float percent = (float) tank.getFluidAmount() / (float) tank.getCapacity();
|
||||||
|
|
||||||
double tankHeight = tankBounds.maxY - tankBounds.minY;
|
double tankHeight = tankBounds.maxY - tankBounds.minY;
|
||||||
double y1 = tankBounds.minY, y2 = (tankBounds.minY + (tankHeight * percent));
|
double y1 = tankBounds.minY;
|
||||||
|
double y2 = tank.getFluidAmount() < tank.getCapacity() ? (3 / 16f + (10 / 16f * percent)) : tankBounds.maxY;
|
||||||
if (tank.getFluid().getFluid().getAttributes().isLighterThanAir()) {
|
if (tank.getFluid().getFluid().getAttributes().isLighterThanAir()) {
|
||||||
double yOff = tankBounds.maxY - y2; // lighter than air fluids move to the top of the tank
|
double yOff = tankBounds.maxY - y2; // lighter than air fluids move to the top of the tank
|
||||||
y1 += yOff;
|
y1 += yOff;
|
||||||
|
@ -178,9 +179,10 @@ public class FluidTankRenderer extends SafeTileEntityRenderer<FluidTankTileEntit
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<TankRenderInfo> getTanksToRender(FluidTankTileEntity te) {
|
private Collection<TankRenderInfo> getTanksToRender(FluidTankTileEntity te) {
|
||||||
boolean up = te.getBlockState().get(FluidTankBlock.TOP);
|
FluidTankTileEntity upTE = te.getOtherFluidTankTileEntity(Direction.UP);
|
||||||
boolean down = te.getBlockState().get(FluidTankBlock.BOTTOM);
|
FluidTankTileEntity downTE = te.getOtherFluidTankTileEntity(Direction.DOWN);
|
||||||
// bounds.shrink(16f);
|
boolean up = upTE == null || upTE.getTank().getFluidAmount() == 0 || te.getTank().getFluid() != upTE.getTank().getFluid();
|
||||||
|
boolean down = downTE == null || downTE.getTank().getFluidAmount() == downTE.getTank().getCapacity() || te.getTank().getFluid() != downTE.getTank().getFluid();
|
||||||
return Collections.singletonList(new FluidTankRenderInfo(te.getTank(), up, down, ((FluidTankBlock) te.getBlockState().getBlock()).getTankBodyShape(te.getWorld(), te.getPos())));
|
return Collections.singletonList(new FluidTankRenderInfo(te.getTank(), up, down, ((FluidTankBlock) te.getBlockState().getBlock()).getTankBodyShape(te.getWorld(), te.getPos())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
package com.simibubi.create.content.contraptions.fluids;
|
package com.simibubi.create.content.contraptions.fluids;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
||||||
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.tileentity.TileEntityType;
|
import net.minecraft.tileentity.TileEntityType;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.fluids.IFluidTank;
|
import net.minecraftforge.fluids.IFluidTank;
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
|
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
|
||||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class FluidTankTileEntity extends SmartTileEntity {
|
public class FluidTankTileEntity extends SmartTileEntity {
|
||||||
|
|
||||||
LazyOptional<FluidTank> fluid = LazyOptional.of(this::createFluidHandler);
|
LazyOptional<FluidTank> fluid = LazyOptional.of(this::createFluidHandler);
|
||||||
|
@ -23,6 +27,51 @@ public class FluidTankTileEntity extends SmartTileEntity {
|
||||||
super(tileEntityTypeIn);
|
super(tileEntityTypeIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
|
||||||
|
|
||||||
|
FluidTankTileEntity other;
|
||||||
|
|
||||||
|
other = getOtherFluidTankTileEntity(Direction.NORTH);
|
||||||
|
if (other != null && other.getTank().isFluidValid(this.getTank().getFluid())) {
|
||||||
|
int delta = other.getTank().getFluidAmount() - this.getTank().getFluidAmount();
|
||||||
|
if (delta > 0) {
|
||||||
|
this.getTank().fill(other.getTank().drain(delta / 2, FluidAction.EXECUTE), FluidAction.EXECUTE);
|
||||||
|
} else if (delta < 0) {
|
||||||
|
other.getTank().fill(this.getTank().drain(-delta / 2, FluidAction.EXECUTE), FluidAction.EXECUTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
other = getOtherFluidTankTileEntity(Direction.WEST);
|
||||||
|
if (other != null && other.getTank().isFluidValid(this.getTank().getFluid())) {
|
||||||
|
int delta = other.getTank().getFluidAmount() - this.getTank().getFluidAmount();
|
||||||
|
if (delta > 0) {
|
||||||
|
this.getTank().fill(other.getTank().drain(delta / 2, FluidAction.EXECUTE), FluidAction.EXECUTE);
|
||||||
|
} else if (delta < 0) {
|
||||||
|
other.getTank().fill(this.getTank().drain(-delta / 2, FluidAction.EXECUTE), FluidAction.EXECUTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
other = getOtherFluidTankTileEntity(Direction.UP);
|
||||||
|
if (other != null && other.getTank().isFluidValid(this.getTank().getFluid())) {
|
||||||
|
int space = this.getTank().getCapacity() - this.getTank().getFluidAmount();
|
||||||
|
if (space > 0 && other.getTank().getFluidAmount() > 0) {
|
||||||
|
this.getTank().fill(other.getTank().drain(space, FluidAction.EXECUTE), FluidAction.EXECUTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FluidTankTileEntity getOtherFluidTankTileEntity(Direction direction) {
|
||||||
|
TileEntity otherTE = world.getTileEntity(pos.offset(direction));
|
||||||
|
if (otherTE instanceof FluidTankTileEntity)
|
||||||
|
return (FluidTankTileEntity) otherTE;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
|
||||||
|
@ -50,7 +99,7 @@ public class FluidTankTileEntity extends SmartTileEntity {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public FluidTank createFluidHandler() {
|
public FluidTank createFluidHandler() {
|
||||||
return new FluidTank(16);
|
return new FluidTank(16000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFluidTank getTank() {
|
public IFluidTank getTank() {
|
||||||
|
|
Loading…
Reference in a new issue