Saving pumped oil amounts in chunk NBTs
This commit is contained in:
parent
66427b2178
commit
aeb505273b
2 changed files with 44 additions and 2 deletions
|
@ -5,6 +5,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import gregtech.api.GregTech_API;
|
import gregtech.api.GregTech_API;
|
||||||
import gregtech.api.damagesources.GT_DamageSources;
|
import gregtech.api.damagesources.GT_DamageSources;
|
||||||
import gregtech.api.enchants.Enchantment_Radioactivity;
|
import gregtech.api.enchants.Enchantment_Radioactivity;
|
||||||
|
import gregtech.api.enums.GT_Values;
|
||||||
import gregtech.api.enums.ItemList;
|
import gregtech.api.enums.ItemList;
|
||||||
import gregtech.api.enums.Materials;
|
import gregtech.api.enums.Materials;
|
||||||
import gregtech.api.enums.SubTag;
|
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.GT_ItemStack;
|
||||||
import gregtech.api.objects.ItemData;
|
import gregtech.api.objects.ItemData;
|
||||||
import gregtech.api.threads.GT_Runnable_Sound;
|
import gregtech.api.threads.GT_Runnable_Sound;
|
||||||
|
import gregtech.common.GT_Proxy;
|
||||||
import ic2.api.recipe.IRecipeInput;
|
import ic2.api.recipe.IRecipeInput;
|
||||||
import ic2.api.recipe.RecipeInputItemStack;
|
import ic2.api.recipe.RecipeInputItemStack;
|
||||||
import ic2.api.recipe.RecipeInputOreDict;
|
import ic2.api.recipe.RecipeInputOreDict;
|
||||||
|
@ -50,6 +52,7 @@ import net.minecraft.tileentity.TileEntityChest;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
|
import net.minecraft.world.ChunkPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraftforge.common.DimensionManager;
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
@ -1476,6 +1479,8 @@ public class GT_Utility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FluidStack getUndergroundOil(World aWorld, int aX, int aZ) {
|
public static FluidStack getUndergroundOil(World aWorld, int aX, int aZ) {
|
||||||
|
|
||||||
|
|
||||||
Random tRandom = new Random((aWorld.getSeed() + (aX / 96) + (7 * (aZ / 96))));
|
Random tRandom = new Random((aWorld.getSeed() + (aX / 96) + (7 * (aZ / 96))));
|
||||||
int oil = tRandom.nextInt(3);
|
int oil = tRandom.nextInt(3);
|
||||||
double amount = tRandom.nextInt(50) + tRandom.nextDouble();
|
double amount = tRandom.nextInt(50) + tRandom.nextDouble();
|
||||||
|
@ -1498,7 +1503,19 @@ public class GT_Utility {
|
||||||
default:
|
default:
|
||||||
tFluid = Materials.Oil.mFluid;
|
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<String> aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) {
|
public static int getCoordinateScan(ArrayList<String> 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 (D1) e.printStackTrace(GT_Log.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (aPlayer.capabilities.isCreativeMode) {
|
if (aPlayer.capabilities.isCreativeMode&>_Values.D1) {
|
||||||
FluidStack tFluid = getUndergroundOil(aWorld, aX, aZ);
|
FluidStack tFluid = getUndergroundOil(aWorld, aX, aZ);
|
||||||
tList.add("Oil in Chunk: " + tFluid.amount + " " + tFluid.getLocalizedName());
|
tList.add("Oil in Chunk: " + tFluid.amount + " " + tFluid.getLocalizedName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.potion.Potion;
|
import net.minecraft.potion.Potion;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
|
import net.minecraft.world.ChunkPosition;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldSettings.GameType;
|
import net.minecraft.world.WorldSettings.GameType;
|
||||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
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.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.event.terraingen.OreGenEvent;
|
import net.minecraftforge.event.terraingen.OreGenEvent;
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
|
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
|
@ -1827,6 +1829,29 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
|
||||||
tEvent = (OreDictEventContainer) i$.next();
|
tEvent = (OreDictEventContainer) i$.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final HashMap<ChunkPosition, int[]> chunkData = new HashMap<ChunkPosition, int[]>(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 static class OreDictEventContainer {
|
||||||
public final OreDictionary.OreRegisterEvent mEvent;
|
public final OreDictionary.OreRegisterEvent mEvent;
|
||||||
|
|
Loading…
Reference in a new issue