use of com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue in project Create by Creators-of-Create.
the class FluidTankRenderer method renderSafe.
@Override
protected void renderSafe(FluidTankTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
if (!te.isController())
return;
if (!te.window)
return;
InterpolatedChasingValue fluidLevel = te.getFluidLevel();
if (fluidLevel == null)
return;
float capHeight = 1 / 4f;
float tankHullWidth = 1 / 16f + 1 / 128f;
float minPuddleHeight = 1 / 16f;
float totalHeight = te.height - 2 * capHeight - minPuddleHeight;
float level = fluidLevel.get(partialTicks);
if (level < 1 / (512f * totalHeight))
return;
float clampedLevel = Mth.clamp(level * totalHeight, 0, totalHeight);
FluidTank tank = te.tankInventory;
FluidStack fluidStack = tank.getFluid();
if (fluidStack.isEmpty())
return;
boolean top = fluidStack.getFluid().getAttributes().isLighterThanAir();
float xMin = tankHullWidth;
float xMax = xMin + te.width - 2 * tankHullWidth;
float yMin = totalHeight + capHeight + minPuddleHeight - clampedLevel;
float yMax = yMin + clampedLevel;
if (top) {
yMin += totalHeight - clampedLevel;
yMax += totalHeight - clampedLevel;
}
float zMin = tankHullWidth;
float zMax = zMin + te.width - 2 * tankHullWidth;
ms.pushPose();
ms.translate(0, clampedLevel - totalHeight, 0);
FluidRenderer.renderFluidBox(fluidStack, xMin, yMin, zMin, xMax, yMax, zMax, buffer, ms, light, false);
ms.popPose();
}
use of com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue in project Create by Creators-of-Create.
the class FluidTankTileEntity method read.
@Override
protected void read(CompoundTag compound, boolean clientPacket) {
super.read(compound, clientPacket);
BlockPos controllerBefore = controller;
int prevSize = width;
int prevHeight = height;
int prevLum = luminosity;
updateConnectivity = compound.contains("Uninitialized");
luminosity = compound.getInt("Luminosity");
controller = null;
lastKnownPos = null;
if (compound.contains("LastKnownPos"))
lastKnownPos = NbtUtils.readBlockPos(compound.getCompound("LastKnownPos"));
if (compound.contains("Controller"))
controller = NbtUtils.readBlockPos(compound.getCompound("Controller"));
if (isController()) {
window = compound.getBoolean("Window");
width = compound.getInt("Size");
height = compound.getInt("Height");
tankInventory.setCapacity(getTotalTankSize() * getCapacityMultiplier());
tankInventory.readFromNBT(compound.getCompound("TankContent"));
if (tankInventory.getSpace() < 0)
tankInventory.drain(-tankInventory.getSpace(), FluidAction.EXECUTE);
}
if (compound.contains("ForceFluidLevel") || fluidLevel == null)
fluidLevel = new InterpolatedChasingValue().start(getFillState()).withSpeed(1 / 2f);
if (!clientPacket)
return;
boolean changeOfController = controllerBefore == null ? controller != null : !controllerBefore.equals(controller);
if (changeOfController || prevSize != width || prevHeight != height) {
if (hasLevel())
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), 16);
if (isController())
tankInventory.setCapacity(getCapacityMultiplier() * getTotalTankSize());
invalidateRenderBoundingBox();
}
if (isController()) {
float fillState = getFillState();
if (compound.contains("ForceFluidLevel") || fluidLevel == null)
fluidLevel = new InterpolatedChasingValue().start(fillState);
fluidLevel.target(fillState);
}
if (luminosity != prevLum && hasLevel())
level.getChunkSource().getLightEngine().checkBlock(worldPosition);
if (compound.contains("LazySync"))
fluidLevel.withSpeed(compound.contains("LazySync") ? 1 / 8f : 1 / 2f);
}
use of com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue in project Create by Creators-of-Create.
the class FluidTankTileEntity method onFluidStackChanged.
protected void onFluidStackChanged(FluidStack newFluidStack) {
if (!hasLevel())
return;
FluidAttributes attributes = newFluidStack.getFluid().getAttributes();
int luminosity = (int) (attributes.getLuminosity(newFluidStack) / 1.2f);
boolean reversed = attributes.isLighterThanAir();
int maxY = (int) ((getFillState() * height) + 1);
for (int yOffset = 0; yOffset < height; yOffset++) {
boolean isBright = reversed ? (height - yOffset <= maxY) : (yOffset < maxY);
int actualLuminosity = isBright ? luminosity : luminosity > 0 ? 1 : 0;
for (int xOffset = 0; xOffset < width; xOffset++) {
for (int zOffset = 0; zOffset < width; zOffset++) {
BlockPos pos = this.worldPosition.offset(xOffset, yOffset, zOffset);
FluidTankTileEntity tankAt = FluidTankConnectivityHandler.anyTankAt(level, pos);
if (tankAt == null)
continue;
level.updateNeighbourForOutputSignal(pos, tankAt.getBlockState().getBlock());
if (tankAt.luminosity == actualLuminosity)
continue;
tankAt.setLuminosity(actualLuminosity);
}
}
}
if (!level.isClientSide) {
setChanged();
sendData();
}
if (isVirtual()) {
if (fluidLevel == null)
fluidLevel = new InterpolatedChasingValue().start(getFillState());
fluidLevel.target(getFillState());
}
}
use of com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue in project Create by Creators-of-Create.
the class BeltTunnelTileEntity method updateTunnelConnections.
public void updateTunnelConnections() {
flaps.clear();
sides.clear();
BlockState tunnelState = getBlockState();
for (Direction direction : Iterate.horizontalDirections) {
if (direction.getAxis() != tunnelState.getValue(BlockStateProperties.HORIZONTAL_AXIS)) {
boolean positive = direction.getAxisDirection() == AxisDirection.POSITIVE ^ direction.getAxis() == Axis.Z;
Shape shape = tunnelState.getValue(BeltTunnelBlock.SHAPE);
if (BeltTunnelBlock.isStraight(tunnelState))
continue;
if (positive && shape == Shape.T_LEFT)
continue;
if (!positive && shape == Shape.T_RIGHT)
continue;
}
sides.add(direction);
// Flap might be occluded
BlockState nextState = level.getBlockState(worldPosition.relative(direction));
if (nextState.getBlock() instanceof BeltTunnelBlock)
continue;
if (nextState.getBlock() instanceof BeltFunnelBlock)
if (nextState.getValue(BeltFunnelBlock.SHAPE) == BeltFunnelBlock.Shape.EXTENDED && nextState.getValue(BeltFunnelBlock.HORIZONTAL_FACING) == direction.getOpposite())
continue;
flaps.put(direction, new InterpolatedChasingValue().start(.25f).target(0).withSpeed(.05f));
}
sendData();
}
use of com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue in project Create by Creators-of-Create.
the class BeltTunnelTileEntity method read.
@Override
protected void read(CompoundTag compound, boolean clientPacket) {
Set<Direction> newFlaps = new HashSet<>(6);
ListTag flapsNBT = compound.getList("Flaps", Tag.TAG_INT);
for (Tag inbt : flapsNBT) if (inbt instanceof IntTag)
newFlaps.add(Direction.from3DDataValue(((IntTag) inbt).getAsInt()));
sides.clear();
ListTag sidesNBT = compound.getList("Sides", Tag.TAG_INT);
for (Tag inbt : sidesNBT) if (inbt instanceof IntTag)
sides.add(Direction.from3DDataValue(((IntTag) inbt).getAsInt()));
for (Direction d : Iterate.directions) if (!newFlaps.contains(d))
flaps.remove(d);
else if (!flaps.containsKey(d))
flaps.put(d, new InterpolatedChasingValue().start(.25f).target(0).withSpeed(.05f));
// Backwards compat
if (!compound.contains("Sides") && compound.contains("Flaps"))
sides.addAll(flaps.keySet());
super.read(compound, clientPacket);
if (clientPacket)
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> InstancedRenderDispatcher.enqueueUpdate(this));
}
Aggregations