[Change] Changed default settings/Behaviours for plants

This commit is contained in:
Frank 2023-06-13 16:46:05 +02:00
parent 3d7eaa7ec5
commit 8013404726
18 changed files with 71 additions and 159 deletions

View file

@ -200,7 +200,7 @@ public class PostInitAPI {
} }
} }
if (block instanceof BehaviourWaterPlant) { if (block instanceof BehaviourWaterPlantLike) {
TagManager.BLOCKS.add(block, CommonBlockTags.WATER_PLANT); TagManager.BLOCKS.add(block, CommonBlockTags.WATER_PLANT);
} }
@ -209,14 +209,14 @@ public class PostInitAPI {
} }
if (block instanceof BehaviourSeed) { if (block instanceof BehaviourSeedLike) {
TagManager.BLOCKS.add(block, CommonBlockTags.SEEDS); TagManager.BLOCKS.add(block, CommonBlockTags.SEEDS);
if (item != null && item != Items.AIR) { if (item != null && item != Items.AIR) {
TagManager.ITEMS.add(block, CommonItemTags.SEEDS); TagManager.ITEMS.add(block, CommonItemTags.SEEDS);
} }
} }
if (block instanceof BehaviourSapling) { if (block instanceof BehaviourSaplingLike) {
TagManager.BLOCKS.add(block, CommonBlockTags.SAPLINGS, BlockTags.SAPLINGS); TagManager.BLOCKS.add(block, CommonBlockTags.SAPLINGS, BlockTags.SAPLINGS);
if (item != null && item != Items.AIR) { if (item != null && item != Items.AIR) {
TagManager.ITEMS.add(block, CommonItemTags.SAPLINGS, ItemTags.SAPLINGS); TagManager.ITEMS.add(block, CommonItemTags.SAPLINGS, ItemTags.SAPLINGS);

View file

@ -2,5 +2,5 @@ package org.betterx.bclib.behaviours.interfaces;
import org.betterx.bclib.interfaces.tools.AddMineableHoe; import org.betterx.bclib.interfaces.tools.AddMineableHoe;
public interface BehaviourSapling extends AddMineableHoe, BehaviourCompostable, BehaviourPlantLike { public interface BehaviourSapling extends AddMineableHoe, BehaviourCompostable, BehaviourPlantLike, BehaviourSaplingLike {
} }

View file

@ -0,0 +1,4 @@
package org.betterx.bclib.behaviours.interfaces;
public interface BehaviourSaplingLike {
}

View file

@ -2,5 +2,5 @@ package org.betterx.bclib.behaviours.interfaces;
import org.betterx.bclib.interfaces.tools.AddMineableHoe; import org.betterx.bclib.interfaces.tools.AddMineableHoe;
public interface BehaviourSeed extends AddMineableHoe, BehaviourCompostable, BehaviourPlantLike { public interface BehaviourSeed extends AddMineableHoe, BehaviourCompostable, BehaviourPlantLike, BehaviourSeedLike {
} }

View file

@ -0,0 +1,4 @@
package org.betterx.bclib.behaviours.interfaces;
public interface BehaviourSeedLike {
}

View file

@ -2,5 +2,5 @@ package org.betterx.bclib.behaviours.interfaces;
import org.betterx.bclib.interfaces.tools.AddMineableHoe; import org.betterx.bclib.interfaces.tools.AddMineableHoe;
public interface BehaviourWaterPlant extends AddMineableHoe, BehaviourPlantLike, BehaviourCompostable { public interface BehaviourWaterPlant extends AddMineableHoe, BehaviourWaterPlantLike, BehaviourCompostable {
} }

View file

@ -0,0 +1,4 @@
package org.betterx.bclib.behaviours.interfaces;
public interface BehaviourWaterPlantLike extends BehaviourPlantLike {
}

View file

@ -0,0 +1,6 @@
package org.betterx.bclib.behaviours.interfaces;
import org.betterx.bclib.interfaces.tools.AddMineableHoe;
public interface BehaviourWaterPlantSapling extends AddMineableHoe, BehaviourCompostable, BehaviourWaterPlantLike, BehaviourSaplingLike {
}

View file

@ -0,0 +1,6 @@
package org.betterx.bclib.behaviours.interfaces;
import org.betterx.bclib.interfaces.tools.AddMineableHoe;
public interface BehaviourWaterPlantSeed extends AddMineableHoe, BehaviourCompostable, BehaviourWaterPlantLike, BehaviourSeedLike {
}

View file

@ -1,6 +1,7 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.BehaviourBuilders; import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.interfaces.SurvivesOnBlocks;
import org.betterx.bclib.util.BlocksHelper; import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper; import org.betterx.bclib.util.MHelper;
@ -16,6 +17,7 @@ import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
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.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
@ -30,21 +32,25 @@ import com.google.common.collect.Lists;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class BaseCropBlock extends BasePlantBlock { public class BaseCropBlock extends BasePlantBlock implements SurvivesOnBlocks {
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
private static final VoxelShape SHAPE = box(2, 0, 2, 14, 14, 14); private static final VoxelShape SHAPE = box(2, 0, 2, 14, 14, 14);
private final Block[] terrain; private final List<Block> terrain;
private final Item drop; private final Item drop;
public BaseCropBlock(Item drop, Block... terrain) { public BaseCropBlock(Item drop, Block... terrain) {
this(BehaviourBuilders.applyBasePlantSettings().randomTicks(), drop, terrain); this(
BehaviourBuilders.createPlant().randomTicks().sound(SoundType.CROP).offsetType(OffsetType.XZ),
drop,
terrain
);
} }
protected BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) { protected BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) {
super(properties); super(properties);
this.drop = drop; this.drop = drop;
this.terrain = terrain; this.terrain = List.of(terrain);
this.registerDefaultState(defaultBlockState().setValue(AGE, 0)); this.registerDefaultState(defaultBlockState().setValue(AGE, 0));
} }
@ -53,16 +59,6 @@ public class BaseCropBlock extends BasePlantBlock {
stateManager.add(AGE); stateManager.add(AGE);
} }
@Override
protected boolean isTerrain(BlockState state) {
for (Block block : terrain) {
if (state.is(block)) {
return true;
}
}
return false;
}
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
if (state.getValue(AGE) < 3) { if (state.getValue(AGE) < 3) {
@ -113,4 +109,14 @@ public class BaseCropBlock extends BasePlantBlock {
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE; return SHAPE;
} }
@Override
public List<Block> getSurvivableBlocks() {
return terrain;
}
@Override
public boolean isTerrain(BlockState state) {
return SurvivesOnBlocks.super.isTerrain(state);
}
} }

View file

@ -1,12 +1,10 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.client.models.BasePatterns; 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.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
import org.betterx.bclib.interfaces.SettingsExtender;
import org.betterx.bclib.items.tool.BaseShearsItem; import org.betterx.bclib.items.tool.BaseShearsItem;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -25,8 +23,6 @@ import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.SoundType;
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.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
@ -46,48 +42,6 @@ import org.jetbrains.annotations.Nullable;
public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock {
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() {
this(BehaviourBuilders.applyBasePlantSettings());
}
public BasePlantBlock(int light) {
this(BehaviourBuilders.applyBasePlantSettings(light));
}
@Deprecated(forRemoval = true)
public BasePlantBlock(int light, SettingsExtender propMod) {
this(false, light, propMod);
}
public BasePlantBlock(boolean replaceable) {
this(BehaviourBuilders.applyBasePlantSettings(replaceable));
}
@Deprecated(forRemoval = true)
public BasePlantBlock(boolean replaceable, SettingsExtender propMod) {
this(replaceable, 0, propMod);
}
public BasePlantBlock(boolean replaceable, int light) {
this(BehaviourBuilders.applyBasePlantSettings(replaceable, light));
}
@Deprecated(forRemoval = true)
public BasePlantBlock(boolean replaceable, int light, SettingsExtender propMod) {
this(
propMod.amend(
(replaceable
? BehaviourBuilders.createReplaceablePlant()
: BehaviourBuilders.createPlant()
)
.lightLevel((state) -> light)
.sound(SoundType.GRASS)
.offsetType(BlockBehaviour.OffsetType.XZ)
)
);
}
protected BasePlantBlock(Properties settings) { protected BasePlantBlock(Properties settings) {
super(settings); super(settings);
} }

View file

@ -1,7 +1,5 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.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;
@ -12,22 +10,11 @@ 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.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import java.util.function.Function;
public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public BasePlantWithAgeBlock() {
this(p -> p);
}
@Deprecated(forRemoval = true)
public BasePlantWithAgeBlock(Function<Properties, Properties> propMod) {
this(propMod.apply(BehaviourBuilders.applyBasePlantSettings().randomTicks()));
}
protected BasePlantWithAgeBlock(Properties settings) { protected BasePlantWithAgeBlock(Properties settings) {
super(settings); super(settings.randomTicks());
} }
@Override @Override

View file

@ -1,6 +1,5 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.behaviours.interfaces.BehaviourWaterPlant; import org.betterx.bclib.behaviours.interfaces.BehaviourWaterPlant;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -14,20 +13,6 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer, BehaviourWaterPlant { public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer, BehaviourWaterPlant {
public BaseUnderwaterWallPlantBlock() {
this(0);
}
public BaseUnderwaterWallPlantBlock(int light) {
this(
UnderwaterPlantBlock.baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
light
)
);
}
public BaseUnderwaterWallPlantBlock(Properties settings) { public BaseUnderwaterWallPlantBlock(Properties settings) {
super(settings); super(settings);
} }

View file

@ -1,6 +1,5 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.util.BlocksHelper; import org.betterx.bclib.util.BlocksHelper;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -30,14 +29,6 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
)); ));
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public BaseWallPlantBlock() {
this(BehaviourBuilders.applyBasePlantSettings());
}
public BaseWallPlantBlock(int light) {
this(BehaviourBuilders.applyBasePlantSettings(light));
}
protected BaseWallPlantBlock(Properties settings) { protected BaseWallPlantBlock(Properties settings) {
super(settings.offsetType(OffsetType.NONE)); super(settings.offsetType(OffsetType.NONE));
} }

