RBMK heat movement, column-specific meltdowns, gamerules

This commit is contained in:
Bob 2021-04-27 23:31:08 +02:00
parent 1554109061
commit 4a5947cec5
12 changed files with 366 additions and 28 deletions

View File

@ -32,7 +32,7 @@ public class RBMKDebrisBurning extends RBMKDebris {
MainRegistry.proxy.effectNT(data);
}
if(rand.nextInt(50) == 0) {
if(rand.nextInt(100) == 0) {
world.setBlock(x, y, z, ModBlocks.pribris);
} else {
world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));

View File

@ -26,8 +26,9 @@ public class ItemDyatlov extends Item {
TileEntity te = world.getTileEntity(pos[0], pos[1], pos[2]);
if(te instanceof TileEntityRBMKBase) {
((TileEntityRBMKBase)te).meltdown();
//((TileEntityRBMKBase)te).heat = 100000;
}
}
}

View File

@ -80,6 +80,7 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
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.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@ -1137,6 +1138,12 @@ public class MainRegistry {
PacketDispatcher.registerPackets();
}
//yes kids, this is where we would usually register commands
@EventHandler
public void serverStart(FMLServerStartingEvent event) {
RBMKDials.createDials(event.getServer().getEntityWorld());
}
private void loadConfig(FMLPreInitializationEvent event) {
Configuration config = new Configuration(event.getSuggestedConfigurationFile());

View File

@ -0,0 +1,30 @@
package com.hbm.tileentity.machine.rbmk;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
public class RBMKDials {
public static final String KEY_PASSIVE_COOLING = "dialPassiveCooling";
public static void createDials(World world) {
GameRules rules = world.getGameRules();
if(!rules.getGameRuleStringValue(KEY_PASSIVE_COOLING).isEmpty())
rules.setOrCreateGameRule(KEY_PASSIVE_COOLING, "5.0");
}
public static double getPassiveCooling(World world) {
return shittyWorkaroundParseDouble(world.getGameRules().getGameRuleStringValue(KEY_PASSIVE_COOLING), 5.0D);
}
//why make the double representation accessible in a game rule when you can just force me to add a second pointless parsing operation?
public static double shittyWorkaroundParseDouble(String s, double def) {
try {
return Double.parseDouble(s);
} catch(Exception ex) { }
return def;
}
}

View File

@ -1,5 +1,45 @@
package com.hbm.tileentity.machine.rbmk;
public class TileEntityRBMKAbsorber extends TileEntityRBMKBase {
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
public class TileEntityRBMKAbsorber extends TileEntityRBMKBase {
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(reduce > 1 && i == 4 - reduce) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
int count = 1 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.BLANK);
}
super.onMelt(reduce);
}
}

View File

@ -61,7 +61,7 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
* @return
*/
public double passiveCooling() {
return 5D;
return RBMKDials.getPassiveCooling(worldObj); //default: 5.0D
}
//necessary checks to figure out whether players are close enough to ensure that the reactor can be safely used
@ -78,10 +78,14 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
NBTTagCompound data = new NBTTagCompound();
this.writeToNBT(data);
this.networkPack(data, 10);
this.networkPack(data, trackingRange());
}
}
public int trackingRange() {
return 25;
}
public static final ForgeDirection[] heatDirs = new ForgeDirection[] {
ForgeDirection.NORTH,
ForgeDirection.EAST,
@ -95,7 +99,8 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
private void moveHeat() {
List<TileEntityRBMKBase> rec = new ArrayList();
double req = 0;
rec.add(this);
double heatTot = this.heat;
for(ForgeDirection dir : heatDirs) {
@ -103,28 +108,22 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
if(te instanceof TileEntityRBMKBase) {
TileEntityRBMKBase base = (TileEntityRBMKBase) te;
if(base.heat < this.heat) {
rec.add(base);
req += (this.heat - base.heat) / 2D;
}
rec.add(base);
heatTot += base.heat;
}
}
if(rec.size() > 0) {
int members = rec.size();
double stepSize = 0.2D;
if(members > 1) {
double max = req / rec.size();
double targetHeat = heatTot / (double)members;
for(TileEntityRBMKBase base : rec) {
double move = (this.heat - base.heat) / 2D;
if(move > max)
move = max;
base.heat += move;
this.heat -= move;
for(TileEntityRBMKBase rbmk : rec) {
double delta = targetHeat - rbmk.heat;
rbmk.heat += delta * stepSize;
rbmk.markDirty();
}
}
}
@ -238,7 +237,7 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
/*reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
@ -271,7 +270,19 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
debris.motionZ = worldObj.rand.nextGaussian() * 0.25D;
debris.motionY = 1D + worldObj.rand.nextDouble();
worldObj.spawnEntityInWorld(debris);
}
}*/
if(this.hasLid())
spawnDebris(DebrisType.LID);
}
protected void spawnDebris(DebrisType type) {
EntityRBMKDebris debris = new EntityRBMKDebris(worldObj, xCoord + 0.5D, yCoord + 4D, zCoord + 0.5D, type);
debris.motionX = worldObj.rand.nextGaussian() * 0.25D;
debris.motionZ = worldObj.rand.nextGaussian() * 0.25D;
debris.motionY = 1D + worldObj.rand.nextDouble();
worldObj.spawnEntityInWorld(debris);
}
public static HashSet<TileEntityRBMKBase> columns = new HashSet();

View File

@ -1,5 +1,45 @@
package com.hbm.tileentity.machine.rbmk;
public class TileEntityRBMKBlank extends TileEntityRBMKBase {
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
public class TileEntityRBMKBlank extends TileEntityRBMKBase {
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(reduce > 1 && i == 4 - reduce) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
int count = 1 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.BLANK);
}
super.onMelt(reduce);
}
}

