From aeb505273bc378b0d85c439fcc0ac6ea4e4d04f9 Mon Sep 17 00:00:00 2001 From: Blood-Asp Date: Sun, 6 Dec 2015 21:15:41 +0100 Subject: [PATCH] Saving pumped oil amounts in chunk NBTs --- .../java/gregtech/api/util/GT_Utility.java | 21 ++++++++++++++-- src/main/java/gregtech/common/GT_Proxy.java | 25 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index a208042f..766f3b6b 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -5,6 +5,7 @@ import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.enchants.Enchantment_Radioactivity; +import gregtech.api.enums.GT_Values; import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.SubTag; @@ -18,6 +19,7 @@ import gregtech.api.net.GT_Packet_Sound; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.ItemData; import gregtech.api.threads.GT_Runnable_Sound; +import gregtech.common.GT_Proxy; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; import ic2.api.recipe.RecipeInputOreDict; @@ -50,6 +52,7 @@ import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; import net.minecraft.util.MathHelper; +import net.minecraft.world.ChunkPosition; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; @@ -1476,6 +1479,8 @@ public class GT_Utility { } public static FluidStack getUndergroundOil(World aWorld, int aX, int aZ) { + + Random tRandom = new Random((aWorld.getSeed() + (aX / 96) + (7 * (aZ / 96)))); int oil = tRandom.nextInt(3); double amount = tRandom.nextInt(50) + tRandom.nextDouble(); @@ -1498,7 +1503,19 @@ public class GT_Utility { default: tFluid = Materials.Oil.mFluid; } - return new FluidStack(tFluid, (int) (Math.pow(amount, 5) / 100)); + int tAmount = (int) (Math.pow(amount, 5) / 100); + ChunkPosition tPos = new ChunkPosition(aX/16, 1, aZ/16); + if(GT_Proxy.chunkData.containsKey(tPos)){ + int[] tInts = GT_Proxy.chunkData.get(tPos); + if(tInts.length>0){ + if(tInts[0]>=0){tAmount = tInts[0];} + } + GT_Proxy.chunkData.remove(tPos); + } + tAmount = tAmount - 5; + GT_Proxy.chunkData.put(tPos, new int[]{tAmount}); + + return new FluidStack(tFluid, tAmount); } public static int getCoordinateScan(ArrayList aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) { @@ -1688,7 +1705,7 @@ public class GT_Utility { if (D1) e.printStackTrace(GT_Log.err); } } - if (aPlayer.capabilities.isCreativeMode) { + if (aPlayer.capabilities.isCreativeMode&>_Values.D1) { FluidStack tFluid = getUndergroundOil(aWorld, aX, aZ); tList.add("Oil in Chunk: " + tFluid.amount + " " + tFluid.getLocalizedName()); } diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java index 0cf7c33a..fc68cd11 100644 --- a/src/main/java/gregtech/common/GT_Proxy.java +++ b/src/main/java/gregtech/common/GT_Proxy.java @@ -48,6 +48,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.DamageSource; +import net.minecraft.world.ChunkPosition; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; import net.minecraft.world.gen.feature.WorldGenMinable; @@ -60,6 +61,7 @@ import net.minecraftforge.event.entity.player.ArrowNockEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.terraingen.OreGenEvent; import net.minecraftforge.event.world.BlockEvent; +import net.minecraftforge.event.world.ChunkDataEvent; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; @@ -1827,6 +1829,29 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler { tEvent = (OreDictEventContainer) i$.next(); } } + + public static final HashMap chunkData = new HashMap(5000); + + @SubscribeEvent + public void handleChunkSaveEvent(ChunkDataEvent.Save event) + { + ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition); + if(chunkData.containsKey(tPos)){ + int[] tInts = chunkData.get(tPos); + if(tInts.length>0){event.getData().setInteger("GTOIL", tInts[0]);}} + } + + @SubscribeEvent + public void handleChunkLoadEvent(ChunkDataEvent.Load event) + { + int tOil = -1; + if(event.getData().hasKey("GTOIL")){ + tOil = event.getData().getInteger("GTOIL");} + ChunkPosition tPos = new ChunkPosition(event.getChunk().xPosition,1,event.getChunk().zPosition); + if(chunkData.containsKey(tPos)){ + chunkData.remove(tPos);} + chunkData.put(tPos, new int[]{ tOil}); + } public static class OreDictEventContainer { public final OreDictionary.OreRegisterEvent mEvent;