diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java index df9d9aa7731..9c0a078f34f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityReservoirHatch.java @@ -4,33 +4,31 @@ import gregtech.api.capability.impl.FilteredItemHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.capability.impl.NotifiableFluidTank; -import gregtech.api.gui.GuiTextures; -import gregtech.api.gui.ModularUI; -import gregtech.api.gui.widgets.*; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.mui.GTGuiTextures; import gregtech.api.mui.GTGuis; +import gregtech.api.mui.sync.GTFluidSyncHandler; +import gregtech.api.util.TextFormattingUtil; import gregtech.client.renderer.texture.Textures; +import gregtech.common.mui.widget.GTFluidSlot; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; +import net.minecraftforge.fluids.capability.IFluidHandlerItem; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.ItemStackHandler; @@ -41,12 +39,13 @@ import com.cleanroommc.modularui.factory.PosGuiData; import com.cleanroommc.modularui.screen.ModularPanel; import com.cleanroommc.modularui.value.sync.PanelSyncManager; +import com.cleanroommc.modularui.value.sync.SyncHandlers; +import com.cleanroommc.modularui.widgets.ItemSlot; import com.cleanroommc.modularui.widgets.SlotGroupWidget; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.function.Consumer; public class MetaTileEntityReservoirHatch extends MetaTileEntityMultiblockNotifiablePart implements IMultiblockAbilityPart { @@ -132,65 +131,59 @@ public boolean usesMui2() { public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) { guiSyncManager.registerSlotGroup("item_inv", 2); + GTFluidSyncHandler tankSyncHandler = new GTFluidSyncHandler(this.fluidTank) + .canDrainSlot(true).canFillSlot(false); + // TODO: Change the position of the name when it's standardized. return GTGuis.createPanel(this, 176, 166) .child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5)) - .child(IKey.lang("gregtech.gui.fluid_amount").color(0xFFFFFF).asWidget().pos(11, 20)) .child(SlotGroupWidget.playerInventory().left(7).bottom(7)) .child(GTGuiTextures.DISPLAY.asWidget() .left(7).top(16) .size(81, 55)) .child(GTGuiTextures.TANK_ICON.asWidget() - .left(91).top(36) - .size(14, 15)); - } - - @Override - protected ModularUI createUI(EntityPlayer entityPlayer) { - return createTankUI(fluidTank, getMetaFullName(), entityPlayer).build(getHolder(), entityPlayer); - } - - public ModularUI.Builder createTankUI(IFluidTank fluidTank, String title, EntityPlayer entityPlayer) { - // Create base builder/widget references - ModularUI.Builder builder = ModularUI.defaultBuilder(); - TankWidget tankWidget; - - // Add input/output-specific widgets - tankWidget = new TankWidget(fluidTank, 69, 52, 18, 18) - .setAlwaysShowFull(true).setDrawHoveringText(false).setContainerClicking(true, false); - - builder.image(7, 16, 81, 55, GuiTextures.DISPLAY) - .widget(new ImageWidget(91, 36, 14, 15, GuiTextures.TANK_ICON)) - .widget(new SlotWidget(exportItems, 0, 90, 53, true, false) - .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.OUT_SLOT_OVERLAY)); - - // Add general widgets - return builder.label(6, 6, title) - .label(11, 20, "gregtech.gui.fluid_amount", 0xFFFFFF) - .widget(new AdvancedTextWidget(11, 30, getFluidAmountText(tankWidget), 0xFFFFFF)) - .widget(new AdvancedTextWidget(11, 40, getFluidNameText(tankWidget), 0xFFFFFF)) - .widget(tankWidget) - .widget(new FluidContainerSlotWidget(importItems, 0, 90, 16, false) - .setBackgroundTexture(GuiTextures.SLOT, GuiTextures.IN_SLOT_OVERLAY)) - .bindPlayerInventory(entityPlayer.inventory); - } - - private Consumer> getFluidNameText(TankWidget tankWidget) { - return (list) -> { - TextComponentTranslation translation = tankWidget.getFluidTextComponent(); - if (translation != null) { - list.add(translation); - } - }; + .left(92).top(36) + .size(14, 15)) + .child(IKey.lang("gregtech.gui.fluid_amount").color(0xFFFFFF).asWidget().pos(11, 20)) + .child(IKey.dynamic(() -> getFluidAmountFormatted(tankSyncHandler)) + .color(0xFFFFFF) + .asWidget().pos(11, 30)) + .child(IKey.dynamic(() -> getFluidNameTranslated(tankSyncHandler)) + .color(0xFFFFFF) + .asWidget().pos(11, 40)) + // TODO: Use controlsAmount(false) in the sync handler when #2622 is done + .child(new GTFluidSlot().syncHandler(tankSyncHandler) + .pos(69, 52)) + .child(new ItemSlot().slot(SyncHandlers.itemSlot(this.importItems, 0) + .slotGroup("item_inv") + .filter(itemStack -> { + IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(itemStack); + return fluidHandlerItem != null && + fluidHandlerItem.getTankProperties()[0].getContents() != null; + })) + .background(GTGuiTextures.SLOT, GTGuiTextures.IN_SLOT_OVERLAY) + .pos(90, 16)) + .child(new ItemSlot().slot(SyncHandlers.itemSlot(this.exportItems, 0) + .slotGroup("item_inv") + .accessibility(false, true)) + .background(GTGuiTextures.SLOT, GTGuiTextures.OUT_SLOT_OVERLAY) + .pos(90, 53)); + } + + private String getFluidNameTranslated(GTFluidSyncHandler tankSyncHandler) { + if (tankSyncHandler.getFluid() == null) { + return ""; + } else { + return tankSyncHandler.getFluid().getLocalizedName(); + } } - private Consumer> getFluidAmountText(TankWidget tankWidget) { - return (list) -> { - String fluidAmount = tankWidget.getFormattedFluidAmount(); - if (!fluidAmount.isEmpty()) { - list.add(new TextComponentString(fluidAmount)); - } - }; + private String getFluidAmountFormatted(GTFluidSyncHandler tankSyncHandler) { + if (tankSyncHandler.getFluid() == null) { + return "0"; + } else { + return TextFormattingUtil.formatNumbers(tankSyncHandler.getFluid().amount); + } } @Override