Portal fixes

This commit is contained in:
paulevsGitch 2020-10-30 12:21:14 +03:00
parent c2e3ef05fa
commit 6d809df962
6 changed files with 149 additions and 25 deletions

View file

@ -20,7 +20,7 @@ import ru.betterend.world.features.EndLilyFeature;
import ru.betterend.world.features.EndLotusFeature;
import ru.betterend.world.features.EndLotusLeafFeature;
import ru.betterend.world.features.EndPortalFeature;
import ru.betterend.world.features.EteranlPortalFeature;
import ru.betterend.world.features.EternalPortalFeature;
import ru.betterend.world.features.LacugroveFeature;
import ru.betterend.world.features.MossyGlowshroomFeature;
import ru.betterend.world.features.PythadendronBushFeature;
@ -71,7 +71,7 @@ public class EndFeatures {
public static final EndPortalFeature END_PORTAL = new EndPortalFeature(new DefaultEndPortalFeature(), (RunedFlavolite) EndBlocks.FLAVOLITE_RUNED);
public static final EndPortalFeature END_PORTAL_ETERNAL = new EndPortalFeature(new DefaultEndPortalFeature(), (RunedFlavolite) EndBlocks.FLAVOLITE_RUNED_ETERNAL);
public static final EndFeature ETERNAL_PORTAL = EndFeature.makeChancedFeature("eternal_portal", new EteranlPortalFeature(), 500);
public static final EndFeature ETERNAL_PORTAL = EndFeature.makeChansedFeature("eternal_portal", new EternalPortalFeature(), 500);
public static void registerBiomeFeatures(Identifier id, Biome biome, List<List<Supplier<ConfiguredFeature<?, ?>>>> features) {
if (id.getNamespace().equals("minecraft")) {

View file

@ -97,7 +97,7 @@ public class EndFeature {
return new EndFeature(name, feature, GenerationStep.Feature.LOCAL_MODIFICATIONS, configured);
}
public static EndFeature makeChancedFeature(String name, Feature<DefaultFeatureConfig> feature, int chance) {
public static EndFeature makeChansedFeature(String name, Feature<DefaultFeatureConfig> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configure(FeatureConfig.DEFAULT).decorate(Decorator.CHANCE.configure(new ChanceDecoratorConfig(chance)));
return new EndFeature(name, feature, GenerationStep.Feature.SURFACE_STRUCTURES, configured);
}

View file

@ -3,14 +3,16 @@ package ru.betterend.world.features;
import java.util.Random;
import net.minecraft.structure.Structure;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
import ru.betterend.BetterEnd;
import ru.betterend.registry.EndTags;
import ru.betterend.util.MHelper;
public class EteranlPortalFeature extends NBTStructureFeature {
public class EternalPortalFeature extends NBTStructureFeature {
private static final Structure PORTAL = readStructure(BetterEnd.makeID("portal/eternal_portal"));
@Override
@ -43,4 +45,20 @@ public class EteranlPortalFeature extends NBTStructureFeature {
protected int getYOffset(Structure structure, StructureWorldAccess world, BlockPos pos, Random random) {
return -3;
}
@Override
protected void addProcessors(StructurePlacementData placementData, Random random) {
DESTRUCTION.setChance(MHelper.randRange(4, 16, random));
placementData.addProcessor(DESTRUCTION);
}
@Override
protected boolean hasErosion() {
return true;
}
@Override
protected boolean hasTerrainOverlay() {
return true;
}
}

View file

@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
@ -15,12 +16,16 @@ import net.minecraft.util.BlockRotation;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockBox;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import ru.betterend.util.BlocksHelper;
import ru.betterend.world.processors.DestructionStructureProcessor;
public abstract class NBTStructureFeature extends DefaultFeature {
protected static final DestructionStructureProcessor DESTRUCTION = new DestructionStructureProcessor();
protected abstract Structure getStructure();
protected abstract boolean canSpawn(StructureWorldAccess world, BlockPos pos);
@ -31,13 +36,18 @@ public abstract class NBTStructureFeature extends DefaultFeature {
protected abstract int getYOffset(Structure structure, StructureWorldAccess world, BlockPos pos, Random random);
protected abstract boolean hasErosion();
protected abstract boolean hasTerrainOverlay();
protected abstract void addProcessors(StructurePlacementData placementData, Random random);
protected BlockPos getGround(StructureWorldAccess world, BlockPos center) {
return getPosOnSurfaceWG(world, center);
return getPosOnSurface(world, center);
}
@Override
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos center, DefaultFeatureConfig featureConfig) {
BlockPos a = center;
center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8);
center = getGround(world, center);
@ -48,30 +58,67 @@ public abstract class NBTStructureFeature extends DefaultFeature {
Structure structure = getStructure();
BlockRotation rotation = getRotation(world, center, random);
BlockMirror mirror = getMirror(world, center, random);
BlockPos size = structure.getSize().rotate(rotation);
double px = size.getX();
double pz = size.getZ();
if (mirror == BlockMirror.FRONT_BACK)
px = -px;
if (mirror == BlockMirror.LEFT_RIGHT)
pz = -pz;
BlockPos offset = Structure.transformAround(structure.getSize(), mirror, rotation, BlockPos.ORIGIN);
center = center.add(0, getYOffset(structure, world, center, random), 0);
center = center.add(-px * 0.5, 0, -pz * 0.5);
//center.subtract(structure.getRotatedSize(rotation));
int offset = getYOffset(structure, world, center, random);
center = center.add(0, offset, 0);
StructurePlacementData placementData = new StructurePlacementData()
.setRotation(rotation)
.setMirror(mirror)
.setPosition(center)
.setBoundingBox(BlockBox.create(center.getX() - 8 - 15, 0, center.getZ() - 8 - 15, center.getX() + 8 + 15, 128, center.getZ() + 8 + 15));
structure.place(world, center, placementData, random);
BlocksHelper.setWithoutUpdate(world, new BlockPos(a.getX(), center.getY() + 10, a.getZ()), Blocks.DIAMOND_BLOCK);
BlocksHelper.setWithoutUpdate(world, center, Blocks.GOLD_BLOCK);
BlockBox bounds = makeBox(center);
StructurePlacementData placementData = new StructurePlacementData().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
addProcessors(placementData, random);
structure.place(world, center.add(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5), placementData, random);
int x1 = center.getX();
int y1 = center.getX();
int z1 = center.getX();
int x2 = x1 + offset.getX();
int y2 = y1 + offset.getY();
int z2 = z1 + offset.getZ();
boolean erosion = hasErosion();
boolean overlay = hasTerrainOverlay();
if (erosion || overlay) {
Mutable mut = new Mutable();
for (int x = x1; x <= x2; x++) {
mut.setX(x);
for (int z = z1; z <= z2; z++) {
mut.setZ(z);
for (int y = y1; y <= y2; y++) {
mut.setY(y);
if (bounds.contains(mut)) {
if (overlay) {
if (world.getBlockState(mut).isOf(Blocks.END_STONE) && world.isAir(mut.up())) {
BlockState terrain = world.getBiome(mut).getGenerationSettings().getSurfaceConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(world, mut, terrain);
}
}
if (erosion) {
mut.setY(mut.getY() - 1);
int down = BlocksHelper.downRay(world, mut, 32);
if (down > 0) {
mut.setY(mut.getY() + 1);
BlockState state = world.getBlockState(mut);
BlocksHelper.setWithoutUpdate(world, mut, AIR);
mut.setY(mut.getY() - down);
BlocksHelper.setWithoutUpdate(world, mut, state);
}
}
}
}
}
}
}
return true;
}
private BlockBox makeBox(BlockPos pos) {
int sx = ((pos.getX() >> 4) << 4) - 16;
int sz = ((pos.getZ() >> 4) << 4) - 16;
int ex = sx + 47;
int ez = sz + 47;
return BlockBox.create(sx, 0, sz, ex, 255, ez);
}
protected static Structure readStructure(Identifier resource) {
String ns = resource.getNamespace();
String nm = resource.getPath();

View file

@ -0,0 +1,31 @@
package ru.betterend.world.processors;
import net.minecraft.structure.Structure.StructureBlockInfo;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.processor.StructureProcessor;
import net.minecraft.structure.processor.StructureProcessorType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldView;
import ru.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper;
public class DestructionStructureProcessor extends StructureProcessor {
private int chance = 4;
public void setChance(int chance) {
this.chance = chance;
}
@Override
public StructureBlockInfo process(WorldView worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlacementData structurePlacementData) {
if (!structureBlockInfo2.state.isOf(EndBlocks.ETERNAL_PEDESTAL) && !structureBlockInfo2.state.isOf(EndBlocks.FLAVOLITE_RUNED_ETERNAL) && MHelper.RANDOM.nextInt(chance) == 0) {
return null;
}
return structureBlockInfo2;
}
@Override
protected StructureProcessorType<?> getType() {
return StructureProcessorType.RULE;
}
}

View file

@ -0,0 +1,28 @@
package ru.betterend.world.processors;
import net.minecraft.structure.Structure.StructureBlockInfo;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.structure.StructurePlacementData;
import net.minecraft.structure.processor.StructureProcessor;
import net.minecraft.structure.processor.StructureProcessorType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldView;
public class TerrainStructureProcessor extends StructureProcessor {
@Override
public StructureBlockInfo process(WorldView worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlacementData structurePlacementData) {
BlockPos bpos = structureBlockInfo2.pos;
if (structureBlockInfo2.state.isOf(Blocks.END_STONE) && worldView.isAir(bpos.up())) {
BlockState top = worldView.getBiome(structureBlockInfo2.pos).getGenerationSettings().getSurfaceConfig().getTopMaterial();
System.out.println(top);
return new StructureBlockInfo(bpos, top, structureBlockInfo2.tag);
}
return structureBlockInfo2;
}
@Override
protected StructureProcessorType<?> getType() {
return StructureProcessorType.RULE;
}
}