Additional Behaviours

This commit is contained in:
Frank 2023-05-21 00:34:04 +02:00
parent 78b39e8506
commit d694a09cdf
11 changed files with 146 additions and 86 deletions

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.util.BlocksHelper; import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper; import org.betterx.bclib.util.MHelper;
@ -37,7 +38,7 @@ public class BaseCropBlock extends BasePlantBlock {
private final Item drop; private final Item drop;
public BaseCropBlock(Item drop, Block... terrain) { public BaseCropBlock(Item drop, Block... terrain) {
this(basePlantSettings().randomTicks(), drop, terrain); this(BehaviourBuilders.applyBasePlantSettings().randomTicks(), drop, terrain);
} }
protected BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) { protected BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) {

View file

@ -21,7 +21,6 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.LeavesBlock;
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;
@ -38,17 +37,12 @@ import java.util.function.Consumer;
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider, TagProvider, AddMineableShears, AddMineableHoe { public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider, TagProvider, AddMineableShears, AddMineableHoe {
protected final Block sapling; protected final Block sapling;
private static BlockBehaviour.Properties makeLeaves(MapColor color) {
return BehaviourBuilders.createLeaves(color)
.copy(Blocks.OAK_LEAVES);
}
public BaseLeavesBlock( public BaseLeavesBlock(
Block sapling, Block sapling,
MapColor color, MapColor color,
Consumer<BlockBehaviour.Properties> customizeProperties Consumer<BlockBehaviour.Properties> customizeProperties
) { ) {
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color))); super(BaseBlock.acceptAndReturn(customizeProperties, BehaviourBuilders.createLeaves(color, true)));
this.sapling = sapling; this.sapling = sapling;
} }
@ -58,17 +52,20 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
int light, int light,
Consumer<BlockBehaviour.Properties> customizeProperties Consumer<BlockBehaviour.Properties> customizeProperties
) { ) {
super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).lightLevel(state -> light))); super(BaseBlock.acceptAndReturn(
customizeProperties,
BehaviourBuilders.createLeaves(color, true).lightLevel(state -> light)
));
this.sapling = sapling; this.sapling = sapling;
} }
public BaseLeavesBlock(Block sapling, MapColor color) { public BaseLeavesBlock(Block sapling, MapColor color) {
super(makeLeaves(color)); super(BehaviourBuilders.createLeaves(color, true));
this.sapling = sapling; this.sapling = sapling;
} }
public BaseLeavesBlock(Block sapling, MapColor color, int light) { public BaseLeavesBlock(Block sapling, MapColor color, int light) {
super(makeLeaves(color).lightLevel(state -> light)); super(BehaviourBuilders.createLeaves(color, true).lightLevel(state -> light));
this.sapling = sapling; this.sapling = sapling;
} }

View file

@ -44,41 +44,14 @@ import java.util.Optional;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock {
public static Properties basePlantSettings() {
return basePlantSettings(false, 0);
}
public static Properties basePlantSettings(int light) {
return basePlantSettings(false, light);
}
public static Properties basePlantSettings(boolean replaceable) {
return basePlantSettings(replaceable, 0);
}
public static Properties basePlantSettings(boolean replaceable, int light) {
return basePlantSettings(replaceable
? BehaviourBuilders.createReplaceablePlant()
: BehaviourBuilders.createPlant(), light);
}
public static Properties basePlantSettings(BlockBehaviour.Properties props, int light) {
props
.sound(SoundType.GRASS)
.noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ);
if (light > 0) props.lightLevel(s -> light);
return props;
}
private static final VoxelShape SHAPE = box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = box(4, 0, 4, 12, 14, 12);
public BasePlantBlock() { public BasePlantBlock() {
this(basePlantSettings()); this(BehaviourBuilders.applyBasePlantSettings());
} }
public BasePlantBlock(int light) { public BasePlantBlock(int light) {
this(basePlantSettings(light)); this(BehaviourBuilders.applyBasePlantSettings(light));
} }
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
@ -87,7 +60,7 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
} }
public BasePlantBlock(boolean replaceable) { public BasePlantBlock(boolean replaceable) {
this(basePlantSettings(replaceable)); this(BehaviourBuilders.applyBasePlantSettings(replaceable));
} }
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
@ -97,7 +70,7 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
public BasePlantBlock(boolean replaceable, int light) { public BasePlantBlock(boolean replaceable, int light) {
this(basePlantSettings(replaceable, light)); this(BehaviourBuilders.applyBasePlantSettings(replaceable, light));
} }
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)

