[Change] Added BehaviourBuilders to replace the deprecated Block-MaterialSystem

This commit is contained in:
Frank 2023-05-17 14:42:40 +02:00
parent e656bce991
commit 4a74a44422
20 changed files with 144 additions and 95 deletions

View file

@ -233,7 +233,7 @@ public class StructureWorldNBT extends StructureNBT {
POS.setY(y); POS.setY(y);
for (int z = start.getZ(); z <= end.getZ(); z++) { for (int z = start.getZ(); z <= end.getZ(); z++) {
POS.setZ(z); POS.setZ(z);
if (world.getBlockState(POS).getMaterial().isReplaceable()) if (world.getBlockState(POS).canBeReplaced())
airCount++; airCount++;
count++; count++;
} }
@ -263,7 +263,7 @@ public class StructureWorldNBT extends StructureNBT {
POS.setY(y); POS.setY(y);
for (int z = start.getZ(); z <= end.getZ(); z++) { for (int z = start.getZ(); z <= end.getZ(); z++) {
POS.setZ(z); POS.setZ(z);
if (world.getBlockState(POS).getMaterial().isReplaceable()) if (world.getBlockState(POS).canBeReplaced())
airCount++; airCount++;
count++; count++;
} }

View file

@ -79,7 +79,7 @@ public abstract class TemplateStructure extends Structure {
} }
protected boolean isFloorPlaceable(BlockState state, BlockState before) { protected boolean isFloorPlaceable(BlockState state, BlockState before) {
return (state == null || state.is(Blocks.AIR)) && before.getMaterial().isSolid(); return (state == null || state.is(Blocks.AIR)) && before.isSolid();
} }
protected int erosion(RandomSource rnd) { protected int erosion(RandomSource rnd) {
@ -219,7 +219,7 @@ public abstract class TemplateStructure extends Structure {
int airCount = 0; int airCount = 0;
for (int i = y; i < y + height && i > y - height; i += searchStep) { for (int i = y; i < y + height && i > y - height; i += searchStep) {
BlockState state = column.getBlock(i); BlockState state = column.getBlock(i);
if (state.isAir() || state.getMaterial().isReplaceable()) { if (state.isAir() || state.canBeReplaced()) {
airCount++; airCount++;
} }
} }

View file

@ -17,7 +17,6 @@ import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.placement.*; import net.minecraft.world.level.levelgen.placement.*;
import net.minecraft.world.level.material.Material;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -278,7 +277,7 @@ abstract class CommonPlacedFeatureBuilder<F extends Feature<FC>, FC extends Feat
/** /**
* Cast a ray with max {@code distance} length to find the next solid Block. The ray will travel through replaceable * Cast a ray with max {@code distance} length to find the next solid Block. The ray will travel through replaceable
* Blocks (see {@link Material#isReplaceable()}) and will be accepted if it hits a block with the * Blocks and will be accepted if it hits a block with the
* {@link CommonBlockTags#TERRAIN}-tag * {@link CommonBlockTags#TERRAIN}-tag
* *
* @param dir The direction the ray is cast * @param dir The direction the ray is cast

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.items.tool.BaseShearsItem; import org.betterx.bclib.items.tool.BaseShearsItem;
import org.betterx.bclib.util.BlocksHelper; import org.betterx.bclib.util.BlocksHelper;
@ -27,7 +28,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -45,20 +45,20 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R
public BaseDoublePlantBlock() { public BaseDoublePlantBlock() {
this( this(
Properties.of(Material.PLANT) BehaviourBuilders
.sound(SoundType.GRASS) .createPlant()
.noCollission() .sound(SoundType.GRASS)
.offsetType(BlockBehaviour.OffsetType.NONE) .offsetType(BlockBehaviour.OffsetType.NONE)
); );
} }
public BaseDoublePlantBlock(int light) { public BaseDoublePlantBlock(int light) {
this( this(
Properties.of(Material.PLANT) BehaviourBuilders
.sound(SoundType.GRASS) .createPlant()
.lightLevel((state) -> state.getValue(TOP) ? light : 0) .sound(SoundType.GRASS)
.noCollission() .lightLevel((state) -> state.getValue(TOP) ? light : 0)
.offsetType(BlockBehaviour.OffsetType.NONE) .offsetType(BlockBehaviour.OffsetType.NONE)
); );
} }
@ -84,7 +84,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below()); BlockState down = world.getBlockState(pos.below());
BlockState up = world.getBlockState(pos.above()); BlockState up = world.getBlockState(pos.above());
return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getMaterial().isReplaceable()); return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.canBeReplaced());
} }
public boolean canStayAt(BlockState state, LevelReader world, BlockPos pos) { public boolean canStayAt(BlockState state, LevelReader world, BlockPos pos) {

View file

@ -1,5 +1,6 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.BlockModelProvider; import org.betterx.bclib.interfaces.BlockModelProvider;
import org.betterx.bclib.interfaces.TagProvider; import org.betterx.bclib.interfaces.TagProvider;
import org.betterx.bclib.util.LootUtil; import org.betterx.bclib.util.LootUtil;
@ -25,7 +26,6 @@ import net.minecraft.world.level.block.DropExperienceBlock;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
@ -45,8 +45,8 @@ public class BaseOreBlock extends DropExperienceBlock implements BlockModelProvi
public BaseOreBlock(Supplier<Item> drop, int minCount, int maxCount, int experience, int miningLevel) { public BaseOreBlock(Supplier<Item> drop, int minCount, int maxCount, int experience, int miningLevel) {
this( this(
Properties BehaviourBuilders
.of(Material.STONE, MapColor.SAND) .createStone(MapColor.SAND)
.requiresCorrectToolForDrops() .requiresCorrectToolForDrops()
.destroyTime(3F) .destroyTime(3F)
.explosionResistance(9F) .explosionResistance(9F)

View file

@ -4,6 +4,7 @@ import org.betterx.bclib.client.models.BasePatterns;
import org.betterx.bclib.client.models.ModelsHelper; import org.betterx.bclib.client.models.ModelsHelper;
import org.betterx.bclib.client.models.PatternsHelper; import org.betterx.bclib.client.models.PatternsHelper;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.interfaces.SettingsExtender; import org.betterx.bclib.interfaces.SettingsExtender;
import org.betterx.bclib.items.tool.BaseShearsItem; import org.betterx.bclib.items.tool.BaseShearsItem;
@ -27,7 +28,6 @@ import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -57,12 +57,13 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
} }
public static Properties basePlantSettings(boolean replaceable, int light) { public static Properties basePlantSettings(boolean replaceable, int light) {
return basePlantSettings(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT, light); return basePlantSettings(replaceable
? BehaviourBuilders.createReplaceablePlant()
: BehaviourBuilders.createPlant(), light);
} }
public static Properties basePlantSettings(Material mat, int light) { public static Properties basePlantSettings(BlockBehaviour.Properties props, int light) {
Properties props = Properties props
.of(mat)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ); .offsetType(BlockBehaviour.OffsetType.XZ);
@ -102,12 +103,14 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public BasePlantBlock(boolean replaceable, int light, SettingsExtender propMod) { public BasePlantBlock(boolean replaceable, int light, SettingsExtender propMod) {
this( this(
propMod.amend(Properties propMod.amend(
.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) (replaceable
.lightLevel((state) -> light) ? BehaviourBuilders.createReplaceablePlant()
.sound(SoundType.GRASS) : BehaviourBuilders.createPlant()
.noCollission() )
.offsetType(BlockBehaviour.OffsetType.XZ) .lightLevel((state) -> light)
.sound(SoundType.GRASS)
.offsetType(BlockBehaviour.OffsetType.XZ)
) )
); );
} }

View file

@ -122,9 +122,9 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
if (!state.getValue(FLOOR)) { if (!state.getValue(FLOOR)) {
int index = (((state.getValue(ROTATION) >> 2) + 2)) & 3; int index = (((state.getValue(ROTATION) >> 2) + 2)) & 3;
return world.getBlockState(pos.relative(BlocksHelper.HORIZONTAL[index])).getMaterial().isSolid(); return world.getBlockState(pos.relative(BlocksHelper.HORIZONTAL[index])).isSolid();
} else { } else {
return world.getBlockState(pos.below()).getMaterial().isSolid(); return world.getBlockState(pos.below()).isSolid();
} }
} }

View file

@ -2,6 +2,7 @@ package org.betterx.bclib.blocks;
import org.betterx.bclib.blocks.BlockProperties.TripleShape; import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.items.tool.BaseShearsItem; import org.betterx.bclib.items.tool.BaseShearsItem;
import org.betterx.bclib.util.BlocksHelper; import org.betterx.bclib.util.BlocksHelper;
@ -26,7 +27,6 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -57,13 +57,14 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid
public BaseVineBlock(int light, boolean bottomOnly, Function<Properties, Properties> propMod) { public BaseVineBlock(int light, boolean bottomOnly, Function<Properties, Properties> propMod) {
this( this(
propMod.apply(Properties propMod.apply(BehaviourBuilders
.of(Material.PLANT) .createPlant()
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM .lightLevel((state) -> bottomOnly
? state.getValue(SHAPE) == TripleShape.BOTTOM
? light ? light
: 0 : light) : 0
.noCollission() : light)
.offsetType(BlockBehaviour.OffsetType.XZ)) .offsetType(BlockBehaviour.OffsetType.XZ))
); );
} }

View file

@ -61,7 +61,7 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
} }
public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) { public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) {
return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction); return blockState.isSolid() && blockState.isFaceSturdy(world, pos, direction);
} }
@Override @Override

View file

@ -5,6 +5,7 @@ import org.betterx.bclib.client.models.BasePatterns;
import org.betterx.bclib.client.models.ModelsHelper; import org.betterx.bclib.client.models.ModelsHelper;
import org.betterx.bclib.client.models.PatternsHelper; import org.betterx.bclib.client.models.PatternsHelper;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.BlockModelProvider; import org.betterx.bclib.interfaces.BlockModelProvider;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
@ -26,7 +27,6 @@ import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
@ -51,23 +51,17 @@ public class FeatureSaplingBlock<F extends Feature<FC>, FC extends FeatureConfig
public FeatureSaplingBlock(FeatureSupplier<F, FC> featureSupplier) { public FeatureSaplingBlock(FeatureSupplier<F, FC> featureSupplier) {
this( this(
BlockBehaviour.Properties.of(Material.PLANT) BehaviourBuilders.createTickingPlant()
.noCollission() .sound(SoundType.GRASS),
.instabreak()
.sound(SoundType.GRASS)
.randomTicks(),
featureSupplier featureSupplier
); );
} }
public FeatureSaplingBlock(int light, FeatureSupplier<F, FC> featureSupplier) { public FeatureSaplingBlock(int light, FeatureSupplier<F, FC> featureSupplier) {
this( this(
BlockBehaviour.Properties.of(Material.PLANT) BehaviourBuilders.createTickingPlant()
.noCollission() .lightLevel(state -> light)
.lightLevel(state -> light) .sound(SoundType.GRASS),
.instabreak()
.sound(SoundType.GRASS)
.randomTicks(),
featureSupplier featureSupplier
); );
} }

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.interfaces.TagProvider; import org.betterx.bclib.interfaces.TagProvider;
import org.betterx.bclib.interfaces.tools.AddMineableHoe; import org.betterx.bclib.interfaces.tools.AddMineableHoe;
@ -14,37 +15,24 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.Material;
import java.util.List; import java.util.List;
public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider, AddMineableShears, AddMineableHoe { public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider, AddMineableShears, AddMineableHoe {
public SimpleLeavesBlock(MapColor color) { public SimpleLeavesBlock(MapColor color) {
this( this(
Properties BehaviourBuilders
.of(Material.LEAVES) .createLeaves(color)
.strength(0.2F)
.color(color)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false)
); );
} }
public SimpleLeavesBlock(MapColor color, int light) { public SimpleLeavesBlock(MapColor color, int light) {
this( this(
Properties BehaviourBuilders
.of(Material.LEAVES) .createLeaves(color)
.lightLevel(ignored -> light) .lightLevel(ignored -> light)
.color(color)
.strength(0.2F)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false)
); );
} }

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.items.tool.BaseShearsItem; import org.betterx.bclib.items.tool.BaseShearsItem;
@ -25,15 +26,12 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.List; import java.util.List;
@ -54,14 +52,13 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
public static Properties baseUnderwaterPlantSettings(boolean replaceable, int light) { public static Properties baseUnderwaterPlantSettings(boolean replaceable, int light) {
return baseUnderwaterPlantSettings( return baseUnderwaterPlantSettings(
replaceable ? Material.REPLACEABLE_WATER_PLANT : Material.WATER_PLANT, replaceable ? BehaviourBuilders.createReplaceableWaterPlant() : BehaviourBuilders.createWaterPlant(),
light light
); );
} }
public static Properties baseUnderwaterPlantSettings(Material mat, int light) { public static Properties baseUnderwaterPlantSettings(BlockBehaviour.Properties props, int light) {
Properties props = FabricBlockSettings props
.of(mat)
.sound(SoundType.WET_GRASS) .sound(SoundType.WET_GRASS)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ); .offsetType(BlockBehaviour.OffsetType.XZ);

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import org.betterx.bclib.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.interfaces.tools.AddMineableHoe; import org.betterx.bclib.interfaces.tools.AddMineableHoe;
import org.betterx.bclib.interfaces.tools.AddMineableShears; import org.betterx.bclib.interfaces.tools.AddMineableShears;
@ -21,13 +22,11 @@ import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.List; import java.util.List;
@ -36,10 +35,9 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende
private static final VoxelShape SHAPE = box(4, 0, 4, 12, 16, 12); private static final VoxelShape SHAPE = box(4, 0, 4, 12, 16, 12);
public UpDownPlantBlock() { public UpDownPlantBlock() {
this(Properties this(BehaviourBuilders
.of(Material.PLANT) .createPlant()
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noCollission()
); );
} }

View file

@ -29,6 +29,6 @@ public abstract class WallMushroomBlock extends BaseWallPlantBlock {
@Override @Override
public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) { public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) {
return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction); return blockState.isSolid() && blockState.isFaceSturdy(world, pos, direction);
} }
} }

View file

@ -0,0 +1,65 @@
package org.betterx.bclib.complexmaterials;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
public class BehaviourBuilders {
public static BlockBehaviour.Properties createPlant() {
return BlockBehaviour.Properties.of()
.mapColor(MapColor.PLANT)
.noCollission()
.instabreak()
.pushReaction(PushReaction.DESTROY);
}
public static BlockBehaviour.Properties createTickingPlant() {
return createPlant().randomTicks();
}
public static BlockBehaviour.Properties createReplaceablePlant() {
return createPlant().replaceable();
}
public static BlockBehaviour.Properties createWaterPlant() {
return BlockBehaviour.Properties.of()
.mapColor(MapColor.WATER)
.noCollission()
.instabreak()
.pushReaction(PushReaction.DESTROY);
}
public static BlockBehaviour.Properties createReplaceableWaterPlant() {
return createWaterPlant().replaceable();
}
public static BlockBehaviour.Properties createLeaves() {
return createLeaves(MapColor.PLANT);
}
public static BlockBehaviour.Properties createLeaves(MapColor color) {
return BlockBehaviour.Properties.of()
.mapColor(color)
.strength(0.2f)
.randomTicks()
.noOcclusion()
.isValidSpawn(Blocks::ocelotOrParrot)
.isSuffocating(Blocks::never)
.isViewBlocking(Blocks::never)
.ignitedByLava()
.pushReaction(PushReaction.DESTROY)
.isRedstoneConductor(Blocks::never);
}
public static BlockBehaviour.Properties createStone() {
return createStone(MapColor.STONE);
}
public static BlockBehaviour.Properties createStone(MapColor color) {
return BlockBehaviour.Properties.of()
.mapColor(color)
.instrument(NoteBlockInstrument.BASEDRUM);
}
}

View file

@ -43,7 +43,7 @@ public class BlockRegistry extends BaseRegistry<Block> {
} }
registerBlockItem(id, item); registerBlockItem(id, item);
if (block.defaultBlockState().getMaterial().isFlammable() if (block.defaultBlockState().ignitedByLava()
&& FlammableBlockRegistry.getDefaultInstance() && FlammableBlockRegistry.getDefaultInstance()
.get(block) .get(block)
.getBurnChance() == 0) { .getBurnChance() == 0) {

View file

@ -20,7 +20,7 @@ import java.util.function.Function;
public abstract class SDF { public abstract class SDF {
private final List<Function<PosInfo, BlockState>> postProcesses = Lists.newArrayList(); private final List<Function<PosInfo, BlockState>> postProcesses = Lists.newArrayList();
private Function<BlockState, Boolean> canReplace = (state) -> { private Function<BlockState, Boolean> canReplace = (state) -> {
return state.getMaterial().isReplaceable(); return state.canBeReplaced();
}; };
public abstract float getDistance(float x, float y, float z); public abstract float getDistance(float x, float y, float z);

View file

@ -85,7 +85,7 @@ public class BlocksHelper {
public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) { public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) {
final MutableBlockPos POS = TL_POS.get(); final MutableBlockPos POS = TL_POS.get();
POS.set(pos); POS.set(pos);
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { for (int j = 1; j < maxDist && (world.getBlockState(POS)).canBeReplaced(); j++) {
POS.setY(POS.getY() - 1); POS.setY(POS.getY() - 1);
} }
return pos.getY() - POS.getY(); return pos.getY() - POS.getY();
@ -94,7 +94,7 @@ public class BlocksHelper {
public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) { public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
final MutableBlockPos POS = TL_POS.get(); final MutableBlockPos POS = TL_POS.get();
POS.set(pos); POS.set(pos);
for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { for (int j = 1; j < maxDist && (world.getBlockState(POS)).canBeReplaced(); j++) {
POS.move(dx, dy, dz); POS.move(dx, dy, dz);
} }
return (int) pos.distSqr(POS); return (int) pos.distSqr(POS);
@ -326,7 +326,7 @@ public class BlocksHelper {
} }
public static boolean isFluid(BlockState state) { public static boolean isFluid(BlockState state) {
return state.getMaterial().isLiquid(); return state.liquid();
} }
public static boolean isFree(BlockState state) { public static boolean isFree(BlockState state) {
@ -334,7 +334,7 @@ public class BlocksHelper {
} }
public static boolean isFreeOrReplaceable(BlockState state) { public static boolean isFreeOrReplaceable(BlockState state) {
return state.isAir() || state.getMaterial().isReplaceable(); return state.isAir() || state.canBeReplaced();
} }
public static boolean isFreeOrFluid(BlockState state) { public static boolean isFreeOrFluid(BlockState state) {

View file

@ -11,8 +11,8 @@ import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.material.Material;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -149,7 +149,7 @@ public class StructureErode {
int px = MHelper.floor(random.nextGaussian() * 2 + x + 0.5); int px = MHelper.floor(random.nextGaussian() * 2 + x + 0.5);
int pz = MHelper.floor(random.nextGaussian() * 2 + z + 0.5); int pz = MHelper.floor(random.nextGaussian() * 2 + z + 0.5);
mut2.set(px, y, pz); mut2.set(px, y, pz);
while (world.getBlockState(mut2).getMaterial().isReplaceable() && mut2.getY() > minY) { while (world.getBlockState(mut2).canBeReplaced() && mut2.getY() > minY) {
mut2.setY(mut2.getY() - 1); mut2.setY(mut2.getY() - 1);
} }
if (!world.getBlockState(mut2).isAir() && state.canSurvive(world, mut2)) { if (!world.getBlockState(mut2).isAir() && state.canSurvive(world, mut2)) {
@ -225,7 +225,7 @@ public class StructureErode {
BlockState state = world.getBlockState(mut); BlockState state = world.getBlockState(mut);
if (!ignore(state, world, mut) && !blocks.contains(mut)) { if (!ignore(state, world, mut) && !blocks.contains(mut)) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
while (world.getBlockState(mut).getMaterial().isReplaceable() && mut.getY() > minY) { while (world.getBlockState(mut).canBeReplaced() && mut.getY() > minY) {
mut.setY(mut.getY() - 1); mut.setY(mut.getY() - 1);
} }
if (mut.getY() > minY) { if (mut.getY() > minY) {
@ -242,7 +242,10 @@ public class StructureErode {
if (state.is(CommonBlockTags.GEN_END_STONES) || state.is(BlockTags.NYLIUM)) { if (state.is(CommonBlockTags.GEN_END_STONES) || state.is(BlockTags.NYLIUM)) {
return true; return true;
} }
return !state.getMaterial().equals(Material.STONE) || BlocksHelper.isInvulnerable(state, world, pos);
//NoteBlockInstrument.BASEDRUM this is basically what Material.STONE was previously
return !state.instrument().equals(NoteBlockInstrument.BASEDRUM)
|| BlocksHelper.isInvulnerable(state, world, pos);
} }
private static boolean isTerrainNear(WorldGenLevel world, BlockPos pos) { private static boolean isTerrainNear(WorldGenLevel world, BlockPos pos) {
@ -266,8 +269,7 @@ public class StructureErode {
mut.setY(y); mut.setY(y);
BlockState state = world.getBlockState(mut); BlockState state = world.getBlockState(mut);
if (state.is(CommonBlockTags.TERRAIN) && !world.getBlockState(mut.above()) if (state.is(CommonBlockTags.TERRAIN) && !world.getBlockState(mut.above())
.getMaterial() .isSolid()) {
.isSolidBlocking()) {
BlocksHelper.setWithoutUpdate(world, mut, top); BlocksHelper.setWithoutUpdate(world, mut, top);
} }
} }

View file

@ -28,7 +28,9 @@ accessible method net/minecraft/world/level/levelgen/NoiseRouterData noNewCaves
accessible method net/minecraft/world/level/levelgen/NoiseRouterData slideNetherLike (Lnet/minecraft/core/HolderGetter;II)Lnet/minecraft/world/level/levelgen/DensityFunction; accessible method net/minecraft/world/level/levelgen/NoiseRouterData slideNetherLike (Lnet/minecraft/core/HolderGetter;II)Lnet/minecraft/world/level/levelgen/DensityFunction;
accessible method net/minecraft/tags/TagEntry elementOrTag ()Lnet/minecraft/util/ExtraCodecs$TagOrElementLocation; accessible method net/minecraft/tags/TagEntry elementOrTag ()Lnet/minecraft/util/ExtraCodecs$TagOrElementLocation;
accessible method net/minecraft/data/worldgen/biome/OverworldBiomes calculateSkyColor (F)I accessible method net/minecraft/data/worldgen/biome/OverworldBiomes calculateSkyColor (F)I
accessible method net/minecraft/advancements/Advancement$Builder <init> (Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/advancements/DisplayInfo;Lnet/minecraft/advancements/AdvancementRewards;Ljava/util/Map;[[Ljava/lang/String;)V accessible method net/minecraft/world/level/block/Blocks ocelotOrParrot (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/EntityType;)Ljava/lang/Boolean;
accessible method net/minecraft/world/level/block/Blocks never (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/EntityType;)Ljava/lang/Boolean;
accessible method net/minecraft/world/level/block/Blocks never (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Z
#Fields #Fields
accessible field net/minecraft/world/entity/ai/village/poi/PoiTypes TYPE_BY_STATE Ljava/util/Map; accessible field net/minecraft/world/entity/ai/village/poi/PoiTypes TYPE_BY_STATE Ljava/util/Map;