diff options
author | Martin Robertz <dream-master@gmx.net> | 2021-11-21 12:00:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-21 12:00:00 +0100 |
commit | 81f0b4801dfb0bd2d2a863e7a60f27af0daba463 (patch) | |
tree | 5b7717983e0f53f94c1c67cb6d2186f452bb7e69 | |
parent | 9dbb981b74002c01e9c38cb2716f918597ccf9ea (diff) | |
parent | 913379a51c0f808ca0e38f38b66af43f2b8ebb0c (diff) | |
download | GT5-Unofficial-81f0b4801dfb0bd2d2a863e7a60f27af0daba463.tar.gz GT5-Unofficial-81f0b4801dfb0bd2d2a863e7a60f27af0daba463.tar.bz2 GT5-Unofficial-81f0b4801dfb0bd2d2a863e7a60f27af0daba463.zip |
Merge pull request #747 from GTNewHorizons/patch-uo
Ensure UO is generated in a consistent way instead of depending on positions of stars and stuff
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | build.gradle | 3 | ||||
-rw-r--r-- | src/main/java/gregtech/common/GT_UndergroundOil.java | 35 |
3 files changed, 30 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore index 3beafd6561..9b4674ed8f 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,7 @@ libs/ *.errored /build/ /run + +# Generated sources + +src/main/generated diff --git a/build.gradle b/build.gradle index 5f4aad8103..4505a0218d 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ buildscript { } } dependencies { - classpath 'com.github.GTNH2:ForgeGradle:FG_1.2-SNAPSHOT' + classpath 'com.github.GTNewHorizons:ForgeGradle:stable-2021-11-20' } } @@ -111,7 +111,6 @@ dependencies { compileOnly 'commons-io:commons-io:2.4' compileOnly 'com.google.auto.value:auto-value-annotations:1.8.2' annotationProcessor 'com.google.auto.value:auto-value:1.8.2' - compileOnly "eu.usrv:YAMCore:${config.minecraft.version}-${config.yamcore.version}:deobf" compileOnly "tconstruct:TConstruct:${config.minecraft.version}-${config.tconstruct.version}:deobf" compileOnly "codechicken:Translocator:${config.minecraft.version}-${config.translocators.version}:dev" compileOnly "net.sengir.forestry:forestry_${config.minecraft.version}:${config.forestry.version}:dev" diff --git a/src/main/java/gregtech/common/GT_UndergroundOil.java b/src/main/java/gregtech/common/GT_UndergroundOil.java index 11bbd6431b..21b681de4a 100644 --- a/src/main/java/gregtech/common/GT_UndergroundOil.java +++ b/src/main/java/gregtech/common/GT_UndergroundOil.java @@ -11,6 +11,7 @@ import net.minecraft.world.chunk.Chunk; import net.minecraftforge.event.world.ChunkDataEvent; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.tuple.Pair; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @@ -28,6 +29,7 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE; public class GT_UndergroundOil { public static final short DIVIDER=5000; private static final GT_UndergroundOilStore STORAGE = new GT_UndergroundOilStore(); + private static final ChunkData NIL_FLUID_STACK = new ChunkData(-1, null, null, false); public static FluidStack undergroundOilReadInformation(IGregTechTileEntity te){ return undergroundOil(te.getWorld().getChunkFromBlockCoords(te.getXCoord(),te.getZCoord()),-1); @@ -76,6 +78,25 @@ public class GT_UndergroundOil { return fluidInChunk; } + /** + * Get the deposit as if it is never exploited + * @return UO fluid kind and amount, or null if nothing here. + */ + public static Pair<GT_UO_Fluid, Integer> getPristineAmount(World world, int chunkX, int chunkZ) { + int dimensionId = world.provider.dimensionId; + GT_UO_Dimension dimension = GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(dimensionId); + if (dimension == null) return null; + // prepare RNG 🙏 🙏 🙏 + final XSTR tVeinRNG = new XSTR(world.getSeed() + dimensionId * 2L + (chunkX >> 3) + 8267L * (chunkZ >> 3)); + final XSTR tChunkRNG = new XSTR(world.getSeed() + dimensionId * 2L + chunkX + 8267L * chunkZ); + GT_UO_Fluid uoFluid = dimension.getRandomFluid(tVeinRNG); + // nothing here :( + if (uoFluid == null || uoFluid.getFluid() == null) return null; + // offset each chunk's fluid amount by +-25% + int amount = (int) ((float) uoFluid.getRandomAmount(tVeinRNG) * (0.75f + (tChunkRNG.nextFloat() / 2f))); + return Pair.of(uoFluid, amount); + } + static void migrate(ChunkDataEvent.Load e) { if (e.getData().hasKey("GTOIL") && e.getData().hasKey("GTOILFLUID")) { ChunkData chunkData = STORAGE.get(e.getChunk()); @@ -114,7 +135,6 @@ public class GT_UndergroundOil { */ @ParametersAreNonnullByDefault private static class GT_UndergroundOilStore extends GT_ChunkAssociatedData<ChunkData> { - private static final GT_UndergroundOil.ChunkData NIL_FLUID_STACK = new GT_UndergroundOil.ChunkData(-1, null, null, false); private static final WeakHashMap<GT_UO_Fluid, Integer> hashes = new WeakHashMap<>(); private GT_UndergroundOilStore() { @@ -154,17 +174,12 @@ public class GT_UndergroundOil { @Override protected GT_UndergroundOil.ChunkData createElement(World world, int chunkX, int chunkZ) { + Pair<GT_UO_Fluid, Integer> pristine = getPristineAmount(world, chunkX, chunkZ); + if (pristine == null) + return NIL_FLUID_STACK; int dimensionId = world.provider.dimensionId; GT_UO_Dimension dimension = GT_Mod.gregtechproxy.mUndergroundOil.GetDimension(dimensionId); - if (dimension == null) return NIL_FLUID_STACK; - // prepare RNG 🙏 🙏 🙏 - final XSTR tRandom = new XSTR(world.getSeed() + dimensionId * 2L + (chunkX >> 3) + 8267L * (chunkZ >> 3)); - GT_UO_Fluid uoFluid = dimension.getRandomFluid(tRandom); - // nothing here :( - if (uoFluid == null || uoFluid.getFluid() == null) return NIL_FLUID_STACK; - // offset each chunk's fluid amount by +-25% - int amount = (int) ((float) uoFluid.getRandomAmount(tRandom) * (0.75f + (XSTR_INSTANCE.nextFloat() / 2f))); - return new GT_UndergroundOil.ChunkData(amount, uoFluid, dimension.getUOFluidKey(uoFluid), false); + return new GT_UndergroundOil.ChunkData(pristine.getRight(), pristine.getLeft(), dimension.getUOFluidKey(pristine.getLeft()), false); } private static int hash(@Nullable GT_UO_Fluid fluid) { |