View file

@ -1,5 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
@ -21,7 +23,7 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public BasePlantWithAgeBlock(Function<Properties, Properties> propMod) { public BasePlantWithAgeBlock(Function<Properties, Properties> propMod) {
this(propMod.apply(basePlantSettings().randomTicks())); this(propMod.apply(BehaviourBuilders.applyBasePlantSettings().randomTicks()));
} }
protected BasePlantWithAgeBlock(Properties settings) { protected BasePlantWithAgeBlock(Properties settings) {

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.util.BlocksHelper; import org.betterx.bclib.util.BlocksHelper;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -30,11 +31,11 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public BaseWallPlantBlock() { public BaseWallPlantBlock() {
this(basePlantSettings()); this(BehaviourBuilders.applyBasePlantSettings());
} }
public BaseWallPlantBlock(int light) { public BaseWallPlantBlock(int light) {
this(basePlantSettings(light)); this(BehaviourBuilders.applyBasePlantSettings(light));
} }
protected BaseWallPlantBlock(Properties settings) { protected BaseWallPlantBlock(Properties settings) {

View file

@ -22,7 +22,7 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerPr
public SimpleLeavesBlock(MapColor color) { public SimpleLeavesBlock(MapColor color) {
this( this(
BehaviourBuilders BehaviourBuilders
.createLeaves(color) .createLeaves(color, true)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
); );
} }
@ -30,7 +30,7 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerPr
public SimpleLeavesBlock(MapColor color, int light) { public SimpleLeavesBlock(MapColor color, int light) {
this( this(
BehaviourBuilders BehaviourBuilders
.createLeaves(color) .createLeaves(color, true)
.lightLevel(ignored -> light) .lightLevel(ignored -> light)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
); );

View file

@ -1,5 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.complexmaterials.BehaviourBuilders;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -15,7 +17,7 @@ import java.util.List;
public abstract class WallMushroomBlock extends BaseWallPlantBlock { public abstract class WallMushroomBlock extends BaseWallPlantBlock {
public WallMushroomBlock(int light) { public WallMushroomBlock(int light) {
super(basePlantSettings(light).destroyTime(0.2F).sound(SoundType.WOOD)); super(BehaviourBuilders.applyBasePlantSettings(light).destroyTime(0.2F).sound(SoundType.WOOD));
} }
protected WallMushroomBlock(BlockBehaviour.Properties properties) { protected WallMushroomBlock(BlockBehaviour.Properties properties) {

View file

@ -20,16 +20,16 @@ public class BaseHangingSignBlock extends CeilingHangingSignBlock implements Blo
public final BaseWallHangingSignBlock wallSign; public final BaseWallHangingSignBlock wallSign;
public BaseHangingSignBlock(WoodType type) { public BaseHangingSignBlock(WoodType type) {
this(type, MapColor.WOOD); this(type, MapColor.WOOD, true);
} }
public BaseHangingSignBlock(BCLWoodTypeWrapper type) { public BaseHangingSignBlock(BCLWoodTypeWrapper type) {
this(type.type, type.color); this(type.type, type.color, type.flammable);
} }
public BaseHangingSignBlock(WoodType type, MapColor color) { public BaseHangingSignBlock(WoodType type, MapColor color, boolean flammable) {
super(BehaviourBuilders.createSign(color), type); super(BehaviourBuilders.createSign(color, flammable), type);
this.wallSign = new BaseWallHangingSignBlock(BehaviourBuilders.createWallSign(color, this), type); this.wallSign = new BaseWallHangingSignBlock(BehaviourBuilders.createWallSign(color, this, flammable), type);
} }

View file

@ -20,16 +20,16 @@ public class BaseSignBlock extends StandingSignBlock implements BlockModelProvid
public final BaseWallSignBlock wallSign; public final BaseWallSignBlock wallSign;
public BaseSignBlock(WoodType type) { public BaseSignBlock(WoodType type) {
this(type, MapColor.WOOD); this(type, MapColor.WOOD, true);
} }
public BaseSignBlock(BCLWoodTypeWrapper type) { public BaseSignBlock(BCLWoodTypeWrapper type) {
this(type.type, type.color); this(type.type, type.color, type.flammable);
} }
public BaseSignBlock(WoodType type, MapColor color) { public BaseSignBlock(WoodType type, MapColor color, boolean flammable) {
super(BehaviourBuilders.createSign(color), type); super(BehaviourBuilders.createSign(color, flammable), type);
this.wallSign = new BaseWallSignBlock(BehaviourBuilders.createWallSign(color, this), type); this.wallSign = new BaseWallSignBlock(BehaviourBuilders.createWallSign(color, this, flammable), type);
} }

View file

@ -14,11 +14,13 @@ public final class BCLWoodTypeWrapper {
public final ResourceLocation id; public final ResourceLocation id;
public final WoodType type; public final WoodType type;
public final MapColor color; public final MapColor color;
public final boolean flammable;
protected BCLWoodTypeWrapper(ResourceLocation id, WoodType type, MapColor color) { protected BCLWoodTypeWrapper(ResourceLocation id, WoodType type, MapColor color, boolean flammable) {
this.id = id; this.id = id;
this.type = type; this.type = type;
this.color = color; this.color = color;
this.flammable = flammable;
} }
public static Builder create(String modID, String string) { public static Builder create(String modID, String string) {
@ -73,10 +75,12 @@ public final class BCLWoodTypeWrapper {
private final ResourceLocation id; private final ResourceLocation id;
private BlockSetType setType; private BlockSetType setType;
private MapColor color; private MapColor color;
private boolean flammable;
public Builder(ResourceLocation id) { public Builder(ResourceLocation id) {
this.id = id; this.id = id;
this.color = MapColor.WOOD; this.color = MapColor.WOOD;
this.flammable = true;
} }
public Builder setBlockSetType(BlockSetType setType) { public Builder setBlockSetType(BlockSetType setType) {
@ -89,11 +93,16 @@ public final class BCLWoodTypeWrapper {
return this; return this;
} }
public Builder setFlammable(boolean flammable) {
this.flammable = flammable;
return this;
}
public BCLWoodTypeWrapper build() { public BCLWoodTypeWrapper build() {
if (setType == null) setType = BlockSetTypeRegistry.registerWood(id); if (setType == null) setType = BlockSetTypeRegistry.registerWood(id);
final WoodType type = WoodTypeRegistry.register(id, setType); final WoodType type = WoodTypeRegistry.register(id, setType);
return new BCLWoodTypeWrapper(id, type, color); return new BCLWoodTypeWrapper(id, type, color, flammable);
} }
} }
} }

View file

@ -2,6 +2,7 @@ package org.betterx.bclib.complexmaterials;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
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.properties.NoteBlockInstrument; import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.MapColor;
@ -9,19 +10,38 @@ import net.minecraft.world.level.material.PushReaction;
public class BehaviourBuilders { public class BehaviourBuilders {
public static BlockBehaviour.Properties createPlant() { public static BlockBehaviour.Properties createPlant() {
return createPlant(MapColor.PLANT);
}
public static BlockBehaviour.Properties createPlant(MapColor color) {
return BlockBehaviour.Properties.of() return BlockBehaviour.Properties.of()
.mapColor(MapColor.PLANT) .mapColor(color)
.noCollission() .noCollission()
.instabreak() .instabreak()
.pushReaction(PushReaction.DESTROY); .pushReaction(PushReaction.DESTROY);
} }
public static BlockBehaviour.Properties createGrass(MapColor color, boolean flammable) {
final BlockBehaviour.Properties p = createPlant(color);
if (flammable)
p.ignitedByLava();
return p;
}
public static BlockBehaviour.Properties createTickingPlant() { public static BlockBehaviour.Properties createTickingPlant() {
return createPlant().randomTicks(); return createTickingPlant(MapColor.PLANT);
}
public static BlockBehaviour.Properties createTickingPlant(MapColor color) {
return createPlant(color).randomTicks();
} }
public static BlockBehaviour.Properties createReplaceablePlant() { public static BlockBehaviour.Properties createReplaceablePlant() {
return createPlant().replaceable(); return createReplaceablePlant(MapColor.PLANT);
}
public static BlockBehaviour.Properties createReplaceablePlant(MapColor color) {
return createPlant(color).replaceable();
} }
public static BlockBehaviour.Properties createWaterPlant() { public static BlockBehaviour.Properties createWaterPlant() {
@ -37,21 +57,26 @@ public class BehaviourBuilders {
} }
public static BlockBehaviour.Properties createLeaves() { public static BlockBehaviour.Properties createLeaves() {
return createLeaves(MapColor.PLANT); return createLeaves(MapColor.PLANT, true);
} }
public static BlockBehaviour.Properties createLeaves(MapColor color) { public static BlockBehaviour.Properties createLeaves(MapColor color, boolean flammable) {
return BlockBehaviour.Properties.of() final BlockBehaviour.Properties p = BlockBehaviour.Properties
.mapColor(color) .of()
.strength(0.2f) .mapColor(color)
.randomTicks() .strength(0.2f)
.noOcclusion() .randomTicks()
.isValidSpawn(Blocks::ocelotOrParrot) .noOcclusion()
.isSuffocating(Blocks::never) .isValidSpawn(Blocks::ocelotOrParrot)
.isViewBlocking(Blocks::never) .isSuffocating(Blocks::never)
.ignitedByLava() .isViewBlocking(Blocks::never)
.pushReaction(PushReaction.DESTROY) .pushReaction(PushReaction.DESTROY)
.isRedstoneConductor(Blocks::never); .isRedstoneConductor(Blocks::never)
.sound(SoundType.GRASS);
if (flammable) {
p.ignitedByLava();
}
return p;
} }
public static BlockBehaviour.Properties createStone() { public static BlockBehaviour.Properties createStone() {
@ -61,21 +86,71 @@ public class BehaviourBuilders {
public static BlockBehaviour.Properties createStone(MapColor color) { public static BlockBehaviour.Properties createStone(MapColor color) {
return BlockBehaviour.Properties.of() return BlockBehaviour.Properties.of()
.mapColor(color) .mapColor(color)
.strength(1.5F, 6.0F)
.instrument(NoteBlockInstrument.BASEDRUM); .instrument(NoteBlockInstrument.BASEDRUM);
} }
public static BlockBehaviour.Properties createSign(MapColor color) { public static BlockBehaviour.Properties createWood() {
return BlockBehaviour.Properties.of() return createWood(MapColor.WOOD, true);
.mapColor(color)
.forceSolidOn()
.instrument(NoteBlockInstrument.BASS)
.noCollission()
.strength(1.0f)
.ignitedByLava();
} }
public static BlockBehaviour.Properties createWallSign(MapColor color, Block dropBlock) { public static BlockBehaviour.Properties createWood(MapColor color, boolean flammable) {
return createSign(color).dropsLike(dropBlock); final BlockBehaviour.Properties p = BlockBehaviour.Properties
.of()
.mapColor(color)
.instrument(NoteBlockInstrument.BASS)
.strength(2.0F)
.sound(SoundType.WOOD);
if (flammable) {
p.ignitedByLava();
}
return p;
}
public static BlockBehaviour.Properties createSign(MapColor color, boolean flammable) {
final BlockBehaviour.Properties p = BlockBehaviour.Properties
.of()
.mapColor(color)
.forceSolidOn()
.instrument(NoteBlockInstrument.BASS)
.noCollission()
.strength(1.0f);
if (flammable) {
p.ignitedByLava();
}
return p;
}
public static BlockBehaviour.Properties createWallSign(MapColor color, Block dropBlock, boolean flammable) {
return createSign(color, flammable).dropsLike(dropBlock);
}
public static BlockBehaviour.Properties applyBasePlantSettings() {
return applyBasePlantSettings(false, 0);
}
public static BlockBehaviour.Properties applyBasePlantSettings(int light) {
return applyBasePlantSettings(false, light);
}
public static BlockBehaviour.Properties applyBasePlantSettings(boolean replaceable) {
return applyBasePlantSettings(replaceable, 0);
}
public static BlockBehaviour.Properties applyBasePlantSettings(boolean replaceable, int light) {
return applyBasePlantSettings(replaceable
? createReplaceablePlant()
: createPlant(), light);
}
public static BlockBehaviour.Properties applyBasePlantSettings(BlockBehaviour.Properties props, int light) {
props
.sound(SoundType.GRASS)
.offsetType(BlockBehaviour.OffsetType.XZ);
if (light > 0) props.lightLevel(s -> light);
return props;
} }
} }