fixes, some more pollution stuff

This commit is contained in:
Boblet 2023-06-05 16:39:05 +02:00
parent ff473c51da
commit 685412473e
7 changed files with 133 additions and 17 deletions

View File

@ -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
## Fixed
* Fixed hydroreactive stat not applying when an item is dropped in the rain

View File

@ -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<World, PollutionPerWorld> 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<ChunkCoordIntPair, PollutionData> 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;
}
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B