Search in sources :

Example 1 with InterpolatedChasingValue

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();
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 2 with InterpolatedChasingValue

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);
}
Also used : InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) BlockPos(net.minecraft.core.BlockPos)

Example 3 with InterpolatedChasingValue

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());
    }
}
Also used : InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) BlockPos(net.minecraft.core.BlockPos)

Example 4 with InterpolatedChasingValue

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();
}
Also used : InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) BlockState(net.minecraft.world.level.block.state.BlockState) Shape(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock.Shape) BeltFunnelBlock(com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 5 with InterpolatedChasingValue

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));
}
Also used : InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) Tag(net.minecraft.nbt.Tag) IntTag(net.minecraft.nbt.IntTag) CompoundTag(net.minecraft.nbt.CompoundTag) ListTag(net.minecraft.nbt.ListTag) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) ListTag(net.minecraft.nbt.ListTag) IntTag(net.minecraft.nbt.IntTag) HashSet(java.util.HashSet)

Aggregations

InterpolatedChasingValue (com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue)6 BlockPos (net.minecraft.core.BlockPos)2 Direction (net.minecraft.core.Direction)2 AxisDirection (net.minecraft.core.Direction.AxisDirection)2 CreativeFluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity)1 CreativeSmartFluidTank (com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank)1 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)1 Shape (com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock.Shape)1 BeltFunnelBlock (com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock)1 SmartFluidTank (com.simibubi.create.foundation.fluid.SmartFluidTank)1 HashSet (java.util.HashSet)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 IntTag (net.minecraft.nbt.IntTag)1 ListTag (net.minecraft.nbt.ListTag)1 Tag (net.minecraft.nbt.Tag)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 FluidAttributes (net.minecraftforge.fluids.FluidAttributes)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 IFluidTank (net.minecraftforge.fluids.IFluidTank)1 FluidTank (net.minecraftforge.fluids.capability.templates.FluidTank)1