RyanHub – file viewer
filename: common/src/main/java/rearth/oritech/client/ui/CentrifugeScreenHandler.java
branch: 1.21
back to repo
package rearth.oritech.client.ui;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.PacketByteBuf;
import rearth.oritech.Oritech;
import rearth.oritech.api.fluid.FluidApi;
import rearth.oritech.block.entity.processing.CentrifugeBlockEntity;
import rearth.oritech.client.init.ModScreens;
import rearth.oritech.util.MachineAddonController;

import java.util.Objects;

public class CentrifugeScreenHandler extends UpgradableMachineScreenHandler {
    
    public final FluidApi.SingleSlotStorage inputTank;
    
    public CentrifugeScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) {
        this(syncId, inventory, ModScreens.UpgradableData.PACKET_CODEC.decode(buf));
    }
    
    public CentrifugeScreenHandler(int syncId, PlayerInventory inventory, ModScreens.UpgradableData data) {
        this(syncId, inventory, Objects.requireNonNull(inventory.player.getWorld().getBlockEntity(data.pos())), data.addonUiData(), data.coreQuality());
    }
    
    public CentrifugeScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity, MachineAddonController.AddonUiData addonUiData, float coreQuality) {
        super(syncId, playerInventory, blockEntity, addonUiData, coreQuality);
        
        if (!(blockEntity instanceof CentrifugeBlockEntity centrifugeEntity)) {
            inputTank = null;
            Oritech.LOGGER.error("Opened centrifuge screen on non-centrifuge block, this should never happen");
            return;
        }
        
        if (centrifugeEntity.hasFluidAddon) {
            inputTank = centrifugeEntity.fluidContainer.getInputContainer();
            this.mainFluidContainer = centrifugeEntity.fluidContainer.getOutputContainer();
        } else {
            inputTank = null;
        }
    }
}