Updated portal position code
This commit is contained in:
parent
5386d2e0f2
commit
1448336709
5 changed files with 70 additions and 67 deletions
|
@ -2,9 +2,9 @@ package ru.betterend.mixin.common;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
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.feature.EndPodiumFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
|
||||
|
@ -27,6 +27,8 @@ import java.util.Random;
|
|||
|
||||
@Mixin(EndPodiumFeature.class)
|
||||
public class EndPodiumFeatureMixin {
|
||||
private static BlockPos be_portalPosition;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
private boolean active;
|
||||
|
@ -40,10 +42,10 @@ public class EndPodiumFeatureMixin {
|
|||
else if (GeneratorOptions.replacePortal()) {
|
||||
Random random = featurePlaceContext.random();
|
||||
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"));
|
||||
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);
|
||||
info.setReturnValue(true);
|
||||
info.cancel();
|
||||
|
@ -53,8 +55,8 @@ public class EndPodiumFeatureMixin {
|
|||
@ModifyVariable(method = "place", ordinal = 0, at = @At("HEAD"))
|
||||
private FeaturePlaceContext<NoneFeatureConfiguration> be_setPosOnGround(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
|
||||
WorldGenLevel world = featurePlaceContext.level();
|
||||
BlockPos pos = be_updatePos(featurePlaceContext.origin(), world);
|
||||
return new FeaturePlaceContext<NoneFeatureConfiguration>(
|
||||
BlockPos pos = be_updatePortalPos(world);
|
||||
return new FeaturePlaceContext<>(
|
||||
world,
|
||||
featurePlaceContext.chunkGenerator(),
|
||||
featurePlaceContext.random(),
|
||||
|
@ -63,21 +65,24 @@ public class EndPodiumFeatureMixin {
|
|||
);
|
||||
}
|
||||
|
||||
private BlockPos be_updatePos(BlockPos blockPos, WorldGenLevel world) {
|
||||
if (GeneratorOptions.useNewGenerator()) {
|
||||
BlockPos pos = GeneratorOptions.getPortalPos();
|
||||
if (pos.equals(BlockPos.ZERO)) {
|
||||
int y = world.getChunk(0, 0, ChunkStatus.FULL).getHeight(Types.WORLD_SURFACE, blockPos.getX(), blockPos.getZ());
|
||||
if (y < 1) {
|
||||
y = 65;
|
||||
}
|
||||
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);
|
||||
private BlockPos be_updatePortalPos(WorldGenLevel world) {
|
||||
CompoundTag compound = WorldDataAPI.getRootTag(BetterEnd.MOD_ID).getCompound("portal");
|
||||
be_portalPosition = NbtUtils.readBlockPos(compound);
|
||||
|
||||
if (be_portalPosition.getY() == 0) {
|
||||
/*if (GeneratorOptions.useNewGenerator()) {
|
||||
int y = TerrainGenerator.getHeight(0, 0, world.getLevel().getChunkSource().getGenerator().getBiomeSource());
|
||||
be_portalPosition = new BlockPos(0, y, 0);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue