From 21dd6d6dc1ccbc9a640140a01941745657af4a10 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Wed, 14 Aug 2024 21:05:06 -0400 Subject: [PATCH] misc changes --- .../nuclear_horizons/ClientProxy.java | 6 + .../nuclear_horizons/CommonProxy.java | 5 + .../nuclear_horizons/NuclearHorizons.java | 2 +- .../nuclear_horizons/ServerProxy.java | 12 + .../reactors/fluids/FluidList.java | 7 +- .../reactors/items/BasicHeatVentItem.java | 2 +- .../reactors/tile/TileReactorCore.java | 205 ++++++++++++++++-- 7 files changed, 211 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/recursive_pineapple/nuclear_horizons/ServerProxy.java diff --git a/src/main/java/com/recursive_pineapple/nuclear_horizons/ClientProxy.java b/src/main/java/com/recursive_pineapple/nuclear_horizons/ClientProxy.java index a4b3638..d64d70c 100644 --- a/src/main/java/com/recursive_pineapple/nuclear_horizons/ClientProxy.java +++ b/src/main/java/com/recursive_pineapple/nuclear_horizons/ClientProxy.java @@ -5,9 +5,15 @@ import codechicken.nei.guihook.GuiContainerManager; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.relauncher.Side; public class ClientProxy extends CommonProxy { + @Override + public Side getSide() { + return Side.CLIENT; + } + @Override public void preInit(FMLPreInitializationEvent event) { super.preInit(event); diff --git a/src/main/java/com/recursive_pineapple/nuclear_horizons/CommonProxy.java b/src/main/java/com/recursive_pineapple/nuclear_horizons/CommonProxy.java index e14bad3..e2d49d3 100644 --- a/src/main/java/com/recursive_pineapple/nuclear_horizons/CommonProxy.java +++ b/src/main/java/com/recursive_pineapple/nuclear_horizons/CommonProxy.java @@ -10,9 +10,14 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; +import cpw.mods.fml.relauncher.Side; public class CommonProxy { + public Side getSide() { + return null; + } + public void preInit(FMLPreInitializationEvent event) { NuclearHorizons.LOG.info("Loading Nuclear Horizons version " + Tags.VERSION); diff --git a/src/main/java/com/recursive_pineapple/nuclear_horizons/NuclearHorizons.java b/src/main/java/com/recursive_pineapple/nuclear_horizons/NuclearHorizons.java index 6840a6c..8a2b195 100644 --- a/src/main/java/com/recursive_pineapple/nuclear_horizons/NuclearHorizons.java +++ b/src/main/java/com/recursive_pineapple/nuclear_horizons/NuclearHorizons.java @@ -23,7 +23,7 @@ public class NuclearHorizons { @SidedProxy( clientSide = "com.recursive_pineapple.nuclear_horizons.ClientProxy", - serverSide = "com.recursive_pineapple.nuclear_horizons.CommonProxy") + serverSide = "com.recursive_pineapple.nuclear_horizons.ServerProxy") public static CommonProxy proxy; @Instance diff --git a/src/main/java/com/recursive_pineapple/nuclear_horizons/ServerProxy.java b/src/main/java/com/recursive_pineapple/nuclear_horizons/ServerProxy.java new file mode 100644 index 0000000..c75e30e --- /dev/null +++ b/src/main/java/com/recursive_pineapple/nuclear_horizons/ServerProxy.java @@ -0,0 +1,12 @@ +package com.recursive_pineapple.nuclear_horizons; + +import cpw.mods.fml.relauncher.Side; + +public class ServerProxy extends CommonProxy { + + @Override + public Side getSide() { + return Side.SERVER; + } + +} diff --git a/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/fluids/FluidList.java b/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/fluids/FluidList.java index 273405c..85c6f6f 100644 --- a/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/fluids/FluidList.java +++ b/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/fluids/FluidList.java @@ -1,10 +1,11 @@ package com.recursive_pineapple.nuclear_horizons.reactors.fluids; +import com.recursive_pineapple.nuclear_horizons.reactors.blocks.BlockList; + +// import gregtech.api.enums.Materials; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -import com.recursive_pineapple.nuclear_horizons.reactors.blocks.BlockList; - public class FluidList { public static final String COOLANT_NAME = "nh_coolant"; @@ -62,6 +63,6 @@ public net.minecraft.util.IIcon getFlowingIcon() { public static void registerCoolants() { CoolantRegistry.registerCoolant(COOLANT, HOT_COOLANT, 1); - CoolantRegistry.registerCoolant(FluidRegistry.getFluid("supercoolant"), HOT_SUPER_COOLANT, 5); + // CoolantRegistry.registerCoolant(Materials.Lead.mStandardMoltenFluid, HOT_SUPER_COOLANT, 10); } } diff --git a/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/items/BasicHeatVentItem.java b/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/items/BasicHeatVentItem.java index 589f22c..dcbf69d 100644 --- a/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/items/BasicHeatVentItem.java +++ b/src/main/java/com/recursive_pineapple/nuclear_horizons/reactors/items/BasicHeatVentItem.java @@ -125,7 +125,7 @@ public void addInformation(ItemStack itemStack, EntityPlayer player, List reactorBlocks = new ArrayList<>(); + private double heatRatio = 0; + public TileReactorCore() { } @@ -291,9 +298,9 @@ public void updateEntity() { this.setChamberCount(getAttachedChambers(worldObj, xCoord, yCoord, zCoord)); + this.tickCounter++; + if (!this.worldObj.isRemote) { - this.tickCounter++; - if (this.tickCounter % REACTOR_TICK_SPEED == 0) { boolean wasActive = isActive; @@ -343,7 +350,25 @@ public void updateEntity() { } this.emitEnergy(); + } else { + if(heatRatio >= 0.4) { + spawnSmoke(xCoord, yCoord, zCoord); + + for (var d : DirectionUtil.values()) { + if (d.getBlock(worldObj, xCoord, yCoord, zCoord) == BlockList.REACTOR_CHAMBER) { + spawnSmoke(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ); + } + } + } + } + } + + private void spawnSmoke(int x, int y, int z) { + if(worldObj.getBlock(x, y + 1, z).isBlockNormalCube()) { + return; } + + worldObj.spawnParticle("smoke", x + Math.random() * 0.8 + 0.1, y + 1.1, z + Math.random() * 0.8 + 0.1, 0, 0.01 * (Math.random() * 0.5 + 1), 0); } @Override @@ -354,7 +379,8 @@ public Packet getDescriptionPacket() { data.setBoolean("isActive", isActive); data.setInteger("storedEU", storedEU); data.setInteger("storedHeat", storedHeat); - data.setInteger("roundedHeat", this.roundedHeat); + data.setDouble("heatRatio", heatRatio); + data.setInteger("roundedHeat", roundedHeat); data.setInteger("addedHeat", addedHeat); data.setInteger("addedEU", addedEU); data.setBoolean("isFluid", isFluid); @@ -372,6 +398,7 @@ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.isActive = data.getBoolean("isActive"); this.storedEU = data.getInteger("storedEU"); this.storedHeat = data.getInteger("storedHeat"); + this.heatRatio = data.getDouble("heatRatio"); this.roundedHeat = data.getInteger("roundedHeat"); this.addedHeat = data.getInteger("addedHeat"); this.addedEU = data.getInteger("addedEU"); @@ -494,6 +521,10 @@ private static long emitEnergyToNetwork(long voltage, long amperage, TileEntity // #region Inventory Logic + private void onComponentInvalidated(int index) { + this.components[index] = null; + } + private int transformSlotIndex(int invSlot) { int cols = this.getColumnCount(); @@ -525,7 +556,7 @@ public ItemStack decrStackSize(int index, int count) { return null; } - this.components[index] = null; + this.onComponentInvalidated(index); this.markDirty(); @@ -551,7 +582,7 @@ public ItemStack getStackInSlotOnClosing(int index) { } this.contents[index] = null; - this.components[index] = null; + this.onComponentInvalidated(index); this.markDirty(); @@ -567,7 +598,7 @@ public void setInventorySlotContents(int index, ItemStack stack) { } this.contents[index] = stack; - this.components[index] = null; + this.onComponentInvalidated(index); if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); @@ -615,9 +646,16 @@ public boolean isItemValidForSlot(int index, ItemStack stack) { // #region Reactor Grid Logic + public void resetHullHeatCache() { + this.hullHeatCache = null; + } + private void doHeatTick() { this.addedHeat = 0; + // a component could change their hull heat increase each tick, so we have to invalidate this here and not when components change + resetHullHeatCache(); + for (int row = 0; row < ROW_COUNT; row++) { for (int col = 0; col < COL_COUNT; col++) { var component = getComponent(col, row); @@ -630,6 +668,10 @@ private void doHeatTick() { for (var reactorBlock : reactorBlocks) { reactorBlock.onHeatTick(this); } + + heatRatio = ((double) storedHeat) / ((double) this.getMaxHullHeat()); + + doHeatDamage(); } private void doEUTick() { @@ -659,6 +701,102 @@ private void doEUTick() { this.voltage = (int) (Math.pow(4, voltageTier) * 8); } + private static final DamageSource RADIATION_DAMAGE = new DamageSource("nh_radiation"); + + private static double map(double x, double in_min, double in_max, double out_min, double out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + } + + private void doHeatDamage() { + final int DAMAGE_RADIUS = 3; + + // flames + if(heatRatio >= 0.4) { + for(int i = 0; i < 10; i++) { + int x = xCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + int y = yCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + int z = zCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + + var block = worldObj.getBlock(x, y, z); + + if (block.isFlammable(worldObj, x, y, z, ForgeDirection.UNKNOWN)) { + block.breakBlock(worldObj, x, y, z, block, worldObj.getBlockMetadata(x, y, z)); + worldObj.setBlock(x, y, z, Blocks.fire, 0, 3); + break; + } + } + } + + // evaporation + if (heatRatio >= 0.5) { + for(int i = 0; i < 10; i++) { + int x = xCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + int y = yCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + int z = zCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + + var block = worldObj.getBlock(x, y, z); + + if (block instanceof IFluidBlock fluidBlock && fluidBlock.getFluid().getTemperature() < 375) { + worldObj.setBlock(x, y, z, Blocks.air, 0, 3); + // fire hiss + worldObj.playAuxSFX(1004, x, y, z, 0); + break; + } + } + } + + // damage + if (heatRatio >= 0.7) { + var entities = worldObj.getEntitiesWithinAABB( + EntityLivingBase.class, + AxisAlignedBB.getBoundingBox( + xCoord - DAMAGE_RADIUS, + yCoord - DAMAGE_RADIUS, + zCoord - DAMAGE_RADIUS, + xCoord + DAMAGE_RADIUS, + yCoord + DAMAGE_RADIUS, + zCoord + DAMAGE_RADIUS)); + + for(var entity : entities) { + entity.attackEntityFrom(RADIATION_DAMAGE, 4); + } + } + + // lava + if (heatRatio >= 0.85) { + for(int i = 0; i < 10; i++) { + int x = xCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + int y = yCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + int z = zCoord + (int) map(Math.random(), 0, 1, -DAMAGE_RADIUS, DAMAGE_RADIUS); + + // don't melt the reactor or its chambers, because why would we want to do that? :tootroll: + if((Math.abs(x - xCoord) + Math.abs(y - yCoord) + Math.abs(z - zCoord)) <= 1) { + continue; + } + + var block = worldObj.getBlock(x, y, z); + + if (!block.isAir(worldObj, x, y, z) && block.getBlockHardness(worldObj, x, y, z) < 5) { + worldObj.setBlock(x, y, z, Blocks.flowing_lava, 1, 3); + // fire hiss + worldObj.playAuxSFX(1004, x, y, z, 0); + break; + } + } + } + + // explosion + if (heatRatio >= 1) { + worldObj.newExplosion( + null, + xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, + (float) (30 * getExplosionRadiusMultiplier()), + true, + true + ); + } + } + @Override public int getWidth() { return COL_COUNT; @@ -746,6 +884,10 @@ public int getHullHeat() { @Override public int getMaxHullHeat() { + if (hullHeatCache != null) { + return hullHeatCache; + } + int maxHeat = 5000; for (int row = 0; row < ROW_COUNT; row++) { @@ -757,9 +899,26 @@ public int getMaxHullHeat() { } } + hullHeatCache = maxHeat; + return maxHeat; } + private double getExplosionRadiusMultiplier() { + double mult = 1.0; + + for (int row = 0; row < ROW_COUNT; row++) { + for (int col = 0; col < COL_COUNT; col++) { + var component = getComponent(col, row); + if (component != null) { + mult *= component.getExplosionRadiusMultiplier(); + } + } + } + + return mult; + } + @Override public void setHullHeat(int newHeat) { this.storedHeat = newHeat;