Use BlocksHelper for Terrain
This commit is contained in:
parent
49edee32a8
commit
51a0e7cf74
4 changed files with 38 additions and 19 deletions
|
@ -23,7 +23,6 @@ import net.minecraft.world.level.levelgen.placement.*;
|
|||
|
||||
import com.mojang.serialization.Codec;
|
||||
import org.betterx.bclib.api.features.config.ScatterFeatureConfig;
|
||||
import org.betterx.bclib.api.tag.CommonBlockTags;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -243,7 +242,7 @@ public class ScatterFeature<FC extends ScatterFeatureConfig>
|
|||
BlockPos blockPos,
|
||||
BlockState baseState) {
|
||||
BlockState blockState = levelAccessor.getBlockState(blockPos);
|
||||
if (blockState.is(CommonBlockTags.TERRAIN)) {
|
||||
if (BlocksHelper.isTerrain(blockState)) {
|
||||
levelAccessor.setBlock(blockPos, baseState, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.mojang.datafixers.util.Function15;
|
|||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.tag.CommonBlockTags;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -352,7 +352,7 @@ public abstract class ScatterFeatureConfig implements FeatureConfiguration {
|
|||
|
||||
@Override
|
||||
public boolean isValidBase(BlockState state) {
|
||||
return state.is(CommonBlockTags.TERRAIN);
|
||||
return BlocksHelper.isTerrain(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
|||
import net.minecraft.world.level.levelgen.placement.PlacementModifierType;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import org.betterx.bclib.util.BlocksHelper;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -60,15 +61,11 @@ public class OnEveryLayer
|
|||
for (int y = startY; y >= ctx.getMinBuildHeight() + 1; --y) {
|
||||
mPos.setY(y - 1);
|
||||
BlockState belowState = ctx.getBlockState(mPos);
|
||||
if (!OnEveryLayer.isEmpty(belowState) && OnEveryLayer.isEmpty(nowState) && !belowState.is(Blocks.BEDROCK)) {
|
||||
if (BlocksHelper.isTerrain(belowState) && BlocksHelper.isFreeOrFluid(nowState) && !belowState.is(Blocks.BEDROCK)) {
|
||||
return mPos.getY() + 1;
|
||||
}
|
||||
nowState = belowState;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
private static boolean isEmpty(BlockState blockState) {
|
||||
return blockState.isAir() || blockState.is(Blocks.WATER) || blockState.is(Blocks.LAVA);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|||
import net.minecraft.world.level.material.LavaFluid;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.betterx.bclib.api.tag.CommonBlockTags;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
@ -169,15 +170,6 @@ public class BlocksHelper {
|
|||
return DIRECTIONS[random.nextInt(6)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if block is {@link Fluid} or not.
|
||||
*
|
||||
* @param state - {@link BlockState} to check.
|
||||
* @return {@code true} if block is fluid and {@code false} if not.
|
||||
*/
|
||||
public static boolean isFluid(BlockState state) {
|
||||
return !state.getFluidState().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if block is "invulnerable" like Bedrock.
|
||||
|
@ -239,7 +231,7 @@ public class BlocksHelper {
|
|||
if (len == 0) { //we started inside of the surface
|
||||
for (int lenUp = 0; lenUp < length; lenUp++) {
|
||||
startPos.move(dir, -1);
|
||||
if (!surface.test(level.getBlockState(startPos))) {
|
||||
if (BlocksHelper.isFree(level.getBlockState(startPos))) {
|
||||
startPos.move(dir, 1);
|
||||
return true;
|
||||
}
|
||||
|
@ -290,4 +282,35 @@ public class BlocksHelper {
|
|||
public static boolean isLava(BlockState state) {
|
||||
return state.getFluidState().getType() instanceof LavaFluid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if block is {@link Fluid} or not.
|
||||
*
|
||||
* @param state - {@link BlockState} to check.
|
||||
* @return {@code true} if block is fluid and {@code false} if not.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static boolean isFluidOld(BlockState state) {
|
||||
return !state.getFluidState().isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isFluid(BlockState state) {
|
||||
return state.getMaterial().isLiquid();
|
||||
}
|
||||
|
||||
public static boolean isFree(BlockState state) {
|
||||
return state.isAir();
|
||||
}
|
||||
|
||||
public static boolean isFreeOrFluid(BlockState state) {
|
||||
return state.isAir() || isFluid(state);
|
||||
}
|
||||
|
||||
public static boolean isTerrain(BlockState state) {
|
||||
return state.is(CommonBlockTags.TERRAIN);
|
||||
}
|
||||
|
||||
public static boolean isTerrainOrFluid(BlockState state) {
|
||||
return state.is(CommonBlockTags.TERRAIN) || isFluid(state);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue