Updated portal position code

This commit is contained in:
paulevsGitch 2021-11-30 13:55:21 +03:00
parent 5386d2e0f2
commit 1448336709
5 changed files with 70 additions and 67 deletions

View file

@ -64,14 +64,11 @@ public class EndDragonFightMixin {
else { else {
LOGGER.debug("Found the exit portal & temporarily using it."); LOGGER.debug("Found the exit portal & temporarily using it.");
} }
blockPos = portalLocation;
} }
List<EndCrystal> crystals = Lists.newArrayList(); List<EndCrystal> crystals = Lists.newArrayList();
BlockPos center = GeneratorOptions.getPortalPos().above(5);
for (Direction dir : BlocksHelper.HORIZONTAL) { for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos central = center.relative(dir, 4); BlockPos central = BlockPos.ZERO.relative(dir, 4);
List<EndCrystal> crystalList = level.getEntitiesOfClass( List<EndCrystal> crystalList = level.getEntitiesOfClass(
EndCrystal.class, EndCrystal.class,
new AABB(central.below(255).south().west(), central.above(255).north().east()) new AABB(central.below(255).south().west(), central.above(255).north().east())

View file

@ -2,9 +2,9 @@ package ru.betterend.mixin.common;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils; import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.feature.EndPodiumFeature; import net.minecraft.world.level.levelgen.feature.EndPodiumFeature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
@ -27,6 +27,8 @@ import java.util.Random;
@Mixin(EndPodiumFeature.class) @Mixin(EndPodiumFeature.class)
public class EndPodiumFeatureMixin { public class EndPodiumFeatureMixin {
private static BlockPos be_portalPosition;
@Final @Final
@Shadow @Shadow
private boolean active; private boolean active;
@ -40,10 +42,10 @@ public class EndPodiumFeatureMixin {
else if (GeneratorOptions.replacePortal()) { else if (GeneratorOptions.replacePortal()) {
Random random = featurePlaceContext.random(); Random random = featurePlaceContext.random();
WorldGenLevel world = featurePlaceContext.level(); WorldGenLevel world = featurePlaceContext.level();
BlockPos blockPos = be_updatePos(featurePlaceContext.origin(), world); BlockPos blockPos = be_updatePortalPos(world);
StructureTemplate structure = StructureHelper.readStructure(BetterEnd.makeID(active ? "portal/end_portal_active" : "portal/end_portal_inactive")); StructureTemplate structure = StructureHelper.readStructure(BetterEnd.makeID(active ? "portal/end_portal_active" : "portal/end_portal_inactive"));
Vec3i size = structure.getSize(); Vec3i size = structure.getSize();
blockPos = blockPos.offset(-(size.getX() >> 1), -1, -(size.getZ() >> 1)); blockPos = blockPos.offset(-(size.getX() >> 1), -3, -(size.getZ() >> 1));
structure.placeInWorld(world, blockPos, blockPos, new StructurePlaceSettings(), random, 2); structure.placeInWorld(world, blockPos, blockPos, new StructurePlaceSettings(), random, 2);
info.setReturnValue(true); info.setReturnValue(true);
info.cancel(); info.cancel();
@ -53,8 +55,8 @@ public class EndPodiumFeatureMixin {
@ModifyVariable(method = "place", ordinal = 0, at = @At("HEAD")) @ModifyVariable(method = "place", ordinal = 0, at = @At("HEAD"))
private FeaturePlaceContext<NoneFeatureConfiguration> be_setPosOnGround(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) { private FeaturePlaceContext<NoneFeatureConfiguration> be_setPosOnGround(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
WorldGenLevel world = featurePlaceContext.level(); WorldGenLevel world = featurePlaceContext.level();
BlockPos pos = be_updatePos(featurePlaceContext.origin(), world); BlockPos pos = be_updatePortalPos(world);
return new FeaturePlaceContext<NoneFeatureConfiguration>( return new FeaturePlaceContext<>(
world, world,
featurePlaceContext.chunkGenerator(), featurePlaceContext.chunkGenerator(),
featurePlaceContext.random(), featurePlaceContext.random(),
@ -63,21 +65,24 @@ public class EndPodiumFeatureMixin {
); );
} }
private BlockPos be_updatePos(BlockPos blockPos, WorldGenLevel world) { private BlockPos be_updatePortalPos(WorldGenLevel world) {
if (GeneratorOptions.useNewGenerator()) { CompoundTag compound = WorldDataAPI.getRootTag(BetterEnd.MOD_ID).getCompound("portal");
BlockPos pos = GeneratorOptions.getPortalPos(); be_portalPosition = NbtUtils.readBlockPos(compound);
if (pos.equals(BlockPos.ZERO)) {
int y = world.getChunk(0, 0, ChunkStatus.FULL).getHeight(Types.WORLD_SURFACE, blockPos.getX(), blockPos.getZ()); if (be_portalPosition.getY() == 0) {
if (y < 1) { /*if (GeneratorOptions.useNewGenerator()) {
y = 65; int y = TerrainGenerator.getHeight(0, 0, world.getLevel().getChunkSource().getGenerator().getBiomeSource());
} be_portalPosition = new BlockPos(0, y, 0);
pos = new BlockPos(pos.getX(), y, pos.getZ());
GeneratorOptions.setPortalPos(pos);
WorldDataAPI.getRootTag(BetterEnd.MOD_ID).put("portal", NbtUtils.writeBlockPos(pos));
WorldDataAPI.saveFile(BetterEnd.MOD_ID);
} }
return pos; else {
be_portalPosition = new BlockPos(0, 65, 0);
}*/
int y = world.getHeight(Types.WORLD_SURFACE, 0, 0);
be_portalPosition = new BlockPos(0, y, 0);
WorldDataAPI.getRootTag(BetterEnd.MOD_ID).put("portal", NbtUtils.writeBlockPos(be_portalPosition));
WorldDataAPI.saveFile(BetterEnd.MOD_ID);
} }
return blockPos;
return be_portalPosition;
} }
} }

View file

@ -52,8 +52,7 @@ public class SpikeFeatureMixin {
String pillarID = String.format("%d_%d", x, z); String pillarID = String.format("%d_%d", x, z);
CompoundTag pillar = WorldDataAPI.getCompoundTag(BetterEnd.MOD_ID, "pillars"); CompoundTag pillar = WorldDataAPI.getCompoundTag(BetterEnd.MOD_ID, "pillars");
boolean haveValue = pillar.contains(pillarID); boolean haveValue = pillar.contains(pillarID);
minY = haveValue ? pillar.getInt(pillarID) : world.getChunk(x >> 4, z >> 4) minY = haveValue ? pillar.getInt(pillarID) : world.getChunk(x >> 4, z >> 4).getHeight(Types.WORLD_SURFACE, x & 15, z);
.getHeight(Types.WORLD_SURFACE, x & 15, z);
if (!haveValue) { if (!haveValue) {
pillar.putInt(pillarID, minY); pillar.putInt(pillarID, minY);
WorldDataAPI.saveFile(BetterEnd.MOD_ID); WorldDataAPI.saveFile(BetterEnd.MOD_ID);

View file

@ -20,7 +20,6 @@ public class GeneratorOptions {
public static LayerOptions smallOptions; public static LayerOptions smallOptions;
private static boolean changeSpawn; private static boolean changeSpawn;
private static BlockPos spawn; private static BlockPos spawn;
private static BlockPos portal = BlockPos.ZERO;
private static boolean replacePortal; private static boolean replacePortal;
private static boolean replacePillars; private static boolean replacePillars;
private static long islandDistBlock; private static long islandDistBlock;
@ -130,14 +129,6 @@ public class GeneratorOptions {
return spawn; return spawn;
} }
public static BlockPos getPortalPos() {
return portal;
}
public static void setPortalPos(BlockPos portal) {
GeneratorOptions.portal = portal;
}
public static boolean replacePortal() { public static boolean replacePortal() {
return replacePortal; return replacePortal;
} }

View file

@ -173,45 +173,56 @@ public class TerrainGenerator {
* @param x - block pos x * @param x - block pos x
* @param z - block pos z * @param z - block pos z
*/ */
public static int getHeight(int x, int z) { public static int getHeight(int x, int z, BiomeSource biomeSource) {
int posX = (x >> 3) << 3;
int posZ = (z >> 3) << 3;
float dx = (x - posX) / 8.0F;
float dz = (z - posZ) / 8.0F;
double[][][] buffer = new double[2][2][32];
LOCKER.lock(); LOCKER.lock();
for (int i = 0; i < 4; i++) {
int ix = i & 1;
int iz = i >> 1;
int px = ((ix << 3) + posX) >> 3;
int pz = ((iz << 3) + posZ) >> 3;
fillTerrainDensity(buffer[ix][iz], px, pz, biomeSource);
}
LOCKER.unlock();
double px = (double) x / 8.0; for (int j = 30; j >= 0; j--) {
double pz = (double) z / 8.0; float a = (float) buffer[0][0][j];
float b = (float) buffer[1][0][j];
double distortion1 = noise1.eval(px * 0.1, pz * 0.1) * 20 + noise2.eval(px * 0.2, pz * 0.2) * 10 + noise1.eval( float c = (float) buffer[0][1][j];
px * 0.4, float d = (float) buffer[1][1][j];
pz * 0.4
) * 5; float e = (float) buffer[0][0][j + 1];
double distortion2 = noise2.eval(px * 0.1, pz * 0.1) * 20 + noise1.eval(px * 0.2, pz * 0.2) * 10 + noise2.eval( float f = (float) buffer[1][0][j + 1];
px * 0.4, float g = (float) buffer[0][1][j + 1];
pz * 0.4 float h = (float) buffer[1][1][j + 1];
) * 5;
px = (double) x * SCALE_XZ + distortion1; if (a < 0 && b < 0 && c < 0 && d < 0 && e < 0 && f < 0 && g < 0 && h < 0) {
pz = (double) z * SCALE_XZ + distortion2; continue;
largeIslands.updatePositions(px, pz);
mediumIslands.updatePositions(px, pz);
smallIslands.updatePositions(px, pz);
for (int y = 32; y >= 0; y--) {
double py = (double) y * SCALE_Y;
float dist = largeIslands.getDensity(px, py, pz);
dist = dist > 1 ? dist : MHelper.max(dist, mediumIslands.getDensity(px, py, pz));
dist = dist > 1 ? dist : MHelper.max(dist, smallIslands.getDensity(px, py, pz));
if (dist > -0.5F) {
dist += noise1.eval(px * 0.01, py * 0.01, pz * 0.01) * 0.02 + 0.02;
dist += noise2.eval(px * 0.05, py * 0.05, pz * 0.05) * 0.01 + 0.01;
dist += noise1.eval(px * 0.1, py * 0.1, pz * 0.1) * 0.005 + 0.005;
} }
if (dist > 0) {
LOCKER.unlock(); a = Mth.lerp(dx, a, b);
return Mth.floor(Mth.clamp(y + dist, y, y + 1) * SCALE_Y); b = Mth.lerp(dx, c, d);
c = Mth.lerp(dx, e, f);
d = Mth.lerp(dx, g, h);
a = Mth.lerp(dz, a, b);
b = Mth.lerp(dz, c, d);
for (int n = 7; n >= 0; n--) {
float dy = n / 8.0F;
float dens = Mth.lerp(dy, a, b);
if (dens > 0) {
return (j << 3 | n) + 1;
}
} }
} }
LOCKER.unlock(); return -256;
return 0;
} }
static { static {