topMaterial handling

This commit is contained in:
Frank 2021-12-09 23:00:35 +01:00
parent 38992bbf93
commit 7292c3cf3a
5 changed files with 88 additions and 55 deletions

View file

@ -1,21 +1,23 @@
package ru.bclib.world.features;
import java.util.List;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import ru.bclib.util.StructureHelper;
import java.util.List;
import java.util.Random;
public class ListFeature extends NBTStructureFeature {
private final List<StructureInfo> list;
private StructureInfo selected;
public ListFeature(List<StructureInfo> list) {
public ListFeature(List<StructureInfo> list, BlockState defaultBlock) {
super(defaultBlock);
this.list = list;
}

View file

@ -1,5 +1,9 @@
package ru.bclib.world.features;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
@ -10,7 +14,6 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
@ -24,11 +27,12 @@ import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.util.BlocksHelper;
import ru.bclib.world.processors.DestructionStructureProcessor;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
public abstract class NBTStructureFeature extends DefaultFeature {
private final BlockState defaultBlock;
public NBTStructureFeature(BlockState defaultBlock){
this.defaultBlock = defaultBlock;
}
protected static final DestructionStructureProcessor DESTRUCTION = new DestructionStructureProcessor();
protected abstract StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, Random random);
@ -142,14 +146,9 @@ public abstract class NBTStructureFeature extends DefaultFeature {
BlockState stateSt = world.getBlockState(mut);
if (!stateSt.is(TagAPI.BLOCK_GEN_TERRAIN)) {
if (merge == TerrainMerge.SURFACE) {
// SurfaceBuilderConfiguration config = world.getBiome(mut)
// .getGenerationSettings()
// .getSurfaceBuilderConfig();
boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking();
BlockState top =
Blocks.PURPLE_CONCRETE.defaultBlockState();
//TODO: 1.18 find another way to get the Top/Bottom Materiel
//isTop ? config.getTopMaterial() : config.getUnderMaterial();
Biome b = world.getBiome(mut);
BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock);
BlocksHelper.setWithoutUpdate(world, mut, top);
}
else {
@ -159,12 +158,8 @@ public abstract class NBTStructureFeature extends DefaultFeature {
else {
if (stateSt.is(TagAPI.BLOCK_END_GROUND) && state.getMaterial().isSolidBlocking()) {
if (merge == TerrainMerge.SURFACE) {
// SurfaceBuilderConfiguration config = world.getBiome(mut)
// .getGenerationSettings()
// .getSurfaceBuilderConfig();
BlockState bottom = Blocks.PURPLE_CONCRETE.defaultBlockState();
//TODO: 1.18 find another way to get the Top Material
//config.getUnderMaterial()
Biome b = world.getBiome(mut);
BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock);
BlocksHelper.setWithoutUpdate(world, mut, bottom);
}
else {

View file

@ -2,24 +2,25 @@ package ru.bclib.world.processors;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
import ru.bclib.api.biomes.BiomeAPI;
public class TerrainStructureProcessor extends StructureProcessor {
private final Block defaultBlock;
public TerrainStructureProcessor(Block defaultBlock){
this.defaultBlock = defaultBlock;
}
@Override
public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlaceSettings structurePlacementData) {
BlockPos bpos = structureBlockInfo2.pos;
if (structureBlockInfo2.state.is(Blocks.END_STONE) && worldView.isEmptyBlock(bpos.above())) {
BlockState top = Blocks.PURPLE_CONCRETE.defaultBlockState();
//TODO: 1.18 find another way to get the Top Materiel
// worldView.getBiome(structureBlockInfo2.pos)
// .getGenerationSettings()
// .getSurfaceBuilderConfig()
// .getTopMaterial();
if (structureBlockInfo2.state.is(defaultBlock) && worldView.isEmptyBlock(bpos.above())) {
final BlockState top = BiomeAPI.findTopMaterial(worldView.getBiome(pos)).orElse(defaultBlock.defaultBlockState());
return new StructureBlockInfo(bpos, top, structureBlockInfo2.nbt);
}
return structureBlockInfo2;