diff options
author | Léa Gris <lea.gris@noiraude.net> | 2023-03-30 21:48:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-30 21:48:25 +0200 |
commit | 7ac8db9ecf8bd8775b5249e48f8ac9a84d675b4d (patch) | |
tree | 85faa9ccd9c8d25f3b4cdf36beb03492b51d0462 /src/main | |
parent | 8187e9841b50a5bd1e713655d7b6598ffa8e8ac6 (diff) | |
download | GT5-Unofficial-7ac8db9ecf8bd8775b5249e48f8ac9a84d675b4d.tar.gz GT5-Unofficial-7ac8db9ecf8bd8775b5249e48f8ac9a84d675b4d.tar.bz2 GT5-Unofficial-7ac8db9ecf8bd8775b5249e48f8ac9a84d675b4d.zip |
Implementation of A more useful Lava Boiler (#1814)
* Fix Missing null/empty checks on boilers base class
Would cause a deadlock on empty boilers unable to start,
as it tried to transfer null or empty FuildStack.
* Fix Sound coordinates so it can be centered on block
* WIP Lava Boiler Improuvements
* :spotlessapply
* Add GUI slot block background textures
* Restrict ash slot to remove items only (disallow inserting items there)
* Finalize GUI and Obsidian Production mechanic
* Fix still output Obisidian from cooled Lava even when no more Lava available
* Lava Boiler Textures: Improves GUI and TOP
- Fluid slot now has Steam themed textures
- Item slot block background gets a smaller icon that hides behind
actual item blocks
- Boiler TOP is now a drain texture instead of pump
* Add null check
Diffstat (limited to 'src/main')
13 files changed, 453 insertions, 55 deletions
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java index 4b6030fa19..a1d1be02ac 100644 --- a/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java +++ b/src/main/java/gregtech/api/gui/modularui/GT_UITextures.java @@ -25,6 +25,7 @@ public class GT_UITextures { .of(MODID, "gui/background/text_field_light_gray", 61, 12, 1); public static final SteamTexture SLOT_ITEM_STEAM = SteamTexture.fullImage(MODID, "gui/slot/item_%s"); + public static final SteamTexture SLOT_FLUID_STEAM = SteamTexture.fullImage(MODID, "gui/slot/fluid_%s"); public static final AdaptableUITexture SLOT_DARK_GRAY = AdaptableUITexture .of(MODID, "gui/slot/dark_gray", 18, 18, 1); public static final AdaptableUITexture SLOT_MAINTENANCE = AdaptableUITexture @@ -68,6 +69,8 @@ public class GT_UITextures { public static final UITexture OVERLAY_SLOT_DUST = UITexture.fullImage(MODID, "gui/overlay_slot/dust"); public static final SteamTexture OVERLAY_SLOT_DUST_STEAM = SteamTexture .fullImage(MODID, "gui/overlay_slot/dust_%s"); + public static final SteamTexture OVERLAY_SLOT_BLOCK_STEAM = SteamTexture + .fullImage(MODID, "gui/overlay_slot/block_%s"); public static final UITexture OVERLAY_SLOT_EXPLOSIVE = UITexture.fullImage(MODID, "gui/overlay_slot/explosive"); public static final UITexture OVERLAY_SLOT_EXTRUDER_SHAPE = UITexture .fullImage(MODID, "gui/overlay_slot/extruder_shape"); diff --git a/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java b/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java index 1bacff886a..8b6e9f85ec 100644 --- a/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java +++ b/src/main/java/gregtech/api/gui/modularui/GUITextureSet.java @@ -41,6 +41,7 @@ public class GUITextureSet { public static final Function<SteamVariant, GUITextureSet> STEAM = steamVariant -> new GUITextureSet() .setMainBackground(GT_UITextures.BACKGROUND_STEAM.get(steamVariant)) .setItemSlot(GT_UITextures.SLOT_ITEM_STEAM.get(steamVariant)) + .setFluidSlot(GT_UITextures.SLOT_FLUID_STEAM.get(steamVariant)) .setCoverTab( GT_UITextures.TAB_COVER_STEAM_NORMAL.get(steamVariant), GT_UITextures.TAB_COVER_STEAM_HIGHLIGHT.get(steamVariant), diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java b/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java index 9d6de7df83..dfee28cf47 100644 --- a/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java +++ b/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java @@ -8,12 +8,13 @@ import gregtech.api.util.GT_Utility; public class GT_Runnable_Sound implements Runnable { - private final int mX, mY, mZ, mTimeUntilNextSound; + private final double mX, mY, mZ; + private final int mTimeUntilNextSound; private final World mWorld; private final ResourceLocation mSoundResourceLocation; private final float mSoundStrength, mSoundModulation; - public GT_Runnable_Sound(World aWorld, int aX, int aY, int aZ, int aTimeUntilNextSound, + public GT_Runnable_Sound(World aWorld, double aX, double aY, double aZ, int aTimeUntilNextSound, ResourceLocation aSoundResourceLocation, float aSoundStrength, float aSoundModulation) { mWorld = aWorld; mX = aX; @@ -26,16 +27,32 @@ public class GT_Runnable_Sound implements Runnable { } /** - * @deprecated Use {@link #GT_Runnable_Sound(World, int, int, int, int, ResourceLocation, float, float)} + * @deprecated Use {@link #GT_Runnable_Sound(World, double, double, double, int, ResourceLocation, float, float)} + */ + public GT_Runnable_Sound(World aWorld, int aX, int aY, int aZ, int aTimeUntilNextSound, + ResourceLocation aSoundResourceLocation, float aSoundStrength, float aSoundModulation) { + this( + aWorld, + (double) aX + 0.5D, + (double) aY + 0.5D, + (double) aZ + 0.5D, + aTimeUntilNextSound, + aSoundResourceLocation, + aSoundStrength, + aSoundModulation); + } + + /** + * @deprecated Use {@link #GT_Runnable_Sound(World, double, double, double, int, ResourceLocation, float, float)} */ @Deprecated public GT_Runnable_Sound(World aWorld, int aX, int aY, int aZ, int aTimeUntilNextSound, String aSoundName, float aSoundStrength, float aSoundModulation) { this( aWorld, - aX, - aY, - aZ, + (double) aX + 0.5D, + (double) aY + 0.5D, + (double) aZ + 0.5D, aTimeUntilNextSound, new ResourceLocation(aSoundName), aSoundStrength, diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 577364c0f7..4dd99e3ff7 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -2165,9 +2165,9 @@ public class GT_Utility { if (GregTech_API.sMultiThreadedSounds) new Thread( new GT_Runnable_Sound( GT.getThePlayer().worldObj, - MathHelper.floor_double(aX), - MathHelper.floor_double(aY), - MathHelper.floor_double(aZ), + aX, + aY, + aZ, aTimeUntilNextSound, aSoundResourceLocation, aSoundStrength, @@ -2175,9 +2175,9 @@ public class GT_Utility { "Sound Effect").start(); else new GT_Runnable_Sound( GT.getThePlayer().worldObj, - MathHelper.floor_double(aX), - MathHelper.floor_double(aY), - MathHelper.floor_double(aZ), + aX, + aY, + aZ, aTimeUntilNextSound, aSoundResourceLocation, aSoundStrength, 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 3d2f69c26d..2519afd4a5 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 @@ -318,7 +318,14 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa tile.doExplosion(2048L); } + /** + * Pushes Steam to a Side of this Boiler + * + * @param aBaseMetaTileEntity The tile-entity instance of this Boiler + * @param aSide The ordinal direction of the side to push Steam to + */ protected final void pushSteamToSide(IGregTechTileEntity aBaseMetaTileEntity, int aSide) { + if (mSteam == null || mSteam.amount == 0) return; IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide((byte) aSide); if (tTileEntity == null) return; FluidStack tDrained = aBaseMetaTileEntity @@ -332,7 +339,13 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa true); } + /** + * Pushes steam to Fluid inventories at all sides except Front. + * + * @param aBaseMetaTileEntity The tile-entity instance of this Boiler + */ protected void pushSteamToInventories(IGregTechTileEntity aBaseMetaTileEntity) { + if (mSteam == null || mSteam.amount == 0) return; for (int i = 1; (this.mSteam != null) && (i < 6); i++) { if (i == aBaseMetaTileEntity.getFrontFacing()) continue; pushSteamToSide(aBaseMetaTileEntity, i); @@ -380,10 +393,6 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa return 100; } - protected boolean isOutputToFront() { - return false; - } - protected abstract int getPollution(); @Override @@ -473,7 +482,8 @@ public abstract class GT_MetaTileEntity_Boiler extends GT_MetaTileEntity_BasicTa } protected SlotWidget createAshSlot() { - return (SlotWidget) new SlotWidget(inventoryHandler, 3).setPos(115, 25).setBackground(getAshSlotBackground()); + return (SlotWidget) new SlotWidget(inventoryHandler, 3).setAccess(true, false).setPos(115, 25) + .setBackground(getAshSlotBackground()); } @Override 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 6a1ad39195..9e17dc12ee 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 @@ -4,23 +4,56 @@ import static gregtech.api.enums.Textures.BlockIcons.BOILER_LAVA_FRONT; import static gregtech.api.enums.Textures.BlockIcons.BOILER_LAVA_FRONT_ACTIVE; import static gregtech.api.enums.Textures.BlockIcons.BOILER_LAVA_FRONT_ACTIVE_GLOW; import static gregtech.api.enums.Textures.BlockIcons.BOILER_LAVA_FRONT_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.FLUID_IN_SIGN; +import static gregtech.api.enums.Textures.BlockIcons.FLUID_OUT_SIGN; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_STEELBRICKS_BOTTOM; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_STEELBRICKS_SIDE; import static gregtech.api.enums.Textures.BlockIcons.MACHINE_STEELBRICKS_TOP; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_DRAIN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT; +import static gregtech.api.objects.XSTR.XSTR_INSTANCE; +import net.minecraft.block.Block; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidContainerItem; +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.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; import gregtech.GT_Mod; -import gregtech.api.enums.Materials; -import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.Dyes; +import gregtech.api.enums.ParticleFX; +import gregtech.api.enums.SoundResource; import gregtech.api.enums.SteamVariant; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.render.TextureFactory; import gregtech.api.util.GT_ModHandler; -import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder; public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { @@ -28,6 +61,8 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { public static final int ENERGY_PER_LAVA = 1; public static final int CONSUMPTION_PER_HEATUP = 3; public static final int PRODUCTION_PER_SECOND = 600; + private final FluidTank lavaTank = new LavaTank(null, getCapacity()); + private int mCooledLava = 0; public GT_MetaTileEntity_Boiler_Lava(int aID, String aName, String aNameRegional) { super( @@ -36,7 +71,7 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { aNameRegional, new String[] { "A Boiler running off Lava", "Produces " + PRODUCTION_PER_SECOND + "L of Steam per second", - "Causes " + Integer.toString(GT_Mod.gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond) + "Causes " + GT_Mod.gregtechproxy.mPollutionHighPressureLavaBoilerPerSecond + " Pollution per second", "Consumes " + ((double) CONSUMPTION_PER_HEATUP / ENERGY_PER_LAVA) + "L of Lava every " @@ -53,22 +88,46 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { } @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, + boolean aActive, boolean aRedstone) { + final ForgeDirection sideDirection = ForgeDirection.getOrientation(aSide); + final ForgeDirection facingDirection = ForgeDirection.getOrientation(aFacing); + final ForgeDirection rearDirection = facingDirection.getOpposite(); + final ITexture[] tmp; + if (aSide >= 2) { + if (sideDirection == facingDirection) { + if (aActive) tmp = mTextures[4][aColorIndex + 1]; + else tmp = mTextures[3][aColorIndex + 1]; + } else if (sideDirection == rearDirection) { + tmp = mTextures[5][aColorIndex + 1]; + } else { + tmp = mTextures[2][aColorIndex + 1]; + } + } else tmp = mTextures[aSide][aColorIndex + 1]; + if (aSide != aFacing && tmp.length == 2) { + return new ITexture[] { tmp[0] }; + } + return tmp; + } + + @Override public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[5][17][]; - final ITexture[] texBottom = { TextureFactory.of(MACHINE_STEELBRICKS_BOTTOM) }, - texTop = { TextureFactory.of(MACHINE_STEELBRICKS_TOP), TextureFactory.of(OVERLAY_PIPE) }, - texSide = { TextureFactory.of(MACHINE_STEELBRICKS_SIDE), TextureFactory.of(OVERLAY_PIPE) }, - texFront = { TextureFactory.of(MACHINE_STEELBRICKS_SIDE), TextureFactory.of(BOILER_LAVA_FRONT), - TextureFactory.of(BOILER_LAVA_FRONT_GLOW) }, - texFrontActive = { TextureFactory.of(MACHINE_STEELBRICKS_SIDE), - TextureFactory.of(BOILER_LAVA_FRONT_ACTIVE), - TextureFactory.builder().addIcon(BOILER_LAVA_FRONT_ACTIVE_GLOW).glow().build() }; - for (byte i = 0; i < 17; i++) { - rTextures[0][i] = texBottom; - rTextures[1][i] = texTop; - rTextures[2][i] = texSide; - rTextures[3][i] = texFront; - rTextures[4][i] = texFrontActive; + ITexture[][][] rTextures = new ITexture[6][17][]; + for (byte color = -1; color < 16; color++) { + int i = color + 1; + short[] colorModulation = Dyes.getModulation(color, Dyes._NULL.mRGBa); + rTextures[0][i] = new ITexture[] { TextureFactory.of(MACHINE_STEELBRICKS_BOTTOM, colorModulation) }; + rTextures[1][i] = new ITexture[] { TextureFactory.of(MACHINE_STEELBRICKS_TOP, colorModulation), + TextureFactory.of(OVERLAY_DRAIN), TextureFactory.of(FLUID_IN_SIGN) }; + rTextures[2][i] = new ITexture[] { TextureFactory.of(MACHINE_STEELBRICKS_SIDE, colorModulation), + TextureFactory.of(OVERLAY_PIPE_OUT), TextureFactory.of(FLUID_IN_SIGN) }; + rTextures[3][i] = new ITexture[] { TextureFactory.of(MACHINE_STEELBRICKS_SIDE, colorModulation), + TextureFactory.of(BOILER_LAVA_FRONT, colorModulation), TextureFactory.of(BOILER_LAVA_FRONT_GLOW) }; + rTextures[4][i] = new ITexture[] { TextureFactory.of(MACHINE_STEELBRICKS_SIDE, colorModulation), + TextureFactory.of(BOILER_LAVA_FRONT_ACTIVE), + TextureFactory.builder().addIcon(BOILER_LAVA_FRONT_ACTIVE_GLOW).glow().build() }; + rTextures[5][i] = new ITexture[] { TextureFactory.of(MACHINE_STEELBRICKS_SIDE, colorModulation), + TextureFactory.of(OVERLAY_PIPE_OUT), TextureFactory.of(FLUID_OUT_SIGN) }; } return rTextures; } @@ -105,6 +164,7 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { @Override protected int getEnergyConsumption() { + this.mCooledLava += CONSUMPTION_PER_HEATUP; return CONSUMPTION_PER_HEATUP; } @@ -113,18 +173,261 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { return COOLDOWN_INTERVAL; } + /** + * Attempts to fill an {@link IFluidTank} from the {@link FluidStack} content of an {@link ItemStack} + * + * @param destinationIFluidTank The destination {@link IFluidTank} to fill + * @param SourceItemStack The source {@link ItemStack} containing the Fluid + * @return The {@link ItemStack} of the Empty version of the source {@link ItemStack} or {@code null} if none + */ + public static ItemStack fillIFluidTankFromItemStack(IFluidTank destinationIFluidTank, ItemStack SourceItemStack) { + if (destinationIFluidTank == null || SourceItemStack == null) return null; + + final FluidStack containedFluidStack = GT_Utility.getFluidForFilledItem(SourceItemStack, true); + if (containedFluidStack == null || containedFluidStack.amount == 0) return null; + + final int fillableAmount = destinationIFluidTank.fill(containedFluidStack, false); + if (fillableAmount <= 0) return null; + + final Item containerItem = SourceItemStack.getItem(); + if (containerItem instanceof IFluidContainerItem) { + IFluidContainerItem equippedIFluidContainerItem = (IFluidContainerItem) containerItem; + destinationIFluidTank.fill(equippedIFluidContainerItem.drain(SourceItemStack, fillableAmount, true), true); + return null; + } else { + final ItemStack emptyContainerItemStack = GT_Utility.getContainerForFilledItem(SourceItemStack, false); + destinationIFluidTank.fill(containedFluidStack, true); + return emptyContainerItemStack; + } + } + @Override - protected void updateFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { - if (GT_OreDictUnificator.isItemStackInstanceOf(this.mInventory[2], OrePrefixes.bucket.get(Materials.Lava))) { - this.mProcessingEnergy += 1000 * ENERGY_PER_LAVA; - aBaseMetaTileEntity.decrStackSize(2, 1); - aBaseMetaTileEntity.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.bucket, Materials.Empty, 1L)); - } else if (GT_OreDictUnificator - .isItemStackInstanceOf(this.mInventory[2], OrePrefixes.bucketClay.get(Materials.Lava))) { - this.mProcessingEnergy += 1000 * ENERGY_PER_LAVA; - aBaseMetaTileEntity.decrStackSize(2, 1); - // Clay lava buckets break, so you don't get it back. + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide() || aPlayer == null) return true; + + final ItemStack equippedItemStack = aPlayer.getCurrentEquippedItem(); + final FluidStack equippedContainerFluidStack = GT_Utility.getFluidForFilledItem(equippedItemStack, true); + final ItemStack returnedItemStack; + final IFluidTank tank; + + if (GT_ModHandler.isWater(equippedContainerFluidStack)) { + tank = this; + } else if (GT_ModHandler.isLava(equippedContainerFluidStack)) { + tank = lavaTank; + } else { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + returnedItemStack = fillIFluidTankFromItemStack(tank, equippedItemStack); + if (returnedItemStack != null && !aPlayer.capabilities.isCreativeMode) { + if (equippedItemStack.stackSize > 1) { + if (!aPlayer.inventory.addItemStackToInventory(returnedItemStack)) { + aBaseMetaTileEntity.getWorld().spawnEntityInWorld( + new EntityItem( + aBaseMetaTileEntity.getWorld(), + (double) aBaseMetaTileEntity.getXCoord() + 0.5D, + (double) aBaseMetaTileEntity.getYCoord() + 1.5D, + (double) aBaseMetaTileEntity.getZCoord() + 0.5D, + equippedItemStack)); + } else if (aPlayer instanceof EntityPlayerMP) { + ((EntityPlayerMP) aPlayer).sendContainerToPlayer(aPlayer.inventoryContainer); } + aPlayer.inventory.decrStackSize(aPlayer.inventory.currentItem, 1); + } else { + aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, returnedItemStack); + } + } + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (lavaTank.getFluid() != null) aNBT.setTag("mLava", lavaTank.getFluid().writeToNBT(new NBTTagCompound())); + aNBT.setInteger("mCooledLava", this.mCooledLava); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + lavaTank.setFluid(FluidStack.loadFluidStackFromNBT(aNBT.getCompoundTag("mLava"))); + this.mCooledLava = aNBT.getInteger("mCooledLava"); + } + + /** + * Pushes steam to Fluid inventory at the rear. + * + * @param aBaseMetaTileEntity The tile-entity instance of this Lava Boiler + */ + @Override + protected void pushSteamToInventories(IGregTechTileEntity aBaseMetaTileEntity) { + if (mSteam == null || mSteam.amount == 0) return; + pushSteamToSide( + aBaseMetaTileEntity, + ForgeDirection.getOrientation(aBaseMetaTileEntity.getFrontFacing()).getOpposite().ordinal()); + } + + /** + * Drains Lava from Fluid inventory on top + * + * @param aBaseMetaTileEntity The tile-entity instance of this Lava Boiler + */ + protected void drainLava(IGregTechTileEntity aBaseMetaTileEntity) { + final IFluidHandler upTank = aBaseMetaTileEntity.getITankContainerAtSide((byte) ForgeDirection.UP.ordinal()); + if (upTank == null) return; + // Simulates drain of maximum lava amount up to 1000L that can fit the internal tank + final FluidStack drainableLavaStack = upTank.drain( + ForgeDirection.DOWN, + FluidRegistry.getFluidStack( + "lava", + Math.min( + this.lavaTank.getCapacity() + - (this.lavaTank.getFluid() != null ? this.lavaTank.getFluid().amount : 0), + 1000)), + false); + if (!GT_ModHandler.isLava(drainableLavaStack) || drainableLavaStack.amount <= 0) return; + // Performs actual drain up and fill internal tank + this.lavaTank.fill(upTank.drain(ForgeDirection.DOWN, drainableLavaStack, true), true); + } + + /** + * Processes cooled Lava into Obsidian + * + * @return success | failure when cannot output + */ + private boolean lavaToObsidian() { + if (this.mCooledLava >= 1000) { + if (getBaseMetaTileEntity().addStackToSlot(3, new ItemStack(Blocks.obsidian, 1))) { + this.mCooledLava -= 1000; + } else { + return false; + } + } + return true; + } + + /** + * Draws random flames and smoke particles in front of this Lava Boiler when it is active + * + * @param aBaseMetaTileEntity The entity that will handle the {@link Block#randomDisplayTick} + */ + @SideOnly(Side.CLIENT) + @Override + public void onRandomDisplayTick(IGregTechTileEntity aBaseMetaTileEntity) { + if (aBaseMetaTileEntity.isActive()) { + + final byte frontFacing = aBaseMetaTileEntity.getFrontFacing(); + final ForgeDirection frontDirection = ForgeDirection.getOrientation(frontFacing); + + if (frontFacing > 1 && aBaseMetaTileEntity.getCoverIDAtSide(frontFacing) == 0 + && !aBaseMetaTileEntity.getOpacityAtSide(frontFacing)) { + + final double oX = aBaseMetaTileEntity.getOffsetX(frontFacing, 1) + 8D / 16D; + final double oY = aBaseMetaTileEntity.getOffsetY(frontFacing, 1); + final double oZ = aBaseMetaTileEntity.getOffsetZ(frontFacing, 1) + 8D / 16D; + final double offset = -0.48D; + final double horizontal = XSTR_INSTANCE.nextFloat() * 10D / 16D - 5D / 16D; + + final double x, y, z; + + y = oY + XSTR_INSTANCE.nextFloat() * 6D / 16D; + + switch (frontDirection) { + case WEST: + x = oX - offset; + z = oZ + horizontal; + break; + case EAST: + x = oX + offset; + z = oZ + horizontal; + break; + case NORTH: + x = oX + horizontal; + z = oZ - offset; + break; + default: // case SOUTH: + x = oX + horizontal; + z = oZ + offset; + break; + } + + ParticleEventBuilder particleEventBuilder = (new ParticleEventBuilder()).setMotion(0D, 0D, 0D) + .setPosition(x, y, z).setWorld(getBaseMetaTileEntity().getWorld()); + particleEventBuilder.setIdentifier(ParticleFX.SMOKE).run(); + particleEventBuilder.setIdentifier(ParticleFX.FLAME).run(); + } + } + } + + @Override + public boolean isFluidInputAllowed(FluidStack aFluid) { + return GT_ModHandler.isWater(aFluid) || GT_ModHandler.isLava(aFluid); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (!aBaseMetaTileEntity.isServerSide()) return; + final FluidStack containedFluidStack = GT_Utility.getFluidForFilledItem(mInventory[getInputSlot()], true); + if (GT_ModHandler.isWater(containedFluidStack)) super.onPreTick(aBaseMetaTileEntity, aTick); + if (GT_ModHandler.isLava(containedFluidStack) + && lavaTank.fill(containedFluidStack, false) == containedFluidStack.amount + && aBaseMetaTileEntity.addStackToSlot( + getOutputSlot(), + GT_Utility.getContainerForFilledItem(mInventory[getInputSlot()], true), + 1)) { + lavaTank.fill(containedFluidStack, true); + aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aTick % 20 == 0) drainLava(aBaseMetaTileEntity); + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return true; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { + return true; + } + + @Override + public void doSound(byte aIndex, double aX, double aY, double aZ) { + if (aIndex != GT_MetaTileEntity_Boiler.SOUND_EVENT_LET_OFF_EXCESS_STEAM) return; + + final ForgeDirection rearDirection = ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()) + .getOpposite(); + GT_Utility.doSoundAtClient( + SoundResource.RANDOM_FIZZ, + 2, + 1.0F, + // Sound emitted from center of rear face (Steam Output) + aX + 0.5 * rearDirection.offsetX, + aY, + aZ + 0.5 * rearDirection.offsetZ); + + new ParticleEventBuilder().setIdentifier(ParticleFX.CLOUD).setWorld(getBaseMetaTileEntity().getWorld()) + // Particles emitted with a 1 block/s velocity toward rear + .setMotion(rearDirection.offsetX / 20D, 0D, rearDirection.offsetZ / 20D).<ParticleEventBuilder>times( + 8, + // Particles emitted from center of rear face (Steam Output) + x -> x.setPosition(aX + rearDirection.offsetX / 2D, aY, aZ + rearDirection.offsetZ / 2D).run()); + } + + @Override + protected void updateFuel(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (!lavaToObsidian()) return; + if (lavaTank.getFluid() == null || lavaTank.getFluid().amount <= 0) return; + final int amountToDrain = Math.min(lavaTank.getFluid().amount, 1000); + final FluidStack drainedLava = lavaTank.drain(amountToDrain, false); + if (drainedLava == null || drainedLava.amount == 0) return; + lavaTank.drain(amountToDrain, true); + this.mProcessingEnergy += drainedLava.amount * ENERGY_PER_LAVA; } @Override @@ -133,14 +436,78 @@ public class GT_MetaTileEntity_Boiler_Lava extends GT_MetaTileEntity_Boiler { } @Override - public final int fill(FluidStack aFluid, boolean doFill) { - if ((GT_ModHandler.isLava(aFluid)) && (this.mProcessingEnergy < 50)) { - int tFilledAmount = Math.min(50, aFluid.amount); - if (doFill) { - this.mProcessingEnergy += tFilledAmount * ENERGY_PER_LAVA; - } - return tFilledAmount; + public int fill(FluidStack aFluid, boolean doFill) { + if (GT_ModHandler.isWater(aFluid)) return super.fill(aFluid, doFill); + if (GT_ModHandler.isLava(aFluid)) return lavaTank.fill(aFluid, doFill); + return 0; + } + + @Override + public FluidStack getDisplayedFluid() { + return lavaTank.getFluid(); + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + return new FluidTankInfo[] { super.getTankInfo(aSide)[0], + new FluidTankInfo(this.lavaTank.getFluid(), this.lavaTank.getCapacity()), + new FluidTankInfo(getDrainableStack(), getCapacity()) }; + } + + @Override + protected IDrawable[] getAshSlotBackground() { + return new IDrawable[] { getGUITextureSet().getItemSlot(), + GT_UITextures.OVERLAY_SLOT_BLOCK_STEAM.get(getSteamVariant()) }; + } + + @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 / getCapacity()) + .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)); + } + + static class LavaTank extends FluidTank { + + public LavaTank(FluidStack stack, int capacity) { + super(stack, capacity); + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + return GT_ModHandler.isLava(resource) ? super.fill(resource, doFill) : 0; } - return super.fill(aFluid, doFill); } } diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block.png b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block.png Binary files differnew file mode 100644 index 0000000000..66bc3742c4 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block.png diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_bronze.png b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_bronze.png Binary files differnew file mode 100644 index 0000000000..4b8f68f319 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_bronze.png diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_primitive.png b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_primitive.png Binary files differnew file mode 100644 index 0000000000..23599f3eca --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_primitive.png diff --git a/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_steel.png b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_steel.png Binary files differnew file mode 100644 index 0000000000..382b68b180 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/overlay_slot/block_steel.png diff --git a/src/main/resources/assets/gregtech/textures/gui/slot/fluid_bronze.png b/src/main/resources/assets/gregtech/textures/gui/slot/fluid_bronze.png Binary files differnew file mode 100644 index 0000000000..87a20f2e94 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/slot/fluid_bronze.png diff --git a/src/main/resources/assets/gregtech/textures/gui/slot/fluid_primitive.png b/src/main/resources/assets/gregtech/textures/gui/slot/fluid_primitive.png Binary files differnew file mode 100644 index 0000000000..7d7d3e2c35 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/slot/fluid_primitive.png diff --git a/src/main/resources/assets/gregtech/textures/gui/slot/fluid_steel.png b/src/main/resources/assets/gregtech/textures/gui/slot/fluid_steel.png Binary files differnew file mode 100644 index 0000000000..c9c04ea90c --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/gui/slot/fluid_steel.png |