From f2c0a4fc6b65749871b60580a6f65374f589b994 Mon Sep 17 00:00:00 2001 From: Mary <33456283+FourIsTheNumber@users.noreply.github.com> Date: Sat, 7 Sep 2024 09:16:14 -0400 Subject: Finishing touches on black hole compressor (#3060) Co-authored-by: Martin Robertz Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: BucketBrigade <138534411+CookieBrigade@users.noreply.github.com> --- .../multi/compressor/MTEBlackHoleCompressor.java | 382 ++++++++++++++------- .../multi/compressor/MTEHIPCompressor.java | 15 +- .../machines/multi/compressor/MTEHeatSensor.java | 4 +- .../multi/compressor/MTEIndustrialCompressor.java | 17 +- .../multi/compressor/MTENeutroniumCompressor.java | 16 +- .../tileentities/render/TileEntityBlackhole.java | 99 ++++++ 6 files changed, 401 insertions(+), 132 deletions(-) create mode 100644 src/main/java/gregtech/common/tileentities/render/TileEntityBlackhole.java (limited to 'src/main/java/gregtech/common/tileentities') diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index ba893e045d..367b529bc3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -1,16 +1,20 @@ package gregtech.common.tileentities.machines.multi.compressor; +import static bartworks.util.BWTooltipReference.TT; import static com.gtnewhorizon.structurelib.structure.StructureUtility.*; import static gregtech.api.enums.GTValues.AuthorFourIsTheNumber; import static gregtech.api.enums.GTValues.Ollie; import static gregtech.api.enums.HatchElement.*; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_BLACKHOLE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_BLACKHOLE_ACTIVE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_BLACKHOLE_ACTIVE_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_BLACKHOLE_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_BLACKHOLE_UNSTABLE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_BLACKHOLE_UNSTABLE_GLOW; import static gregtech.api.util.GTStructureUtility.buildHatchAdder; import static gregtech.api.util.GTStructureUtility.ofFrame; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -20,6 +24,7 @@ import javax.annotation.Nonnull; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -42,11 +47,13 @@ import gregtech.api.enums.Materials; import gregtech.api.enums.MaterialsUEVplus; import gregtech.api.enums.Textures; import gregtech.api.gui.modularui.GTUITextures; +import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.logic.ProcessingLogic; import gregtech.api.metatileentity.implementations.MTEExtendedPowerMultiBlockBase; +import gregtech.api.metatileentity.implementations.MTEHatchEnergy; import gregtech.api.metatileentity.implementations.MTEHatchInput; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; @@ -57,8 +64,10 @@ import gregtech.api.render.TextureFactory; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; +import gregtech.api.util.OverclockCalculator; import gregtech.common.blocks.BlockCasings10; import gregtech.common.items.MetaGeneratedItem01; +import gregtech.common.tileentities.render.TileEntityBlackhole; import gtPlusPlus.core.util.minecraft.PlayerUtils; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -111,7 +120,8 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase spacetimeHatches = new ArrayList<>(); + + /** + * 1: Off + * 2: On, stable + * 3: On, unstable + */ + private byte blackHoleStatus = 1; private final FluidStack blackholeCatalyzingCost = (MaterialsUEVplus.SpaceTime).getMolten(1); private int catalyzingCostModifier = 1; @@ -143,6 +159,22 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase getStructureDefinition() { return STRUCTURE_DEFINITION; @@ -171,15 +203,39 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase { + MAIN_OVERLAY = OVERLAY_MULTI_BLACKHOLE; + GLOW_OVERLAY = OVERLAY_MULTI_BLACKHOLE_GLOW; + } + case 2 -> { + MAIN_OVERLAY = OVERLAY_MULTI_BLACKHOLE_ACTIVE; + GLOW_OVERLAY = OVERLAY_MULTI_BLACKHOLE_ACTIVE_GLOW; + } + case 3 -> { + MAIN_OVERLAY = OVERLAY_MULTI_BLACKHOLE_UNSTABLE; + GLOW_OVERLAY = OVERLAY_MULTI_BLACKHOLE_UNSTABLE_GLOW; + } } + + rTexture = new ITexture[] { + Textures.BlockIcons + .getCasingTextureForId(GTUtility.getCasingTextureIndex(GregTechAPI.sBlockCasings10, 11)), + TextureFactory.builder() + .addIcon(MAIN_OVERLAY) + .extFacing() + .build(), + TextureFactory.builder() + .addIcon(GLOW_OVERLAY) + .extFacing() + .glow() + .build() }; + } else { rTexture = new ITexture[] { Textures.BlockIcons .getCasingTextureForId(GTUtility.getCasingTextureIndex(GregTechAPI.sBlockCasings10, 11)) }; @@ -227,78 +286,78 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase 1) return false; + energyHatchTier = mExoticEnergyHatches.get(0).mTier; + } else if (!mEnergyHatches.isEmpty()) { + byte tier = mEnergyHatches.get(0).mTier; + for (MTEHatchEnergy hatch : mEnergyHatches) if (hatch.mTier < tier) tier = hatch.mTier; + energyHatchTier = tier; + } return true; } @@ -334,19 +404,21 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase 0) { currentTip.add(EnumChatFormatting.DARK_PURPLE + "Black Hole Active"); currentTip.add( @@ -382,6 +454,8 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase 0) { - if (!blackholeOn) return CheckRecipeResultRegistry.NO_BLACK_HOLE; - } else { - if (blackHoleStability <= 0) setSpeedBonus(5F); - else if (blackholeOn) setSpeedBonus(0.2F); + setSpeedBonus(0.2F); + if (blackHoleStatus == 1) return CheckRecipeResultRegistry.NO_BLACK_HOLE; + + // If the recipe doesn't require black hole, but it is unstable, incur a 0.5x speed penalty + if (recipe.getMetadataOrDefault(CompressionTierKey.INSTANCE, 0) == 0 && (blackHoleStatus == 3)) { + setSpeedBonus(5F); } return super.validateRecipe(recipe); } @@ -432,7 +522,7 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase 0) { + if ((blackHoleStatus == 3) && recipe.getMetadataOrDefault(CompressionTierKey.INSTANCE, 0) > 0) { return CheckRecipeResultRegistry.UNSTABLE_BLACK_HOLE; } return CheckRecipeResultRegistry.SUCCESSFUL; @@ -446,29 +536,40 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase= 0) { - float stabilityDecrease = 1F; - // If the machine is running, reduce stability loss by 25% - if (this.maxProgresstime() != 0) { - stabilityDecrease = 0.75F; - } - // Search all hatches for catalyst fluid - // If found enough, drain it and reduce stability loss to 0 - // Every 30 drains, double the cost - FluidStack totalCost = new FluidStack(blackholeCatalyzingCost, catalyzingCostModifier); - for (MTEHatchInput hatch : mInputHatches) { - if (drain(hatch, totalCost, false)) { - drain(hatch, totalCost, true); - catalyzingCounter += 1; - stabilityDecrease = 0; - if (catalyzingCounter >= 30) { - catalyzingCostModifier *= 2; - catalyzingCounter = 0; + if (blackHoleStatus == 2) { + if (blackHoleStability >= 0) { + if (rendererTileEntity == null) createRenderBlock(); + rendererTileEntity.setStability(blackHoleStability / 100F); + float stabilityDecrease = 1F; + // If the machine is running, reduce stability loss by 25% + if (this.maxProgresstime() != 0) { + stabilityDecrease = 0.75F; + } + + // Search all hatches for catalyst fluid + // If found enough, drain it and reduce stability loss to 0 + // Every 30 drains, double the cost + FluidStack totalCost = new FluidStack(blackholeCatalyzingCost, catalyzingCostModifier); + + boolean didDrain = false; + for (MTEHatchInput hatch : spacetimeHatches) { + if (drain(hatch, totalCost, false)) { + drain(hatch, totalCost, true); + catalyzingCounter += 1; + stabilityDecrease = 0; + if (catalyzingCounter >= 30) { + catalyzingCostModifier *= 2; + catalyzingCounter = 0; + } + didDrain = true; + break; } } - } - if (blackHoleStability >= 0) blackHoleStability -= stabilityDecrease; - else blackHoleStability = 0; + if (rendererTileEntity == null) createRenderBlock(); + rendererTileEntity.toggleLaser(didDrain); + if (blackHoleStability >= 0) blackHoleStability -= stabilityDecrease; + else blackHoleStability = 0; + } else blackHoleStatus = 3; } } } @@ -531,4 +632,53 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase 0) doingHIP = true; + int recipeReq = recipe.getMetadataOrDefault(CompressionTierKey.INSTANCE, 0); + if (recipeReq == 1) { + doingHIP = true; + } else if (recipeReq == 2) { + return CheckRecipeResultRegistry.NO_RECIPE; + } return super.validateRecipe(recipe); } }.setMaxParallelSupplier(this::getMaxParallelRecipes); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHeatSensor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHeatSensor.java index 8ea57bc1cf..82f9d43506 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHeatSensor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEHeatSensor.java @@ -31,8 +31,8 @@ public class MTEHeatSensor extends MTEHatch { protected boolean inverted = false; private boolean isOn = false; - private static final IIconContainer textureFont = Textures.BlockIcons.OVERLAY_HATCH_BLACKHOLE; - private static final IIconContainer textureFont_Glow = Textures.BlockIcons.OVERLAY_HATCH_BLACKHOLE_GLOW; + private static final IIconContainer textureFont = Textures.BlockIcons.OVERLAY_HATCH_HEAT_SENSOR; + private static final IIconContainer textureFont_Glow = Textures.BlockIcons.OVERLAY_HATCH_HEAT_SENSOR_GLOW; public MTEHeatSensor(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, 0, "Reads heat from HIP Unit."); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java index e21da1856f..c887d1cf03 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEIndustrialCompressor.java @@ -14,6 +14,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; +import org.jetbrains.annotations.NotNull; + import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; import com.gtnewhorizon.structurelib.structure.IStructureDefinition; import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; @@ -29,7 +31,11 @@ import gregtech.api.metatileentity.implementations.MTEExtendedPowerMultiBlockBas import gregtech.api.multitileentity.multiblock.casing.Glasses; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.metadata.CompressionTierKey; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.MultiblockTooltipBuilder; import gregtech.common.blocks.BlockCasings10; @@ -188,7 +194,16 @@ public class MTEIndustrialCompressor extends MTEExtendedPowerMultiBlockBase 0) + return CheckRecipeResultRegistry.NO_RECIPE; + return super.validateRecipe(recipe); + } + }.setSpeedBonus(1F / 2F) .setMaxParallelSupplier(this::getMaxParallelRecipes) .setEuModifier(0.9F); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTENeutroniumCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTENeutroniumCompressor.java index 323e09f61b..f5326e284e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTENeutroniumCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTENeutroniumCompressor.java @@ -9,10 +9,10 @@ import static gregtech.api.enums.HatchElement.Energy; import static gregtech.api.enums.HatchElement.InputBus; import static gregtech.api.enums.HatchElement.Maintenance; import static gregtech.api.enums.HatchElement.OutputBus; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR_ACTIVE; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR_ACTIVE_GLOW; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_MULTI_COMPRESSOR_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_NEUTRONIUM; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_NEUTRONIUM_ACTIVE; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_NEUTRONIUM_ACTIVE_GLOW; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_MULTI_NEUTRONIUM_GLOW; import static gregtech.api.util.GTStructureUtility.buildHatchAdder; import static gregtech.api.util.GTStructureUtility.ofFrame; @@ -115,11 +115,11 @@ public class MTENeutroniumCompressor extends MTEExtendedPowerMultiBlockBase.5 starts showing changes + private float stability = 1; + private float laserR = 0.318f, laserG = 0.157f, laserB = 0.533f; + private boolean laserRender = false; + + private static final String NBT_TAG = "BLACKHOLE"; + + private static final String STABILITY_NBT_TAG = NBT_TAG + "STABILITY"; + private static final String COLOR_RED_NBT_TAG = NBT_TAG + "COLOR_RED"; + private static final String COLOR_GREEN_NBT_TAG = NBT_TAG + "COLOR_GREEN"; + private static final String COLOR_BLUE_NBT_TAG = NBT_TAG + "COLOR_BLUE"; + private static final String RENDER_NBT_TAG = NBT_TAG + "LASER_RENDER"; + + public void setLaserColor(float r, float g, float b) { + laserR = r; + laserG = g; + laserB = b; + updateToClient(); + } + + public void toggleLaser(boolean toggle) { + laserRender = toggle; + updateToClient(); + } + + public float getLaserR() { + return laserR; + } + + public float getLaserG() { + return laserG; + } + + public float getLaserB() { + return laserB; + } + + public boolean getLaserRender() { + return laserRender; + } + + public void setStability(float stability) { + // Can probably be simplified, maps stability > .5 as 1, and stability <.5 from 0 to 1 + this.stability = ((float) Math.min(stability + .5, 1f) - .5f) * 2f; + updateToClient(); + } + + public float getStability() { + return stability; + } + + public void writeToNBT(NBTTagCompound compound) { + super.writeToNBT(compound); + compound.setFloat(STABILITY_NBT_TAG, stability); + compound.setFloat(COLOR_RED_NBT_TAG, laserR); + compound.setFloat(COLOR_GREEN_NBT_TAG, laserG); + compound.setFloat(COLOR_BLUE_NBT_TAG, laserB); + compound.setBoolean(RENDER_NBT_TAG, laserRender); + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + stability = compound.getFloat(STABILITY_NBT_TAG); + laserR = compound.getFloat(COLOR_RED_NBT_TAG); + laserG = compound.getFloat(COLOR_GREEN_NBT_TAG); + laserB = compound.getFloat(COLOR_BLUE_NBT_TAG); + laserRender = compound.getBoolean(RENDER_NBT_TAG); + super.readFromNBT(compound); + + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + writeToNBT(nbttagcompound); + + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + readFromNBT(pkt.func_148857_g()); + } + + public void updateToClient() { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + +} -- cgit