Custom End Portal
This commit is contained in:
parent
22e916f4a1
commit
674d80a3de
6 changed files with 109 additions and 35 deletions
|
@ -2,33 +2,71 @@ package ru.betterend.mixin.common;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.Heightmap.Type;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.EndPortalFeature;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.StructureHelper;
|
||||
import ru.betterend.util.WorldDataUtil;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
@Mixin(EndPortalFeature.class)
|
||||
public class EndPortalFeatureMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private boolean open;
|
||||
|
||||
@Inject(method = "generate", at = @At("HEAD"), cancellable = true)
|
||||
private void bePortalGenerate(StructureWorldAccess structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig, CallbackInfoReturnable<Boolean> info) {
|
||||
private void bePortalGenerate(StructureWorldAccess world, ChunkGenerator generator, Random random, BlockPos blockPos, DefaultFeatureConfig config, CallbackInfoReturnable<Boolean> info) {
|
||||
if (!GeneratorOptions.hasPortal()) {
|
||||
info.setReturnValue(false);
|
||||
info.cancel();
|
||||
}
|
||||
else if (GeneratorOptions.replacePortal()) {
|
||||
blockPos = be_updatePos(blockPos, world);
|
||||
Structure structure = StructureHelper.readStructure(BetterEnd.makeID(open ? "portal/end_portal_active" : "portal/end_portal_inactive"));
|
||||
BlockPos size = structure.getSize();
|
||||
blockPos = blockPos.add(-(size.getX() >> 1), -3, -(size.getZ() >> 1));
|
||||
structure.place(world, blockPos, new StructurePlacementData(), random);
|
||||
info.setReturnValue(true);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyVariable(method = "generate", ordinal = 0, at = @At("HEAD"))
|
||||
private BlockPos be_setPosOnGround(BlockPos blockPos, StructureWorldAccess structureWorldAccess) {
|
||||
int y = structureWorldAccess.getChunk(blockPos).sampleHeightmap(Type.WORLD_SURFACE, blockPos.getX() & 15, blockPos.getZ() & 15);
|
||||
return new BlockPos(blockPos.getX(), y, blockPos.getZ());
|
||||
private BlockPos be_setPosOnGround(BlockPos blockPos, StructureWorldAccess world) {
|
||||
return be_updatePos(blockPos, world);
|
||||
}
|
||||
|
||||
private BlockPos be_updatePos(BlockPos blockPos, StructureWorldAccess world) {
|
||||
if (GeneratorOptions.useNewGenerator()) {
|
||||
BlockPos pos = GeneratorOptions.getPortalPos();
|
||||
if (pos.equals(BlockPos.ORIGIN)) {
|
||||
int y = world.getChunk(blockPos).sampleHeightmap(Type.WORLD_SURFACE, blockPos.getX(), blockPos.getZ());
|
||||
if (y < 1) {
|
||||
y = 65;
|
||||
}
|
||||
pos = new BlockPos(pos.getX(), y, pos.getZ());
|
||||
GeneratorOptions.setPortalPos(pos);
|
||||
WorldDataUtil.getRootTag().put("portal", NbtHelper.fromBlockPos(pos));
|
||||
WorldDataUtil.saveFile();
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
return blockPos;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue