From 3faed14975dc7a398a2ef21d55a63b920c4cb08c Mon Sep 17 00:00:00 2001 From: Boblet Date: Tue, 28 Jun 2022 16:41:49 +0200 Subject: [PATCH] furnace fix, fallout JSON config --- .../com/hbm/config/FalloutConfigJSON.java | 82 ++++++ .../hbm/entity/effect/EntityFalloutRain.java | 263 +++++++++++------- .../TileEntityMachineElectricFurnace.java | 8 +- 3 files changed, 247 insertions(+), 106 deletions(-) create mode 100644 src/main/java/com/hbm/config/FalloutConfigJSON.java diff --git a/src/main/java/com/hbm/config/FalloutConfigJSON.java b/src/main/java/com/hbm/config/FalloutConfigJSON.java new file mode 100644 index 000000000..ad3f7c6c3 --- /dev/null +++ b/src/main/java/com/hbm/config/FalloutConfigJSON.java @@ -0,0 +1,82 @@ +package com.hbm.config; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import com.google.gson.Gson; +import com.hbm.inventory.RecipesCommon.MetaBlock; +import com.hbm.main.MainRegistry; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.world.World; + +public class FalloutConfigJSON { + + public static final List entries = new ArrayList(); + public static Random rand = new Random(); + + public static final Gson gson = new Gson(); + + public static void initialize() { + File folder = MainRegistry.configDir; + + File recFile = new File(folder.getAbsolutePath() + File.separatorChar + "hbmFallout.json"); + } + + public static class FalloutEntry { + private Block matchesBlock = null; + private int matchesMeta = -1; + private Material matchesMaterial = null; + + private MetaBlock[] primaryBlocks = null; + private MetaBlock[] secondaryBlocks = null; + private float primaryChance = 1.0F; + private double minDist = 0.0D; + private double maxDist = 1.0D; + + private boolean isSolid = false; + + public FalloutEntry mB(Block block) { this.matchesBlock = block; return this; } + public FalloutEntry mM(int meta) { this.matchesMeta = meta; return this; } + public FalloutEntry mMa(Material mat) { this.matchesMaterial = mat; return this; } + + public FalloutEntry prim(MetaBlock... blocks) { this.primaryBlocks = blocks; return this; } + public FalloutEntry sec(MetaBlock... blocks) { this.secondaryBlocks = blocks; return this; } + public FalloutEntry c(float chance) { this.primaryChance = chance; return this; } + public FalloutEntry min(double min) { this.minDist = min; return this; } + public FalloutEntry max(double max) { this.maxDist = max; return this; } + public FalloutEntry sol(boolean solid) { this.isSolid = solid; return this; } + + public boolean eval(World world, int x, int y, int z, Block b, double dist) { + + if(matchesBlock != null && b != matchesBlock) return false; + if(matchesMaterial != null && b.getMaterial() != matchesMaterial) return false; + if(matchesMeta != -1 && world.getBlockMetadata(x, y, z) != matchesMeta) return false; + if(dist > maxDist || dist < minDist) return false; + + if(primaryChance < 1F && rand.nextFloat() > primaryChance) { + + if(primaryBlocks == null) return false; + + MetaBlock block = primaryBlocks[rand.nextInt(primaryBlocks.length)]; + world.setBlock(x, y, z, block.block, block.meta, 2); + return true; + + } else { + + if(secondaryBlocks == null) return false; + + MetaBlock block = secondaryBlocks[rand.nextInt(secondaryBlocks.length)]; + world.setBlock(x, y, z, block.block, block.meta, 2); + return true; + } + } + + public boolean isSolid() { + return this.isSolid; + } + } +} diff --git a/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java b/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java index b875bcd87..e4842bf22 100644 --- a/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java +++ b/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java @@ -2,20 +2,24 @@ package com.hbm.entity.effect; import com.hbm.blocks.ModBlocks; import com.hbm.config.BombConfig; -import com.hbm.config.RadiationConfig; import com.hbm.config.VersatileConfig; import com.hbm.saveddata.AuxSavedData; +import com.hbm.util.Tuple.Quintet; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.Vec3; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; +import net.minecraft.world.storage.WorldInfo; import net.minecraftforge.common.util.ForgeDirection; import java.util.*; +import java.util.function.Consumer; public class EntityFalloutRain extends Entity { private boolean firstTick = true; // Of course Vanilla has it private in Entity... @@ -35,46 +39,61 @@ public class EntityFalloutRain extends Entity { private int tickDelay = BombConfig.fDelay; - @Override + @Override public void onUpdate() { - if(!worldObj.isRemote) { - if (firstTick) { + + if(!worldObj.isRemote) { + + if(firstTick) { if (chunksToProcess.isEmpty() && outerChunksToProcess.isEmpty()) gatherChunks(); + //initConversion(); firstTick = false; } - if (tickDelay == 0) { + if(tickDelay == 0) { tickDelay = BombConfig.fDelay; + if (!chunksToProcess.isEmpty()) { long chunkPos = chunksToProcess.remove(chunksToProcess.size() - 1); // Just so it doesn't shift the whole list every time int chunkPosX = (int) (chunkPos & Integer.MAX_VALUE); int chunkPosZ = (int) (chunkPos >> 32 & Integer.MAX_VALUE); - for (int x = chunkPosX << 4; x <= (chunkPosX << 4) + 16; x++) for (int z = chunkPosZ << 4; z <= (chunkPosZ << 4) + 16; z++) - stomp(x, z, Math.hypot(x - posX, z - posZ) * 100 / getScale()); + for(int x = chunkPosX << 4; x <= (chunkPosX << 4) + 16; x++) { + for(int z = chunkPosZ << 4; z <= (chunkPosZ << 4) + 16; z++) { + stomp(x, z, Math.hypot(x - posX, z - posZ) * 100 / getScale()); + } + } + } else if (!outerChunksToProcess.isEmpty()) { long chunkPos = outerChunksToProcess.remove(outerChunksToProcess.size() - 1); int chunkPosX = (int) (chunkPos & Integer.MAX_VALUE); int chunkPosZ = (int) (chunkPos >> 32 & Integer.MAX_VALUE); - for (int x = chunkPosX << 4; x <= (chunkPosX << 4) + 16; x++) for (int z = chunkPosZ << 4; z <= (chunkPosZ << 4) + 16; z++) { - double distance = Math.hypot(x - posX, z - posZ); - if (distance <= getScale()) stomp(x, z, distance * 100 / getScale()); + for(int x = chunkPosX << 4; x <= (chunkPosX << 4) + 16; x++) { + for(int z = chunkPosZ << 4; z <= (chunkPosZ << 4) + 16; z++) { + double distance = Math.hypot(x - posX, z - posZ); + if(distance <= getScale()) { + stomp(x, z, distance * 100 / getScale()); + } + } } - } else setDead(); + } else { + setDead(); + } } tickDelay--; if(this.isDead) { - if(BombConfig.rain > 0 && getScale() > 150) { - worldObj.getWorldInfo().setRaining(true); - worldObj.getWorldInfo().setThundering(true); - worldObj.getWorldInfo().setRainTime(BombConfig.rain); - worldObj.getWorldInfo().setThunderTime(BombConfig.rain); - AuxSavedData.setThunder(worldObj, BombConfig.rain); - } - } - } - } + if(BombConfig.rain > 0 && getScale() > 150) { + WorldInfo info = worldObj.getWorldInfo(); + info.setRaining(true); + info.setThundering(true); + info.setRainTime(BombConfig.rain); + info.setThunderTime(BombConfig.rain); + AuxSavedData.setThunder(worldObj, BombConfig.rain); + } + } + } + } private final List chunksToProcess = new ArrayList<>(); private final List outerChunksToProcess = new ArrayList<>(); @@ -106,39 +125,38 @@ public class EntityFalloutRain extends Entity { } // TODO cache chunks? - private void stomp(int x, int z, double dist) { - - int depth = 0; - - for(int y = 255; y >= 0; y--) { + private void stomp(int x, int z, double dist) { + + int depth = 0; + + for(int y = 255; y >= 0; y--) { + + Block b = worldObj.getBlock(x, y, z); + Block ab = worldObj.getBlock(x, y + 1, z); + int meta = worldObj.getBlockMetadata(x, y, z); + + if(b.getMaterial() == Material.air) + continue; + + if(b != ModBlocks.fallout && (ab == Blocks.air || (ab.isReplaceable(worldObj, x, y + 1, z) && !ab.getMaterial().isLiquid()))) { + + double d = dist / 100; + + double chance = 0.05 - Math.pow((d - 0.6) * 0.5, 2); + + if(chance >= rand.nextDouble() && ModBlocks.fallout.canPlaceBlockAt(worldObj, x, y + 1, z)) + worldObj.setBlock(x, y + 1, z, ModBlocks.fallout); + } + + if(b.isFlammable(worldObj, x, y, z, ForgeDirection.UP)) { + if(rand.nextInt(5) == 0) + worldObj.setBlock(x, y + 1, z, Blocks.fire); + } - Block b = worldObj.getBlock(x, y, z); - Block ab = worldObj.getBlock(x, y + 1, z); - int meta = worldObj.getBlockMetadata(x, y, z); - - if(b.getMaterial() == Material.air) - continue; - - if(b != ModBlocks.fallout && (ab == Blocks.air || (ab.isReplaceable(worldObj, x, y + 1, z) && !ab.getMaterial().isLiquid()))) { - - double d = dist / 100; - - double chance = 0.05 - Math.pow((d - 0.6) * 0.5, 2); - - if(chance >= rand.nextDouble() && ModBlocks.fallout.canPlaceBlockAt(worldObj, x, y + 1, z)) - worldObj.setBlock(x, y + 1, z, ModBlocks.fallout); - } - - if(b.isFlammable(worldObj, x, y, z, ForgeDirection.UP)) { - if(rand.nextInt(5) == 0) - worldObj.setBlock(x, y + 1, z, Blocks.fire); - } - if (b == Blocks.leaves || b == Blocks.leaves2) { worldObj.setBlock(x, y, z, Blocks.air); - } - - else if(b == Blocks.stone) { + + } else if(b == Blocks.stone) { depth++; @@ -151,56 +169,51 @@ public class EntityFalloutRain extends Entity { else return; - if(depth > 2) - return; - - }else if(b == Blocks.grass) { - worldObj.setBlock(x, y, z, ModBlocks.waste_earth); - return; - - } else if(b == Blocks.mycelium) { - worldObj.setBlock(x, y, z, ModBlocks.waste_mycelium); - return; - } else if(b == Blocks.sand) { - - if(rand.nextInt(20) == 0) - worldObj.setBlock(x, y, z, meta == 0 ? ModBlocks.waste_trinitite : ModBlocks.waste_trinitite_red); - return; - } + if(depth > 2) + return; - else if (b == Blocks.clay) { + } else if(b == Blocks.grass) { + worldObj.setBlock(x, y, z, ModBlocks.waste_earth); + return; + + } else if(b == Blocks.mycelium) { + worldObj.setBlock(x, y, z, ModBlocks.waste_mycelium); + return; + + } else if(b == Blocks.sand) { + + if(rand.nextInt(20) == 0) + worldObj.setBlock(x, y, z, meta == 0 ? ModBlocks.waste_trinitite : ModBlocks.waste_trinitite_red); + return; + + } else if (b == Blocks.clay) { worldObj.setBlock(x, y, z, Blocks.hardened_clay); - return; - } - - else if (b == Blocks.mossy_cobblestone) { + return; + + } else if (b == Blocks.mossy_cobblestone) { worldObj.setBlock(x, y, z, Blocks.coal_ore); - return; - } - - else if (b == Blocks.coal_ore) { + return; + + } else if (b == Blocks.coal_ore) { int ra = rand.nextInt(150); if (ra < 20) { worldObj.setBlock(x, y, z, Blocks.diamond_ore); } else if (ra < 30) { worldObj.setBlock(x, y, z, Blocks.emerald_ore); } - return; - } - - else if (b == Blocks.log || b == Blocks.log2) { + return; + + } else if (b == Blocks.log || b == Blocks.log2) { worldObj.setBlock(x, y, z, ModBlocks.waste_log); - } - - else if (b == Blocks.brown_mushroom_block || b == Blocks.red_mushroom_block) { + + } else if (b == Blocks.brown_mushroom_block || b == Blocks.red_mushroom_block) { if (meta == 10) { worldObj.setBlock(x, y, z, ModBlocks.waste_log); } else { worldObj.setBlock(x, y, z, Blocks.air,0,2); } - } - - else if (b.getMaterial() == Material.wood && b.isOpaqueCube() && b != ModBlocks.waste_log) { + + } else if (b.getMaterial() == Material.wood && b.isOpaqueCube() && b != ModBlocks.waste_log) { worldObj.setBlock(x, y, z, ModBlocks.waste_planks); } @@ -209,31 +222,46 @@ public class EntityFalloutRain extends Entity { worldObj.setBlock(x, y, z, ModBlocks.ore_schrabidium); else worldObj.setBlock(x, y, z, ModBlocks.ore_uranium_scorched); - return; - } - - else if (b == ModBlocks.ore_nether_uranium) { + return; + + } else if (b == ModBlocks.ore_nether_uranium) { if (rand.nextInt(VersatileConfig.getSchrabOreChance()) == 0) worldObj.setBlock(x, y, z, ModBlocks.ore_nether_schrabidium); else worldObj.setBlock(x, y, z, ModBlocks.ore_nether_uranium_scorched); - return; - } - - else if(b == ModBlocks.ore_gneiss_uranium) { + return; + + } else if(b == ModBlocks.ore_gneiss_uranium) { if(rand.nextInt(VersatileConfig.getSchrabOreChance()) == 0) worldObj.setBlock(x, y, z, ModBlocks.ore_gneiss_schrabidium); else worldObj.setBlock(x, y, z, ModBlocks.ore_gneiss_uranium_scorched); return; - - //this piece stops the "stomp" from reaching below ground - } else if(b.isNormalCube()) { + //this piece stops the "stomp" from reaching below ground + } else if(b.isNormalCube()) { return; } - } - } + } + } + + /*public HashMap directConversions = new HashMap(); + + private void initConversion() { + + directConversions.put(Blocks.stone, new BlockConversion() { @Override public boolean convert() { + if(dist < 5) set(ModBlocks.sellafield_1); + else if(dist < 15) set(ModBlocks.sellafield_0); + else if(dist < 75) set(ModBlocks.sellafield_slaked); + return true; + } + }); + + directConversions.put(Blocks.grass, new BlockConversion() { boolean convert() { set(ModBlocks.waste_earth); return false; }}); + directConversions.put(Blocks.mycelium, new BlockConversion() { boolean convert() { set(ModBlocks.waste_mycelium); return false; }}); + directConversions.put(Blocks.leaves, new BlockConversion() { boolean convert() { destroy(); return false; }}); + directConversions.put(Blocks.leaves2, new BlockConversion() { boolean convert() { destroy(); return false; }}); + }*/ @Override protected void entityInit() { @@ -283,4 +311,41 @@ public class EntityFalloutRain extends Entity { int scale = this.dataWatcher.getWatchableObjectInt(16); return scale == 0 ? 1 : scale; } + + /*private abstract class BlockConversion { + + protected World world; + protected int x; + protected int y; + protected int z; + protected double dist; + + public boolean invoke(World world, int x, int y, int z, double dist) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.dist = dist; + + return convert(); + } + + abstract boolean convert(); + + protected void destroy() { + world.setBlock(x, y, z, Blocks.air); + } + + protected void set(Block b) { + world.setBlock(x, y, z, b); + } + + protected void setChance(Block b, float f) { + if(world.rand.nextFloat() < f) world.setBlock(x, y, z, b); + } + + protected void setConditional(Block b, float f) { + if(world.rand.nextFloat() < f) world.setBlock(x, y, z, b); + } + }*/ } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineElectricFurnace.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineElectricFurnace.java index 03e621775..c7c4030d0 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineElectricFurnace.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineElectricFurnace.java @@ -4,20 +4,14 @@ import com.hbm.blocks.machine.MachineElectricFurnace; import com.hbm.inventory.UpgradeManager; import com.hbm.items.machine.ItemMachineUpgrade.UpgradeType; import com.hbm.lib.Library; -import com.hbm.packet.AuxElectricityPacket; -import com.hbm.packet.AuxGaugePacket; -import com.hbm.packet.PacketDispatcher; import com.hbm.tileentity.TileEntityMachineBase; import api.hbm.energy.IBatteryItem; import api.hbm.energy.IEnergyUser; -import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityMachineElectricFurnace extends TileEntityMachineBase implements ISidedInventory, IEnergyUser { @@ -178,7 +172,7 @@ public class TileEntityMachineElectricFurnace extends TileEntityMachineBase impl power -= consumption; - if(this.progress == maxProgress) { + if(this.progress >= maxProgress) { this.progress = 0; this.processItem(); flag1 = true;