View File

@ -3,6 +3,8 @@ package com.hbm.tileentity.machine.rbmk;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import com.hbm.handler.FluidTypeHandler.FluidType;
import com.hbm.interfaces.IControlReceiver;
import com.hbm.interfaces.IFluidAcceptor;
@ -11,7 +13,9 @@ import com.hbm.inventory.FluidTank;
import com.hbm.lib.Library;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
public class TileEntityRBMKBoiler extends TileEntityRBMKSlottedBase implements IFluidAcceptor, IFluidSource, IControlReceiver {
@ -163,4 +167,40 @@ public class TileEntityRBMKBoiler extends TileEntityRBMKSlottedBase implements I
this.markDirty();
}
}
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(reduce > 1 && i == 4 - reduce) {
//TODO: steam explosions
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
int count = 1 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.BLANK);
}
super.onMelt(reduce);
}
}

View File

@ -1,9 +1,14 @@
package com.hbm.tileentity.machine.rbmk;
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
public abstract class TileEntityRBMKControl extends TileEntityRBMKSlottedBase {
@ -46,6 +51,11 @@ public abstract class TileEntityRBMKControl extends TileEntityRBMKSlottedBase {
super.updateEntity();
}
@Override
public int trackingRange() {
return 150;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
@ -72,4 +82,38 @@ public abstract class TileEntityRBMKControl extends TileEntityRBMKSlottedBase {
public double getMaxRenderDistanceSquared() {
return 65536.0D;
}
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(reduce > 1 && i == 4 - reduce) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
int count = 2 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.ROD);
}
//control rods will not spawn lid projectiles since the lid is already part of the rod projectiles
//super.onMelt(reduce);
}
}

View File

@ -1,5 +1,44 @@
package com.hbm.tileentity.machine.rbmk;
public class TileEntityRBMKModerator extends TileEntityRBMKBase {
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
public class TileEntityRBMKModerator extends TileEntityRBMKBase {
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(reduce > 1 && i == 4 - reduce) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
int count = 2 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.GRAPHITE);
}
super.onMelt(reduce);
}
}

View File

@ -1,5 +1,43 @@
package com.hbm.tileentity.machine.rbmk;
public class TileEntityRBMKReflector extends TileEntityRBMKBase {
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import net.minecraft.init.Blocks;
import net.minecraft.util.MathHelper;
public class TileEntityRBMKReflector extends TileEntityRBMKBase {
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(reduce > 1 && i == 4 - reduce) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
int count = 1 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.BLANK);
}
super.onMelt(reduce);
}
}

View File

@ -1,9 +1,13 @@
package com.hbm.tileentity.machine.rbmk;
import com.hbm.blocks.ModBlocks;
import com.hbm.entity.projectile.EntityRBMKDebris.DebrisType;
import com.hbm.items.machine.ItemRBMKRod;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBMKFluxReceiver {
@ -21,6 +25,7 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
return "container.rbmkRod";
}
@SuppressWarnings("incomplete-switch") //shut the fuck up
@Override
public void receiveFlux(NType type, double flux) {
@ -166,4 +171,47 @@ public class TileEntityRBMKRod extends TileEntityRBMKSlottedBase implements IRBM
nbt.setString("f_heat", rod.getCoreHeat(slots[0]) + " / " + rod.getHullHeat(slots[0]) + " / " + rod.meltingPoint);
}
}
@Override
public void onMelt(int reduce) {
reduce = MathHelper.clamp_int(reduce, 1, 3);
if(worldObj.rand.nextInt(3) == 0)
reduce++;
for(int i = 3; i >= 0; i--) {
if(i <= 4 - reduce) {
if(slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.corium_block);
} else {
if(reduce > 1 && i == 4 - reduce) {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris_burning);
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, ModBlocks.pribris);
}
}
} else {
worldObj.setBlock(xCoord, yCoord + i, zCoord, Blocks.air);
}
worldObj.markBlockForUpdate(xCoord, yCoord + i, zCoord);
}
if(slots[0] != null && slots[0].getItem() instanceof ItemRBMKRod) {
int count = 1 + worldObj.rand.nextInt(3);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.FUEL);
}
}
spawnDebris(DebrisType.ELEMENT);
super.onMelt(reduce);
}
}