View file

@ -50,16 +50,13 @@ public class FeatureSaplingBlock<F extends Feature<FC>, FC extends FeatureConfig
private final FeatureSupplier<F, FC> feature; private final FeatureSupplier<F, FC> feature;
public FeatureSaplingBlock(FeatureSupplier<F, FC> featureSupplier) { public FeatureSaplingBlock(FeatureSupplier<F, FC> featureSupplier) {
this( this(0, featureSupplier);
BehaviourBuilders.createTickingPlant()
.sound(SoundType.GRASS),
featureSupplier
);
} }
public FeatureSaplingBlock(int light, FeatureSupplier<F, FC> featureSupplier) { public FeatureSaplingBlock(int light, FeatureSupplier<F, FC> featureSupplier) {
this( this(
BehaviourBuilders.createTickingPlant() BehaviourBuilders.createPlant().randomTicks()
.noCollission()
.lightLevel(state -> light) .lightLevel(state -> light)
.sound(SoundType.GRASS), .sound(SoundType.GRASS),
featureSupplier featureSupplier

View file

@ -1,7 +1,5 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.behaviours.interfaces.BehaviourWaterPlant;
import org.betterx.bclib.client.render.BCLRenderLayer; import org.betterx.bclib.client.render.BCLRenderLayer;
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;
@ -21,8 +19,6 @@ import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.LiquidBlockContainer; import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SoundType;
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.Fluid; import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
@ -36,49 +32,10 @@ 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;
import java.util.function.Function;
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer, BehaviourWaterPlant {
public static Properties baseUnderwaterPlantSettings(BlockBehaviour.Properties props, int light) {
props
.sound(SoundType.WET_GRASS)
.noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ);
if (light > 0) props.lightLevel(s -> light);
return props;
}
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer {
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 UnderwaterPlantBlock() {
this(p -> p);
}
@Deprecated(forRemoval = true)
public UnderwaterPlantBlock(Function<Properties, Properties> propMod) {
this(
propMod.apply(baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
0
))
);
}
public UnderwaterPlantBlock(int light) {
this(light, p -> p);
}
@Deprecated(forRemoval = true)
public UnderwaterPlantBlock(int light, Function<Properties, Properties> propMod) {
this(
propMod.apply(baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
light
))
);
}
public UnderwaterPlantBlock(Properties settings) { public UnderwaterPlantBlock(Properties settings) {
super(settings); super(settings);
} }

View file

@ -7,6 +7,8 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
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.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
@ -14,11 +16,16 @@ import net.minecraft.world.level.block.state.properties.IntegerProperty;
public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock(BlockBehaviour.Properties properties) {
super(properties.randomTicks());
}
public UnderwaterPlantWithAgeBlock() { public UnderwaterPlantWithAgeBlock() {
super(baseUnderwaterPlantSettings( this(BehaviourBuilders
BehaviourBuilders.createWaterPlant(), .createWaterPlant()
0 .sound(SoundType.WET_GRASS)
).randomTicks()); .offsetType(BlockBehaviour.OffsetType.XZ)
);
} }
@Override @Override

View file

@ -17,7 +17,11 @@ 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(BehaviourBuilders.applyBasePlantSettings(light).destroyTime(0.2F).sound(SoundType.WOOD)); super(BehaviourBuilders.createPlant()
.destroyTime(0.2F)
.lightLevel(state -> light)
.sound(SoundType.WOOD)
);
} }
protected WallMushroomBlock(BlockBehaviour.Properties properties) { protected WallMushroomBlock(BlockBehaviour.Properties properties) {