From 685412473ed4f2d53de727863c02de4acfd8f5e7 Mon Sep 17 00:00:00 2001 From: Boblet Date: Mon, 5 Jun 2023 16:39:05 +0200 Subject: [PATCH] fixes, some more pollution stuff --- changelog | 3 +- .../handler/pollution/PollutionHandler.java | 101 +++++++++++++++--- .../hazard/type/HazardTypeHydroactive.java | 3 +- src/main/java/com/hbm/items/ModItems.java | 3 + .../hbm/items/tool/ItemPollutionDetector.java | 32 ++++++ .../java/com/hbm/items/tool/ItemWandD.java | 8 +- .../hbm/textures/items/pollution_detector.png | Bin 0 -> 241 bytes 7 files changed, 133 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/hbm/items/tool/ItemPollutionDetector.java create mode 100644 src/main/resources/assets/hbm/textures/items/pollution_detector.png diff --git a/changelog b/changelog index 494b463ba..f875507b2 100644 --- a/changelog +++ b/changelog @@ -14,4 +14,5 @@ * Paraffin wax can now also be used to make chlorated petroleum wax * Retextured schrabidium batteries, the cap is now black instead of red -## Fixed \ No newline at end of file +## Fixed +* Fixed hydroreactive stat not applying when an item is dropped in the rain diff --git a/src/main/java/com/hbm/handler/pollution/PollutionHandler.java b/src/main/java/com/hbm/handler/pollution/PollutionHandler.java index 692ba83a2..fff803ed6 100644 --- a/src/main/java/com/hbm/handler/pollution/PollutionHandler.java +++ b/src/main/java/com/hbm/handler/pollution/PollutionHandler.java @@ -4,12 +4,17 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.HashMap; +import java.util.Locale; import java.util.Map.Entry; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.relauncher.Side; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.MathHelper; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -19,7 +24,58 @@ public class PollutionHandler { public static final String fileName = "hbmpollution.dat"; public static HashMap perWorld = new HashMap(); + + /////////////////////// + /// UTILITY METHODS /// + /////////////////////// + public static void incrementPollution(World world, int x, int y, int z, PollutionType type, float amount) { + PollutionPerWorld ppw = perWorld.get(world); + if(ppw == null) return; + ChunkCoordIntPair pos = new ChunkCoordIntPair(x >> 6, z >> 6); + PollutionData data = ppw.pollution.get(pos); + if(data == null) { + data = new PollutionData(); + ppw.pollution.put(pos, data); + } + data.pollution[type.ordinal()] = MathHelper.clamp_float(data.pollution[type.ordinal()] + amount, 0F, 10_000F); + } + + public static void decrementPollution(World world, int x, int y, int z, PollutionType type, float amount) { + incrementPollution(world, x, y, z, type, -amount); + } + + public static void setPollution(World world, int x, int y, int z, PollutionType type, float amount) { + PollutionPerWorld ppw = perWorld.get(world); + if(ppw == null) return; + ChunkCoordIntPair pos = new ChunkCoordIntPair(x >> 6, z >> 6); + PollutionData data = ppw.pollution.get(pos); + if(data == null) { + data = new PollutionData(); + ppw.pollution.put(pos, data); + } + data.pollution[type.ordinal()] = amount; + } + + public static float getPollution(World world, int x, int y, int z, PollutionType type) { + PollutionPerWorld ppw = perWorld.get(world); + if(ppw == null) return 0F; + ChunkCoordIntPair pos = new ChunkCoordIntPair(x >> 6, z >> 6); + PollutionData data = ppw.pollution.get(pos); + if(data == null) return 0F; + return data.pollution[type.ordinal()]; + } + + public static PollutionData getPollutionData(World world, int x, int y, int z) { + PollutionPerWorld ppw = perWorld.get(world); + if(ppw == null) return null; + ChunkCoordIntPair pos = new ChunkCoordIntPair(x >> 6, z >> 6); + PollutionData data = ppw.pollution.get(pos); + return data; + } + ////////////////////// + /// EVENT HANDLING /// + ////////////////////// @SubscribeEvent public void onWorldLoad(WorldEvent.Load event) { if(!event.world.isRemote) { @@ -70,16 +126,33 @@ public class PollutionHandler { public String getDataDir(WorldServer world) { String dir = world.getSaveHandler().getWorldDirectory().getAbsolutePath(); - if(world.provider.dimensionId != 0) { dir += File.separator + "DIM" + world.provider.dimensionId; } - dir += File.separator + "data"; - return dir; } + + ////////////////////////// + /// SYSTEM UPDATE LOOP /// + ////////////////////////// + int eggTimer = 0; + @SubscribeEvent + public void updateSystem(TickEvent.ServerTickEvent event) { + + if(event.side == Side.SERVER && event.phase == Phase.END) { + + eggTimer++; + if(eggTimer < 60) return; + eggTimer = 0; + + // TBI + } + } + ////////////////////// + /// DATA STRUCTURE /// + ////////////////////// public static class PollutionPerWorld { public HashMap pollution = new HashMap(); @@ -118,22 +191,26 @@ public class PollutionHandler { } public static class PollutionData { - float soot; - float poison; - float heavyMetal; + public float[] pollution = new float[PollutionType.values().length]; public static PollutionData fromNBT(NBTTagCompound nbt) { PollutionData data = new PollutionData(); - data.soot = nbt.getFloat("soot"); - data.poison = nbt.getFloat("poison"); - data.heavyMetal = nbt.getFloat("heavyMetal"); + + for(int i = 0; i < PollutionType.values().length; i++) { + data.pollution[i] = nbt.getFloat(PollutionType.values()[i].name().toLowerCase(Locale.US)); + } + return data; } public void toNBT(NBTTagCompound nbt) { - nbt.setFloat("soot", soot); - nbt.setFloat("poison", poison); - nbt.setFloat("heavyMetal", heavyMetal); + for(int i = 0; i < PollutionType.values().length; i++) { + nbt.setFloat(PollutionType.values()[i].name().toLowerCase(Locale.US), pollution[i]); + } } } + + public static enum PollutionType { + SOOT, POISON, HEAVYMETAL, FALLOUT; + } } diff --git a/src/main/java/com/hbm/hazard/type/HazardTypeHydroactive.java b/src/main/java/com/hbm/hazard/type/HazardTypeHydroactive.java index 2a2dbb9e5..f7d6a3c49 100644 --- a/src/main/java/com/hbm/hazard/type/HazardTypeHydroactive.java +++ b/src/main/java/com/hbm/hazard/type/HazardTypeHydroactive.java @@ -6,7 +6,6 @@ import com.hbm.config.RadiationConfig; import com.hbm.hazard.modifier.HazardModifier; import com.hbm.util.I18nUtil; -import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -33,7 +32,7 @@ public class HazardTypeHydroactive extends HazardTypeBase { if(RadiationConfig.disableHydro) return; - if(item.worldObj.getBlock((int)Math.floor(item.posX), (int)Math.floor(item.posY), (int)Math.floor(item.posZ)).getMaterial() == Material.water) { + if(item.isWet()) { item.setDead(); item.worldObj.newExplosion(null, item.posX, item.posY + item.height * 0.5, item.posZ, level, false, true); } diff --git a/src/main/java/com/hbm/items/ModItems.java b/src/main/java/com/hbm/items/ModItems.java index fc5d18874..816ecdfe4 100644 --- a/src/main/java/com/hbm/items/ModItems.java +++ b/src/main/java/com/hbm/items/ModItems.java @@ -1249,6 +1249,7 @@ public class ModItems { public static Item dosimeter; public static Item geiger_counter; public static Item digamma_diagnostic; + public static Item pollution_detector; public static Item survey_scanner; public static Item mirror_tool; public static Item rbmk_tool; @@ -4575,6 +4576,7 @@ public class ModItems { dosimeter = new ItemDosimeter().setUnlocalizedName("dosimeter").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":dosimeter"); geiger_counter = new ItemGeigerCounter().setUnlocalizedName("geiger_counter").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":geiger_counter"); digamma_diagnostic = new ItemDigammaDiagnostic().setUnlocalizedName("digamma_diagnostic").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":digamma_diagnostic"); + pollution_detector = new ItemPollutionDetector().setUnlocalizedName("pollution_detector").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":pollution_detector"); survey_scanner = new ItemSurveyScanner().setUnlocalizedName("survey_scanner").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":survey_scanner"); mirror_tool = new ItemMirrorTool().setUnlocalizedName("mirror_tool").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":mirror_tool"); rbmk_tool = new ItemRBMKTool().setUnlocalizedName("rbmk_tool").setMaxStackSize(1).setCreativeTab(MainRegistry.consumableTab).setTextureName(RefStrings.MODID + ":rbmk_tool"); @@ -6725,6 +6727,7 @@ public class ModItems { GameRegistry.registerItem(dosimeter, dosimeter.getUnlocalizedName()); GameRegistry.registerItem(geiger_counter, geiger_counter.getUnlocalizedName()); GameRegistry.registerItem(digamma_diagnostic, digamma_diagnostic.getUnlocalizedName()); + GameRegistry.registerItem(pollution_detector, pollution_detector.getUnlocalizedName()); GameRegistry.registerItem(containment_box, containment_box.getUnlocalizedName()); //Keys and Locks diff --git a/src/main/java/com/hbm/items/tool/ItemPollutionDetector.java b/src/main/java/com/hbm/items/tool/ItemPollutionDetector.java new file mode 100644 index 000000000..ef45af10d --- /dev/null +++ b/src/main/java/com/hbm/items/tool/ItemPollutionDetector.java @@ -0,0 +1,32 @@ +package com.hbm.items.tool; + +import com.hbm.handler.pollution.PollutionHandler; +import com.hbm.handler.pollution.PollutionHandler.PollutionData; +import com.hbm.handler.pollution.PollutionHandler.PollutionType; +import com.hbm.packet.PacketDispatcher; +import com.hbm.packet.PlayerInformPacket; +import com.hbm.util.ChatBuilder; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; + +public class ItemPollutionDetector extends Item { + + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean bool) { + + if(!(entity instanceof EntityPlayerMP) || world.getTotalWorldTime() % 10 != 0) return; + + PollutionData data = PollutionHandler.getPollutionData(world, (int) Math.floor(entity.posX), (int) Math.floor(entity.posY), (int) Math.floor(entity.posZ)); + if(data == null) data = new PollutionData(); + + PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("Soot: " + data.pollution[PollutionType.SOOT.ordinal()]).color(EnumChatFormatting.RED).flush(), 100), (EntityPlayerMP) entity); + PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("Poison: " + data.pollution[PollutionType.POISON.ordinal()]).color(EnumChatFormatting.RED).flush(), 101), (EntityPlayerMP) entity); + PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("Heavy metal: " + data.pollution[PollutionType.HEAVYMETAL.ordinal()]).color(EnumChatFormatting.RED).flush(), 102), (EntityPlayerMP) entity); + PacketDispatcher.wrapper.sendTo(new PlayerInformPacket(ChatBuilder.start("Fallout: " + data.pollution[PollutionType.FALLOUT.ordinal()]).color(EnumChatFormatting.RED).flush(), 103), (EntityPlayerMP) entity); + } +} diff --git a/src/main/java/com/hbm/items/tool/ItemWandD.java b/src/main/java/com/hbm/items/tool/ItemWandD.java index 7ea8ad8b7..b165bae10 100644 --- a/src/main/java/com/hbm/items/tool/ItemWandD.java +++ b/src/main/java/com/hbm/items/tool/ItemWandD.java @@ -12,6 +12,8 @@ import com.hbm.explosion.vanillant.standard.BlockProcessorStandard; import com.hbm.explosion.vanillant.standard.EntityProcessorStandard; import com.hbm.explosion.vanillant.standard.ExplosionEffectStandard; import com.hbm.explosion.vanillant.standard.PlayerProcessorStandard; +import com.hbm.handler.pollution.PollutionHandler; +import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.lib.Library; import com.hbm.packet.PacketDispatcher; import com.hbm.packet.PlayerInformPacket; @@ -43,13 +45,15 @@ public class ItemWandD extends Item { if(pos != null) { - ExplosionVNT vnt = new ExplosionVNT(world, pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord, 7); + /*ExplosionVNT vnt = new ExplosionVNT(world, pos.hitVec.xCoord, pos.hitVec.yCoord, pos.hitVec.zCoord, 7); vnt.setBlockAllocator(new BlockAllocatorBulkie(60)); vnt.setBlockProcessor(new BlockProcessorStandard().withBlockEffect(new BlockMutatorBulkie(ModBlocks.block_slag)).setNoDrop()); vnt.setEntityProcessor(new EntityProcessorStandard()); vnt.setPlayerProcessor(new PlayerProcessorStandard()); vnt.setSFX(new ExplosionEffectStandard()); - vnt.explode(); + vnt.explode();*/ + + PollutionHandler.incrementPollution(world, pos.blockX, pos.blockY, pos.blockZ, PollutionType.SOOT, 15); /*TimeAnalyzer.startCount("setBlock"); world.setBlock(pos.blockX, pos.blockY, pos.blockZ, Blocks.dirt); diff --git a/src/main/resources/assets/hbm/textures/items/pollution_detector.png b/src/main/resources/assets/hbm/textures/items/pollution_detector.png new file mode 100644 index 0000000000000000000000000000000000000000..b926f8086389a911a67c40c5028aa3f7c47a2d86 GIT binary patch literal 241 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf