Skip to content

Commit

Permalink
Migrate to FluidSlotWidget from FluidDisplaySlotWidget (#1963)
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune authored May 8, 2023
1 parent 312812a commit 4f5d969
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 649 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {

api("com.github.GTNewHorizons:NotEnoughItems:2.3.46-GTNH:dev")
api("com.github.GTNewHorizons:GTNHLib:0.0.13:dev")
api("com.github.GTNewHorizons:ModularUI:1.1.2:dev")
api("com.github.GTNewHorizons:ModularUI:1.1.7:dev")
api("com.github.GTNewHorizons:waila:1.5.24:dev")
api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-197-GTNH:dev")
implementation("com.github.GTNewHorizons:Eternal-Singularity:1.1.0:dev")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/GT_Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
guiFactory = "gregtech.client.GT_GuiFactory",
dependencies = " required-after:IC2;" + " required-after:structurelib;"
+ " required-after:gtnhlib@[0.0.8,);"
+ " required-after:modularui;"
+ " required-after:modularui@[1.1.7,);"
+ " after:dreamcraft;"
+ " after:Forestry;"
+ " after:PFAAGeologica;"
Expand Down
1 change: 0 additions & 1 deletion src/main/java/gregtech/api/enums/GT_Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ public static final class NBT {
public static final Set<String> mCTMEnabledBlock = new HashSet<>();
public static final Set<String> mCTMDisabledBlock = new HashSet<>();

public static boolean updateFluidDisplayItems = true;
public static final int STEAM_PER_WATER = 160;
/**
* If true, then digital chest with AE2 storage bus will be accessible only through AE2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.api.interfaces;

@Deprecated
public interface IHasFluidDisplayItem {

void updateFluidDisplayItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ public interface IFluidLockable {

boolean isFluidLocked();

boolean allowChangingLockedFluid(String name);

default void onFluidLockPacketReceived(String name) {}
boolean acceptsFluidLock(String name);
}
2 changes: 0 additions & 2 deletions src/main/java/gregtech/api/metatileentity/BaseTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,6 @@ public ItemStackHandler getInventoryHandler() {
BATTERY_SLOT_TOOLTIP_ALT = "GT5U.machines.battery_slot.tooltip.alternative",
UNUSED_SLOT_TOOLTIP = "GT5U.machines.unused_slot.tooltip",
SPECIAL_SLOT_TOOLTIP = "GT5U.machines.special_slot.tooltip",
FLUID_INPUT_TOOLTIP = "GT5U.machines.fluid_input_slot.tooltip",
FLUID_OUTPUT_TOOLTIP = "GT5U.machines.fluid_output_slot.tooltip",
STALLED_STUTTERING_TOOLTIP = "GT5U.machines.stalled_stuttering.tooltip",
STALLED_VENT_TOOLTIP = "GT5U.machines.stalled_vent.tooltip",
FLUID_TRANSFER_TOOLTIP = "GT5U.machines.fluid_transfer.tooltip",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import appeng.api.crafting.ICraftingIconProvider;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.ItemList;
import gregtech.api.gui.modularui.GUITextureSet;
import gregtech.api.interfaces.IConfigurationCircuitSupport;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
Expand Down Expand Up @@ -83,7 +84,12 @@ protected void loadMetaTileNBT(NBTTagCompound aNBT) {
final NBTTagCompound tTag = tItemList.getCompoundTagAt(i);
final int tSlot = migrateInventoryIndex(tTag.getInteger("IntSlot"), nbtVersion);
if (tSlot >= 0 && tSlot < getMetaTileEntity().getRealInventory().length) {
getMetaTileEntity().getRealInventory()[tSlot] = GT_Utility.loadItem(tTag);
ItemStack loadedStack = GT_Utility.loadItem(tTag);
// We move away from fluid display item in TEs
if (loadedStack != null && loadedStack.getItem() == ItemList.Display_Fluid.getItem()) {
loadedStack = null;
}
getMetaTileEntity().getRealInventory()[tSlot] = loadedStack;
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,14 @@ public int getCapacity() {
return 0;
}

/**
* Actual fluid capacity. If your machine has void-overflow feature, you'll want to override this method to make
* sure correct capacity is shown on GUI.
*/
public int getRealCapacity() {
return getCapacity();
}

@Override
public void onMachineBlockUpdate() {
/* Do nothing */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import static gregtech.api.enums.GT_Values.debugCleanroom;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT;
import static gregtech.api.metatileentity.BaseTileEntity.FLUID_INPUT_TOOLTIP;
import static gregtech.api.metatileentity.BaseTileEntity.FLUID_OUTPUT_TOOLTIP;
import static gregtech.api.metatileentity.BaseTileEntity.FLUID_TRANSFER_TOOLTIP;
import static gregtech.api.metatileentity.BaseTileEntity.ITEM_TRANSFER_TOOLTIP;
import static gregtech.api.metatileentity.BaseTileEntity.NEI_TRANSFER_STEAM_TOOLTIP;
Expand Down Expand Up @@ -48,16 +46,16 @@
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.api.widget.Widget;
import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils;
import com.gtnewhorizons.modularui.common.fluid.FluidStackTank;
import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget;
import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget;
import com.gtnewhorizons.modularui.common.widget.ProgressBar;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;

import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.SoundResource;
import gregtech.api.gui.GT_Container_BasicMachine;
import gregtech.api.gui.GT_GUIContainer_BasicMachine;
Expand All @@ -81,7 +79,6 @@
import gregtech.api.util.GT_Utility;
import gregtech.api.util.GT_Waila;
import gregtech.common.gui.modularui.UIHelper;
import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget;
import gregtech.common.power.BasicMachineEUPower;
import gregtech.common.power.Power;
import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_Cleanroom;
Expand Down Expand Up @@ -123,6 +120,10 @@ public abstract class GT_MetaTileEntity_BasicMachine extends GT_MetaTileEntity_B
protected GT_Recipe mLastRecipe = null;

private FluidStack mFluidOut;
protected final FluidStackTank fluidOutputTank = new FluidStackTank(
() -> mFluidOut,
fluidStack -> mFluidOut = fluidStack,
this::getCapacity);

/**
* @param aOverlays 0 = SideFacingActive 1 = SideFacingInactive 2 = FrontFacingActive 3 = FrontFacingInactive 4 =
Expand Down Expand Up @@ -481,11 +482,6 @@ public boolean displaysStackSize() {
return true;
}

@Override
public FluidStack getDisplayedFluid() {
return displaysOutputFluid() ? getDrainableStack() : null;
}

@Override
public FluidStack getDrainableStack() {
return mFluidOut;
Expand Down Expand Up @@ -756,29 +752,6 @@ protected void doDisplayThings() {
}
}

@Override
public void updateFluidDisplayItem() {
updateFluidOutputDisplayItem();
updateFluidInputDisplayItem();
}

public void updateFluidOutputDisplayItem() {
super.updateFluidDisplayItem();
}

public void updateFluidInputDisplayItem() {
if (displaysInputFluid()) {
int tDisplayStackSlot = OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length;
if (getFillableStack() == null) {
if (ItemList.Display_Fluid.isStackEqual(mInventory[tDisplayStackSlot], true, true))
mInventory[tDisplayStackSlot] = null;
} else {
mInventory[tDisplayStackSlot] = GT_Utility
.getFluidDisplayStack(getFillableStack(), true, !displaysStackSize());
}
}
}

protected boolean hasEnoughEnergyToCheckRecipe() {
return getBaseMetaTileEntity().isUniversalEnergyStored(getMinimumStoredEU() / 2);
}
Expand Down Expand Up @@ -863,14 +836,6 @@ protected boolean isOutputEmpty() {
return rIsEmpty;
}

protected boolean displaysInputFluid() {
return true;
}

protected boolean displaysOutputFluid() {
return true;
}

@Override
public void onValueUpdate(byte aValue) {
mMainFacing = ForgeDirection.getOrientation(aValue);
Expand Down Expand Up @@ -1440,38 +1405,13 @@ protected SlotWidget createSpecialSlot(IDrawable[] backgrounds, Pos2d pos) {
.setPos(pos);
}

protected FluidDisplaySlotWidget createFluidInputSlot(IDrawable[] backgrounds, Pos2d pos) {
return (FluidDisplaySlotWidget) new FluidDisplaySlotWidget(
inventoryHandler,
OTHER_SLOT_COUNT + mInputSlotCount + mOutputItems.length)
.setFluidAccessConstructor(() -> constructFluidAccess(true))
.setIHasFluidDisplay(this)
.setCanDrain(true)
.setCanFill(true)
.setActionRealClick(FluidDisplaySlotWidget.Action.TRANSFER)
.setBeforeRealClick((clickData, widget) -> {
if (NetworkUtils.isClient()) {
// propagate display item content to
// actual fluid stored in this tank
setFillableStack(
GT_Utility.getFluidFromDisplayStack(
widget.getMcSlot()
.getStack()));
}
return true;
})
.setUpdateFluidDisplayItem(this::updateFluidInputDisplayItem)
.setGTTooltip(() -> mTooltipCache.getData(FLUID_INPUT_TOOLTIP, GT_Utility.formatNumbers(getCapacity())))
.setTooltipShowUpDelay(TOOLTIP_DELAY)
.setBackground(backgrounds)
.setPos(pos);
}

protected FluidDisplaySlotWidget createFluidOutputSlot(IDrawable[] backgrounds, Pos2d pos) {
return (FluidDisplaySlotWidget) createDrainableFluidSlot()
.setUpdateFluidDisplayItem(this::updateFluidOutputDisplayItem)
.setGTTooltip(() -> mTooltipCache.getData(FLUID_OUTPUT_TOOLTIP, GT_Utility.formatNumbers(getCapacity())))
.setTooltipShowUpDelay(TOOLTIP_DELAY)
protected FluidSlotWidget createFluidInputSlot(IDrawable[] backgrounds, Pos2d pos) {
return (FluidSlotWidget) new FluidSlotWidget(fluidTank).setBackground(backgrounds)
.setPos(pos);
}

protected FluidSlotWidget createFluidOutputSlot(IDrawable[] backgrounds, Pos2d pos) {
return (FluidSlotWidget) new FluidSlotWidget(fluidOutputTank).setInteraction(true, false)
.setBackground(backgrounds)
.setPos(pos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.gtnewhorizons.modularui.api.math.Pos2d;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget;

import gregtech.api.GregTech_API;
import gregtech.api.enums.Dyes;
Expand All @@ -28,7 +29,6 @@
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder;
import gregtech.common.gui.modularui.widget.FluidDisplaySlotWidget;
import gregtech.common.power.Power;
import gregtech.common.power.SteamPower;

Expand Down Expand Up @@ -370,12 +370,12 @@ public void addGregTechLogo(ModularWindow.Builder builder) {
}

@Override
protected FluidDisplaySlotWidget createFluidInputSlot(IDrawable[] backgrounds, Pos2d pos) {
protected FluidSlotWidget createFluidInputSlot(IDrawable[] backgrounds, Pos2d pos) {
return null;
}

@Override
protected FluidDisplaySlotWidget createFluidOutputSlot(IDrawable[] backgrounds, Pos2d pos) {
protected FluidSlotWidget createFluidOutputSlot(IDrawable[] backgrounds, Pos2d pos) {
return null;
}
}
Loading

0 comments on commit 4f5d969

Please sign in to comment.