diff options
author | Yannick Marcotte-Gourde <yannickmg@gmail.com> | 2024-08-14 00:34:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 06:34:38 +0200 |
commit | d167ee2f8a4ff9d73cbc56f0fb6338fb1fc236f9 (patch) | |
tree | 3ef2a0979eff8fca8a118f49063de6fd615009bb /src/main/java/gregtech/common | |
parent | 1bb8b83e53c1d4242d2791bf75597deb02404e8c (diff) | |
download | GT5-Unofficial-d167ee2f8a4ff9d73cbc56f0fb6338fb1fc236f9.tar.gz GT5-Unofficial-d167ee2f8a4ff9d73cbc56f0fb6338fb1fc236f9.tar.bz2 GT5-Unofficial-d167ee2f8a4ff9d73cbc56f0fb6338fb1fc236f9.zip |
Single-block Steam Boiler item handling improvements (#2871)
* Refactored GT_MetaTileEntity_Boiler_Bronze::updateFuel
* Refactored GT_MetaTileEntity_Boiler_Lava::addUIWidgets
* GT_MetaTileEntity_Boiler: Set item filter on fluid & fuel slots
* GT_MetaTileEntity_Boiler: Made automation handling more consistent and respect slot filters
* Remove deprecated fuel & ash slots from solar boilers
* Removed overrides identical to super
* Streamline coal boiler combustion logic
Diffstat (limited to 'src/main/java/gregtech/common')
4 files changed, 113 insertions, 208 deletions
diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java index 6b245a9da1..a40a65f0b4 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler.java @@ -10,10 +10,13 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; +import org.jetbrains.annotations.NotNull; + import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.UITexture; 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.widget.DrawableWidget; import com.gtnewhorizons.modularui.common.widget.ProgressBar; import com.gtnewhorizons.modularui.common.widget.SlotWidget; @@ -348,16 +351,21 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa } } + protected boolean isAutomatable() { + return GT_Mod.gregtechproxy.mAllowSmallBoilerAutomation; + } + @Override public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, ItemStack aStack) { - return GT_Mod.gregtechproxy.mAllowSmallBoilerAutomation; + return isAutomatable() && aIndex == 1 || aIndex == 3; } @Override public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, ItemStack aStack) { - return GT_Mod.gregtechproxy.mAllowSmallBoilerAutomation; + return isAutomatable() && (aIndex == 0 && isItemValidFluidFilledItem(aStack)) + || (aIndex == 2 && isItemValidFuel(aStack)); } @Override @@ -432,10 +440,12 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa @Override public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { builder.widget( - new SlotWidget(inventoryHandler, 0).setPos(43, 25) + new SlotWidget(inventoryHandler, 0).setFilter(this::isItemValidFluidFilledItem) + .setPos(43, 25) .setBackground(getGUITextureSet().getItemSlot(), getOverlaySlotIn())) .widget( - new SlotWidget(inventoryHandler, 1).setPos(43, 61) + new SlotWidget(inventoryHandler, 1).setAccess(true, false) + .setPos(43, 61) .setBackground(getGUITextureSet().getItemSlot(), getOverlaySlotOut())) .widget(createFuelSlot()) .widget(createAshSlot()) @@ -471,11 +481,20 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa .setSize(18, 18)); } - protected SlotWidget createFuelSlot() { - return (SlotWidget) new SlotWidget(inventoryHandler, 2).setPos(115, 61) + private boolean isItemValidFluidFilledItem(@NotNull ItemStack stack) { + return isFluidInputAllowed(GT_Utility.getFluidForFilledItem(stack, true)); + } + + protected Widget createFuelSlot() { + return new SlotWidget(inventoryHandler, 2).setFilter(this::isItemValidFuel) + .setPos(115, 61) .setBackground(getFuelSlotBackground()); } + protected boolean isItemValidFuel(@NotNull ItemStack stack) { + return true; + } + protected SlotWidget createAshSlot() { return (SlotWidget) new SlotWidget(inventoryHandler, 3).setAccess(true, false) .setPos(115, 25) diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java index 9e746dc5e9..3450d55290 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Bronze.java @@ -10,9 +10,17 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_BRONZEBRICKS_TOP; import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE; import static gregtech.api.objects.XSTR.XSTR_INSTANCE; +import java.util.Optional; +import java.util.stream.Stream; + import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidContainerRegistry; + +import org.jetbrains.annotations.NotNull; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -20,7 +28,6 @@ import gregtech.GT_Mod; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.ParticleFX; -import gregtech.api.enums.SteamVariant; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -81,11 +88,6 @@ public class GT_MetaTileEntity_Boiler_Bronze extends GT_MetaTileEntity_Boiler { } @Override - public int maxProgresstime() { - return 500; - } - - @Override public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_Boiler_Bronze(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); } @@ -179,133 +181,80 @@ public class GT_MetaTileEntity_Boiler_Bronze extends GT_MetaTileEntity_Boiler { @Override protected void updateFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (this.mInventory[2] == null) return; - if ((GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Coal) - && !GT_Utility.isPartOfOrePrefix(this.mInventory[2], OrePrefixes.block)) - || (GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Charcoal) - && !GT_Utility.isPartOfOrePrefix(this.mInventory[2], OrePrefixes.block)) - || (GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Lignite) - && !GT_Utility.isPartOfOrePrefix(this.mInventory[2], OrePrefixes.block)) - || (GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Diamond) - && !GT_Utility.isPartOfOrePrefix(this.mInventory[2], OrePrefixes.block)) - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelCoke") - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelCactusCharcoal") - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelCactusCoke") - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelSugarCharcoal") - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], "fuelSugarCoke")) { - if ((TileEntityFurnace.getItemBurnTime(this.mInventory[2]) / 10) > 0) { - this.mProcessingEnergy += (TileEntityFurnace.getItemBurnTime(this.mInventory[2]) / 10); - if (XSTR.XSTR_INSTANCE.nextInt( - GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Coal) - || GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Charcoal) ? 3 - : GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Lignite) ? 8 : 2) - == 0) { - aBaseMetaTileEntity.addStackToSlot( - 3, - GT_OreDictUnificator.get( - OrePrefixes.dustTiny, - (GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Lignite) - || GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Coal)) ? Materials.DarkAsh - : Materials.Ash, - 1L)); - } - aBaseMetaTileEntity.decrStackSize(2, 1); + ItemStack fuel = mInventory[2]; + int burnTime = TileEntityFurnace.getItemBurnTime(fuel); + getCombustionPotential(fuel, burnTime).ifPresent(ashMaterial -> { + aBaseMetaTileEntity.decrStackSize(2, 1); + this.mProcessingEnergy += burnTime / 10; + boolean isABlock = !Block.getBlockFromItem(fuel.getItem()) + .equals(Blocks.air); + combustFuel(burnTime, isABlock).map(dustSize -> GT_OreDictUnificator.get(dustSize, ashMaterial, 1L)) + .ifPresent(ashes -> aBaseMetaTileEntity.addStackToSlot(3, ashes)); + }); + } + + private static Optional<Materials> getCombustionPotential(ItemStack fuel, int burnTime) { + if (burnTime / 10 <= 0 || FluidContainerRegistry.isFilledContainer(fuel)) { + return Optional.empty(); + } + String lowerCaseBlockName = Block.getBlockFromItem(fuel.getItem()) + .getUnlocalizedName() + .toLowerCase(); + if (couldProduceDarkAshes(fuel, lowerCaseBlockName)) { + return Optional.of(Materials.DarkAsh); + } + if (couldProduceRegularAshes(fuel, lowerCaseBlockName, burnTime)) { + return Optional.of(Materials.Ash); + } + return Optional.empty(); + } + + private static boolean couldProduceDarkAshes(ItemStack fuel, String lowerCaseBlockName) { + return GT_Utility.isPartOfMaterials(fuel, Materials.Coal) + || GT_Utility.isPartOfMaterials(fuel, Materials.Lignite) + || lowerCaseBlockName.matches("tile\\..+compressedcoal"); + } + + private static boolean couldProduceRegularAshes(ItemStack fuel, String lowerCaseBlockName, int burnTime) { + return GT_Utility.isPartOfMaterials(fuel, Materials.Charcoal) + || GT_Utility.isPartOfMaterials(fuel, Materials.Diamond) + || (Stream.of("^tile\\..+charcoal", "^tile\\..+coke", "^tile\\..+railcraft.cube") + .anyMatch(lowerCaseBlockName::matches)) + || Stream.of("fuelCoke", "fuelCactusCharcoal", "fuelCactusCoke", "fuelSugarCharcoal", "fuelSugarCoke") + .anyMatch(name -> GT_OreDictUnificator.isItemStackInstanceOf(fuel, name)) + || burnTime >= 2000; + } + + private static Optional<OrePrefixes> combustFuel(int burnTime, boolean isABlock) { + if (isABlock) { + return Optional.of(OrePrefixes.dust); + } else if (XSTR.XSTR_INSTANCE.nextInt(getAshChanceBound(burnTime)) == 0) { + if (burnTime > 100000) { + return Optional.of(OrePrefixes.dust); + } else if (burnTime > 10000) { + return Optional.of(OrePrefixes.dustSmall); + } else { + return Optional.of(OrePrefixes.dustTiny); } - } else if ( - // If its a block of the following materials - GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.block.get(Materials.Coal)) - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.block.get(Materials.Lignite)) - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.block.get(Materials.Charcoal)) - || GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.block.get(Materials.Diamond)) - || - - // if its either a Railcraft Coke Block or a custom GTNH compressed Coal/charcoal/lignite/coke block - (Block.getBlockFromItem(this.mInventory[2].getItem()) != null && // check if the block exists - (Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("tile") && // check if the block is a tile -> block - ( - // If the name of the block contains these names - Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("charcoal") - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("coal") - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("diamond") - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("coke") - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("railcraft.cube") - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("lignite"))))) { - // try to add 10% of the burnvalue as Processing energy, no boost - // for coal coke here - if ((TileEntityFurnace.getItemBurnTime(this.mInventory[2]) / 10) > 0) { - this.mProcessingEnergy += (TileEntityFurnace.getItemBurnTime(this.mInventory[2]) - / 10); - aBaseMetaTileEntity.addStackToSlot( - 3, - GT_OreDictUnificator.get( - OrePrefixes.dust, - (GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Lignite) - || GT_Utility.isPartOfMaterials(this.mInventory[2], Materials.Coal) - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("coal") - || Block.getBlockFromItem(this.mInventory[2].getItem()) - .getUnlocalizedName() - .toLowerCase() - .contains("lignite")) ? Materials.DarkAsh : Materials.Ash, - 1L)); - aBaseMetaTileEntity.decrStackSize(2, 1); - } - // enables every other fuel with at least 2000 burntime as a fuel, - // i.e. peat, Magic/Solid Super Fuel, Coal - // Singularities, Nitor, while bucket of creosite should be blocked - // same goes for lava - } else - if ((TileEntityFurnace.getItemBurnTime(this.mInventory[2])) >= 2000 - && !(this.mInventory[2].getUnlocalizedName() - .toLowerCase() - .contains("bucket") - || this.mInventory[2].getUnlocalizedName() - .toLowerCase() - .contains("cell"))) { - this.mProcessingEnergy += (TileEntityFurnace.getItemBurnTime(this.mInventory[2]) / 10); - // adds tiny pile of ash for burntime under 10k, small pile for - // under 100k and pile for - // bigger values - if (XSTR.XSTR_INSTANCE.nextInt(2) == 0) - aBaseMetaTileEntity.addStackToSlot( - 3, - GT_OreDictUnificator.get( - (TileEntityFurnace.getItemBurnTime(this.mInventory[2]) >= 10000 - ? TileEntityFurnace.getItemBurnTime(this.mInventory[2]) >= 100000 - ? OrePrefixes.dust - : OrePrefixes.dustSmall - : OrePrefixes.dustTiny), - Materials.Ash, - 1L)); - aBaseMetaTileEntity.decrStackSize(2, 1); - } + } + return Optional.empty(); + } + + /** + * The upper bound for the chance to get ash from combustion + * <br> + * Ash chance scales based on burn time from 14% at 0 up to 50% at 2000 + * + * @param burnTime number assumed to be positive + * @return an upper bound between 7 and 2. + */ + private static int getAshChanceBound(int burnTime) { + return (5 - (Math.min(burnTime, 2000) / 400)) + 2; } @Override - public SteamVariant getSteamVariant() { - return SteamVariant.BRONZE; + protected boolean isItemValidFuel(@NotNull ItemStack stack) { + return getCombustionPotential(stack, TileEntityFurnace.getItemBurnTime(stack)).isPresent(); } + } diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java index 7fe3a3f4bb..d0dfe74b64 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Lava.java @@ -31,12 +31,8 @@ import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidTank; import com.gtnewhorizons.modularui.api.drawable.IDrawable; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.widget.FluidSlotWidget; -import com.gtnewhorizons.modularui.common.widget.ProgressBar; -import com.gtnewhorizons.modularui.common.widget.SlotWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -392,14 +388,7 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { } @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - return true; - } - - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { + protected boolean isAutomatable() { return true; } @@ -466,48 +455,9 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { } @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - builder.widget( - new SlotWidget(inventoryHandler, 0).setPos(43, 25) - .setBackground(getGUITextureSet().getItemSlot(), getOverlaySlotIn())) - .widget( - new SlotWidget(inventoryHandler, 1).setAccess(true, false) - .setPos(43, 61) - .setBackground(getGUITextureSet().getItemSlot(), getOverlaySlotOut())) - .widget( - new FluidSlotWidget(lavaTank).setBackground(getGUITextureSet().getFluidSlot(), getOverlaySlotIn()) - .setPos(115, 61)) - .widget(createAshSlot()) - .widget( - new ProgressBar().setProgress(() -> mSteam == null ? 0 : (float) mSteam.amount / getSteamCapacity()) - .setTexture(getProgressbarEmpty(), GT_UITextures.PROGRESSBAR_BOILER_STEAM, 10) - .setDirection(ProgressBar.Direction.UP) - .setPos(70, 25) - .setSize(10, 54)) - .widget( - new ProgressBar().setProgress(() -> mFluid == null ? 0 : (float) mFluid.amount / getCapacity()) - .setTexture(getProgressbarEmpty(), GT_UITextures.PROGRESSBAR_BOILER_WATER, 10) - .setDirection(ProgressBar.Direction.UP) - .setPos(83, 25) - .setSize(10, 54)) - .widget( - new ProgressBar().setProgress(() -> (float) mTemperature / maxProgresstime()) - .setTexture(getProgressbarEmpty(), GT_UITextures.PROGRESSBAR_BOILER_HEAT, 10) - .setDirection(ProgressBar.Direction.UP) - .setPos(96, 25) - .setSize(10, 54)) - .widget( - new ProgressBar() - // cap minimum so that one can easily see there's fuel remaining - .setProgress(() -> mProcessingEnergy > 0 ? Math.max((float) mProcessingEnergy / 1000, 1f / 5) : 0) - .setTexture(getProgressbarFuel(), 14) - .setDirection(ProgressBar.Direction.UP) - .setPos(116, 45) - .setSize(14, 14)) - .widget( - new DrawableWidget().setDrawable(getOverlaySlotCanister()) - .setPos(43, 43) - .setSize(18, 18)); + protected Widget createFuelSlot() { + return new FluidSlotWidget(lavaTank).setBackground(getGUITextureSet().getFluidSlot(), getOverlaySlotIn()) + .setPos(115, 61); } static class LavaTank extends FluidTank { diff --git a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java index f5c59330ed..4c7eb3ce38 100644 --- a/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java +++ b/src/main/java/gregtech/common/tileentities/boilers/GT_MetaTileEntity_Boiler_Solar.java @@ -15,13 +15,12 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.widget.SlotWidget; import gregtech.api.enums.Dyes; import gregtech.api.enums.SteamVariant; import gregtech.api.enums.Textures.BlockIcons; -import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -277,25 +276,13 @@ public class GT_MetaTileEntity_Boiler_Solar extends GT_MetaTileEntity_Boiler { } @Override - protected IDrawable[] getFuelSlotBackground() { - return new IDrawable[] { GT_UITextures.TRANSPARENT }; - } - - @Override - protected IDrawable[] getAshSlotBackground() { - return new IDrawable[] { GT_UITextures.TRANSPARENT }; - } - - @Override - protected SlotWidget createFuelSlot() { - // todo: remove this slot after some time - return super.createFuelSlot().setAccess(true, false); + protected Widget createFuelSlot() { + return null; } @Override protected SlotWidget createAshSlot() { - // todo: remove this slot after some time - return super.createAshSlot().setAccess(true, false); + return null; } @Override |