aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/GT_UndergroundOil.java
diff options
context:
space:
mode:
authorJohannes Gäßler <updrn@student.kit.edu>2017-06-15 12:28:14 +0200
committerJohannes Gäßler <updrn@student.kit.edu>2017-06-15 12:28:14 +0200
commit34474480f73ca5ab1c711d73bdb4bd809673e063 (patch)
tree794ef12002b88e2f01b5f6d76c9c1f9b62a48961 /src/main/java/gregtech/common/GT_UndergroundOil.java
parentc3f2b2b49dc3911a377fd062908d4df78bd3e58d (diff)
parent08c75fd813a4b48ba7a6b58391767161791c96e7 (diff)
downloadGT5-Unofficial-34474480f73ca5ab1c711d73bdb4bd809673e063.tar.gz
GT5-Unofficial-34474480f73ca5ab1c711d73bdb4bd809673e063.tar.bz2
GT5-Unofficial-34474480f73ca5ab1c711d73bdb4bd809673e063.zip
Merge remote-tracking branch 'origin/unstable' into ChemistryUpdate
Conflicts: src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Cleanroom.java src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeBoiler.java src/main/java/gregtech/loaders/load/GT_FuelLoader.java src/main/java/gregtech/loaders/preload/GT_Loader_MetaTileEntities.java src/main/java/gregtech/nei/GT_NEI_DefaultHandler.java
Diffstat (limited to 'src/main/java/gregtech/common/GT_UndergroundOil.java')
-rw-r--r--src/main/java/gregtech/common/GT_UndergroundOil.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/main/java/gregtech/common/GT_UndergroundOil.java b/src/main/java/gregtech/common/GT_UndergroundOil.java
new file mode 100644
index 0000000000..a3e0962100
--- /dev/null
+++ b/src/main/java/gregtech/common/GT_UndergroundOil.java
@@ -0,0 +1,100 @@
+package gregtech.common;
+
+import gregtech.GT_Mod;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.objects.GT_UO_Fluid;
+import gregtech.api.objects.XSTR;
+import gregtech.common.GT_Proxy;
+import net.minecraft.world.ChunkCoordIntPair;
+import net.minecraft.world.ChunkPosition;
+import net.minecraft.world.World;
+import net.minecraft.world.chunk.Chunk;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidRegistry;
+import net.minecraftforge.fluids.FluidStack;
+
+import java.util.HashMap;
+
+import static gregtech.api.util.GT_Utility.getScaleCoordinates;
+import static gregtech.common.GT_Proxy.*;
+
+/**
+ * Created by Tec on 29.04.2017.
+ */
+public class GT_UndergroundOil {
+ public static final short DIVIDER=5000;
+
+ public static FluidStack undergroundOil(IGregTechTileEntity te, float drainSpeedCoefficient){
+ return undergroundOil(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()),drainSpeedCoefficient);
+ }
+
+ //Returns whole content for information purposes -> when drainSpeedCoeff < 0
+ //Else returns extracted fluidStack if amount > 0, or null otherwise
+ public static FluidStack undergroundOil(Chunk chunk, float drainSpeedCoefficient) {
+ if (GT_Mod.gregtechproxy.mUndergroundOil.CheckBlackList(chunk.worldObj.provider.dimensionId)) return null;
+ World aWorld = chunk.worldObj;
+
+ //Read hash map
+ HashMap<ChunkCoordIntPair, int[]> chunkData = dimensionWiseChunkData.get(aWorld.provider.dimensionId);
+ if(chunkData==null){
+ chunkData=new HashMap<>(1024);
+ dimensionWiseChunkData.put(aWorld.provider.dimensionId,chunkData);
+ }
+
+ int[] tInts = chunkData.get(chunk.getChunkCoordIntPair());
+
+ if(tInts==null) tInts=getDefaultChunkDataOnCreation();//init if null
+ else if(tInts[GTOIL]==0){//FAST stop
+ //can return 0 amount stack for info :D
+ return drainSpeedCoefficient>=0 ? null : new FluidStack(FluidRegistry.getFluid(tInts[GTOILFLUID]),0);
+ }
+
+ //GEN IT TO GET OBJECT...
+ XSTR tRandom = new XSTR(aWorld.getSeed() + aWorld.provider.dimensionId * 2 +
+ (chunk.getChunkCoordIntPair().chunkXPos>>3) +
+ 8267 * (chunk.getChunkCoordIntPair().chunkZPos>>3));
+ GT_UO_Fluid uoFluid = GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(aWorld.provider.dimensionId).getRandomFluid(tRandom);
+
+ //Fluid stack holder
+ FluidStack fluidInChunk;
+
+ //Set fluidstack from uoFluid
+ if (uoFluid == null || uoFluid.getFluid()==null){
+ tInts[GTOILFLUID]=Integer.MAX_VALUE;//null fluid pointer... kindof
+ tInts[GTOIL]=0;
+ chunkData.put(chunk.getChunkCoordIntPair(),tInts);//update hash map
+ return null;
+ } else {
+ if(tInts[GTOILFLUID]== uoFluid.getFluid().getID()){//if stored fluid matches uoFluid
+ fluidInChunk = new FluidStack(uoFluid.getFluid(),tInts[GTOIL]);
+ }else{
+ fluidInChunk = new FluidStack(uoFluid.getFluid(), uoFluid.getRandomAmount(tRandom));
+ tRandom=new XSTR();
+ fluidInChunk.amount=(int)((float)fluidInChunk.amount*(0.75f+(tRandom.nextFloat()/2f)));//Randomly change amounts by +/- 25%
+ }
+ tInts[GTOIL]=fluidInChunk.amount;
+ tInts[GTOILFLUID]=fluidInChunk.getFluidID();
+ }
+
+ //do stuff on it if needed
+ if(drainSpeedCoefficient>=0){
+ if(fluidInChunk.amount<DIVIDER){
+ fluidInChunk=null;
+ tInts[GTOIL]=0;//so in next access it will stop way above
+ }else{
+ fluidInChunk.amount = (int)(fluidInChunk.amount*(double)drainSpeedCoefficient/DIVIDER);//give appropriate amount
+ tInts[GTOIL]-=uoFluid.DecreasePerOperationAmount;//diminish amount
+ }
+ }else{//just get info
+ if(fluidInChunk.amount<DIVIDER){
+ fluidInChunk.amount=0;//return informative stack
+ tInts[GTOIL]=0;//so in next access it will stop way above
+ }else{
+ fluidInChunk.amount=fluidInChunk.amount/DIVIDER;//give moderate extraction speed
+ }
+ }
+
+ chunkData.put(chunk.getChunkCoordIntPair(),tInts);//update hash map
+ return fluidInChunk;
+ }
+}