Skip to content

Commit

Permalink
Fix underground fluid prospecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann Bernhardt committed Nov 30, 2021
1 parent fc869c5 commit d1a71d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 58 deletions.
57 changes: 0 additions & 57 deletions src/main/java/com/sinthoras/visualprospecting/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,61 +220,4 @@ public static Map<Integer, ByteBuffer> getDIMFiles(File directory) {
return new HashMap<>();
}
}

// Rewrite from GT_UndergroundOil.undergroundOil(Chunk chunk, float readOrDrainCoefficient),
// because there is no reason to require a chunk to be loaded
public static FluidStack prospectFluid(World world, int chunkX, int chunkZ) {
final ChunkCoordIntPair chunkCoordinate = new ChunkCoordIntPair(chunkX, chunkZ);
int dimensionId = world.provider.dimensionId;
GT_UO_Dimension dimension = GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(dimensionId);
if (dimension == null) {
return null;
}

Map<ChunkCoordIntPair, int[]> chunkData = dimensionWiseChunkData.computeIfAbsent(dimensionId, k -> new HashMap<>(1024));

int[] tInts = chunkData.get(chunkCoordinate);

if (tInts == null) {
tInts = getDefaultChunkDataOnCreation();
}
else if (tInts[GTOIL] == 0) {
return new FluidStack(FluidRegistry.getFluid(tInts[GTOILFLUID]), 0);
}

final XSTR tRandom = new XSTR(world.getSeed() + dimensionId * 2L + (chunkX >> 3) + 8267L * (chunkZ >> 3));

GT_UO_Fluid uoFluid = dimension.getRandomFluid(tRandom);

FluidStack fluidInChunk;

if (uoFluid == null || uoFluid.getFluid() == null) {
tInts[GTOILFLUID] = Integer.MAX_VALUE;//null fluid pointer... kind of
tInts[GTOIL] = 0;
chunkData.put(chunkCoordinate, 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));
fluidInChunk.amount = (int) ((float) fluidInChunk.amount * (0.75f + (XSTR_INSTANCE.nextFloat() / 2f)));//Randomly change amounts by +/- 25%
}
tInts[GTOIL] = fluidInChunk.amount;
tInts[GTOILFLUID] = fluidInChunk.getFluidID();
}

if (fluidInChunk.amount <= GT_UndergroundOil.DIVIDER) {
fluidInChunk.amount = 0;//return informative stack
tInts[GTOIL] = 0;//so in next access it will stop way above
}
else {
fluidInChunk.amount = fluidInChunk.amount / GT_UndergroundOil.DIVIDER;//give moderate extraction speed
}

chunkData.put(chunkCoordinate, tInts);//update hash map
return fluidInChunk;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.ArrayList;
import java.util.List;

import static gregtech.common.GT_UndergroundOil.undergroundOil;

public class ServerCache extends WorldCache {

public static final ServerCache instance = new ServerCache();
Expand Down Expand Up @@ -78,7 +80,7 @@ public List<UndergroundFluidPosition> prospectUndergroundFluidBlockRadius(World
Fluid fluid = null;
for (int offsetChunkX = 0; offsetChunkX < VP.undergroundFluidSizeChunkX; offsetChunkX++) {
for (int offsetChunkZ = 0; offsetChunkZ < VP.undergroundFluidSizeChunkZ; offsetChunkZ++) {
final FluidStack prospectedFluid = Utils.prospectFluid(world, chunkX + offsetChunkX, chunkZ + offsetChunkZ);
final FluidStack prospectedFluid = undergroundOil(world, chunkX + offsetChunkX, chunkZ + offsetChunkZ, -1);
if (prospectedFluid != null) {
fluid = prospectedFluid.getFluid();
chunks[offsetChunkX][offsetChunkZ] = prospectedFluid.amount;
Expand Down

0 comments on commit d1a71d0

Please sign in to comment.