[Change] Refactored Plant API
This commit is contained in:
parent
d5cf63427b
commit
1de4db3cde
11 changed files with 116 additions and 127 deletions
|
@ -14,19 +14,15 @@ import net.minecraft.world.item.enchantment.Enchantments;
|
|||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.StateDefinition;
|
||||
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.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -40,18 +36,11 @@ public class BaseCropBlock extends BasePlantBlock {
|
|||
private final Item drop;
|
||||
|
||||
public BaseCropBlock(Item drop, Block... terrain) {
|
||||
this(
|
||||
FabricBlockSettings.of(Material.PLANT)
|
||||
.sound(SoundType.GRASS)
|
||||
.randomTicks()
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.NONE),
|
||||
drop, terrain
|
||||
);
|
||||
this(basePlantSettings().randomTicks(), drop, terrain);
|
||||
}
|
||||
|
||||
public BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) {
|
||||
super(properties.offsetType(BlockBehaviour.OffsetType.NONE));
|
||||
protected BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) {
|
||||
super(properties);
|
||||
this.drop = drop;
|
||||
this.terrain = terrain;
|
||||
this.registerDefaultState(defaultBlockState().setValue(AGE, 0));
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R
|
|||
FabricBlockSettings.of(Material.PLANT)
|
||||
.sound(SoundType.GRASS)
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.XZ)
|
||||
.offsetType(BlockBehaviour.OffsetType.NONE)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R
|
|||
.sound(SoundType.GRASS)
|
||||
.lightLevel((state) -> state.getValue(TOP) ? light : 0)
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.XZ)
|
||||
.offsetType(BlockBehaviour.OffsetType.NONE)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.betterx.bclib.client.models.ModelsHelper;
|
|||
import org.betterx.bclib.client.models.PatternsHelper;
|
||||
import org.betterx.bclib.client.render.BCLRenderLayer;
|
||||
import org.betterx.bclib.interfaces.RenderLayerProvider;
|
||||
import org.betterx.bclib.interfaces.SettingsExtender;
|
||||
import org.betterx.bclib.items.tool.BaseShearsItem;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
|
@ -41,46 +42,68 @@ import com.google.common.collect.Lists;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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 ? Material.REPLACEABLE_PLANT : Material.PLANT, light);
|
||||
}
|
||||
|
||||
public static Properties basePlantSettings(Material mat, int light) {
|
||||
Properties props = FabricBlockSettings
|
||||
.of(mat)
|
||||
.sounds(SoundType.GRASS)
|
||||
.noCollision()
|
||||
.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);
|
||||
|
||||
public BasePlantBlock() {
|
||||
this(false, p -> p);
|
||||
this(basePlantSettings());
|
||||
}
|
||||
|
||||
public BasePlantBlock(int light) {
|
||||
this(light, p -> p);
|
||||
this(basePlantSettings(light));
|
||||
}
|
||||
|
||||
public BasePlantBlock(int light, Function<Properties, Properties> propMod) {
|
||||
@Deprecated(forRemoval = true)
|
||||
public BasePlantBlock(int light, SettingsExtender propMod) {
|
||||
this(false, light, propMod);
|
||||
}
|
||||
|
||||
public BasePlantBlock(boolean replaceabled) {
|
||||
this(replaceabled, p -> p);
|
||||
public BasePlantBlock(boolean replaceable) {
|
||||
this(basePlantSettings(replaceable));
|
||||
}
|
||||
|
||||
public BasePlantBlock(boolean replaceable, Function<Properties, Properties> propMod) {
|
||||
this(
|
||||
propMod.apply(FabricBlockSettings
|
||||
.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
|
||||
.sound(SoundType.GRASS)
|
||||
.noCollission()
|
||||
.offsetType(OffsetType.NONE)
|
||||
)
|
||||
);
|
||||
@Deprecated(forRemoval = true)
|
||||
public BasePlantBlock(boolean replaceable, SettingsExtender propMod) {
|
||||
this(replaceable, 0, propMod);
|
||||
}
|
||||
|
||||
|
||||
public BasePlantBlock(boolean replaceable, int light) {
|
||||
this(replaceable, light, p -> p);
|
||||
this(basePlantSettings(replaceable, light));
|
||||
}
|
||||
|
||||
public BasePlantBlock(boolean replaceable, int light, Function<Properties, Properties> propMod) {
|
||||
@Deprecated(forRemoval = true)
|
||||
public BasePlantBlock(boolean replaceable, int light, SettingsExtender propMod) {
|
||||
this(
|
||||
propMod.apply(FabricBlockSettings
|
||||
propMod.amend(FabricBlockSettings
|
||||
.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
|
||||
.luminance(light)
|
||||
.sound(SoundType.GRASS)
|
||||
|
@ -90,12 +113,13 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
|
|||
);
|
||||
}
|
||||
|
||||
public BasePlantBlock(Properties settings) {
|
||||
super(settings.offsetType(BlockBehaviour.OffsetType.XZ));
|
||||
protected BasePlantBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
protected abstract boolean isTerrain(BlockState state);
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
|
@ -105,8 +129,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
BlockState down = world.getBlockState(pos.below());
|
||||
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
||||
BlockState down = level.getBlockState(pos.below());
|
||||
return isTerrain(down);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,9 @@ import net.minecraft.util.RandomSource;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -23,16 +19,12 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
|
|||
this(p -> p);
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public BasePlantWithAgeBlock(Function<Properties, Properties> propMod) {
|
||||
this(
|
||||
propMod.apply(FabricBlockSettings.of(Material.PLANT)
|
||||
.sound(SoundType.GRASS)
|
||||
.randomTicks()
|
||||
.noCollission())
|
||||
);
|
||||
this(propMod.apply(basePlantSettings().randomTicks()));
|
||||
}
|
||||
|
||||
public BasePlantWithAgeBlock(Properties settings) {
|
||||
protected BasePlantWithAgeBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,32 +5,20 @@ import net.minecraft.world.level.BlockGetter;
|
|||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.LiquidBlockContainer;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer {
|
||||
|
||||
public BaseUnderwaterWallPlantBlock() {
|
||||
this(
|
||||
FabricBlockSettings
|
||||
.of(Material.WATER_PLANT)
|
||||
.sound(SoundType.WET_GRASS)
|
||||
.noCollission()
|
||||
);
|
||||
this(0);
|
||||
}
|
||||
|
||||
public BaseUnderwaterWallPlantBlock(int light) {
|
||||
this(
|
||||
FabricBlockSettings
|
||||
.of(Material.WATER_PLANT)
|
||||
.luminance(light)
|
||||
.sound(SoundType.WET_GRASS)
|
||||
.noCollission()
|
||||
UnderwaterPlantBlock.baseUnderwaterPlantSettings(light)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -55,7 +43,7 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
return world.getFluidState(pos).getType() == Fluids.WATER && super.canSurvive(state, world, pos);
|
||||
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
||||
return level.getFluidState(pos).getType() == Fluids.WATER && super.canSurvive(state, level, pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,12 @@ import net.minecraft.world.level.BlockGetter;
|
|||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -34,30 +30,18 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
|
|||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||
|
||||
public BaseWallPlantBlock() {
|
||||
this(
|
||||
FabricBlockSettings
|
||||
.of(Material.PLANT)
|
||||
.sound(SoundType.GRASS)
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.NONE)
|
||||
);
|
||||
this(basePlantSettings());
|
||||
}
|
||||
|
||||
public BaseWallPlantBlock(int light) {
|
||||
this(
|
||||
FabricBlockSettings
|
||||
.of(Material.PLANT)
|
||||
.luminance(light)
|
||||
.sound(SoundType.GRASS)
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.NONE)
|
||||
);
|
||||
this(basePlantSettings(light));
|
||||
}
|
||||
|
||||
public BaseWallPlantBlock(Properties settings) {
|
||||
super(settings.offsetType(BlockBehaviour.OffsetType.NONE));
|
||||
protected BaseWallPlantBlock(Properties settings) {
|
||||
super(settings.offsetType(OffsetType.NONE));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(FACING);
|
||||
|
@ -69,11 +53,11 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
|
||||
Direction direction = state.getValue(FACING);
|
||||
BlockPos blockPos = pos.relative(direction.getOpposite());
|
||||
BlockState blockState = world.getBlockState(blockPos);
|
||||
return isSupport(world, blockPos, blockState, direction);
|
||||
BlockState blockState = level.getBlockState(blockPos);
|
||||
return isSupport(level, blockPos, blockState, direction);
|
||||
}
|
||||
|
||||
public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) {
|
||||
|
|
|
@ -40,19 +40,45 @@ import java.util.List;
|
|||
import java.util.function.Function;
|
||||
|
||||
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer {
|
||||
public static Properties baseUnderwaterPlantSettings() {
|
||||
return baseUnderwaterPlantSettings(false, 0);
|
||||
}
|
||||
|
||||
public static Properties baseUnderwaterPlantSettings(int light) {
|
||||
return baseUnderwaterPlantSettings(false, light);
|
||||
}
|
||||
|
||||
public static Properties baseUnderwaterPlantSettings(boolean replaceable) {
|
||||
return baseUnderwaterPlantSettings(replaceable, 0);
|
||||
}
|
||||
|
||||
public static Properties baseUnderwaterPlantSettings(boolean replaceable, int light) {
|
||||
return baseUnderwaterPlantSettings(
|
||||
replaceable ? Material.REPLACEABLE_WATER_PLANT : Material.WATER_PLANT,
|
||||
light
|
||||
);
|
||||
}
|
||||
|
||||
public static Properties baseUnderwaterPlantSettings(Material mat, int light) {
|
||||
Properties props = FabricBlockSettings
|
||||
.of(mat)
|
||||
.sound(SoundType.WET_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);
|
||||
|
||||
public UnderwaterPlantBlock() {
|
||||
this(p -> p);
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public UnderwaterPlantBlock(Function<Properties, Properties> propMod) {
|
||||
this(
|
||||
propMod.apply(FabricBlockSettings
|
||||
.of(Material.WATER_PLANT)
|
||||
.sound(SoundType.WET_GRASS)
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.XZ))
|
||||
propMod.apply(baseUnderwaterPlantSettings())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -60,14 +86,10 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
|
|||
this(light, p -> p);
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public UnderwaterPlantBlock(int light, Function<Properties, Properties> propMod) {
|
||||
this(
|
||||
propMod.apply(FabricBlockSettings
|
||||
.of(Material.WATER_PLANT)
|
||||
.luminance(light)
|
||||
.sound(SoundType.WET_GRASS)
|
||||
.noCollission()
|
||||
.offsetType(BlockBehaviour.OffsetType.XZ))
|
||||
propMod.apply(baseUnderwaterPlantSettings(light))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,25 +5,15 @@ import net.minecraft.server.level.ServerLevel;
|
|||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
|
||||
public static final IntegerProperty AGE = BlockProperties.AGE;
|
||||
|
||||
public UnderwaterPlantWithAgeBlock() {
|
||||
super(
|
||||
FabricBlockSettings
|
||||
.of(Material.WATER_PLANT)
|
||||
.sound(SoundType.WET_GRASS)
|
||||
.randomTicks()
|
||||
.noCollission()
|
||||
);
|
||||
super(baseUnderwaterPlantSettings().randomTicks());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,29 +7,18 @@ import net.minecraft.world.level.LevelReader;
|
|||
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.material.Material;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class WallMushroomBlock extends BaseWallPlantBlock {
|
||||
public WallMushroomBlock(int light) {
|
||||
this(
|
||||
FabricBlockSettings
|
||||
.of(Material.PLANT)
|
||||
.luminance(light)
|
||||
.destroyTime(0.2F)
|
||||
.sound(SoundType.GRASS)
|
||||
.sound(SoundType.WOOD)
|
||||
.noCollission()
|
||||
);
|
||||
super(basePlantSettings(light).destroyTime(0.2F).sound(SoundType.WOOD));
|
||||
}
|
||||
|
||||
public WallMushroomBlock(BlockBehaviour.Properties properties) {
|
||||
protected WallMushroomBlock(BlockBehaviour.Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package org.betterx.bclib.interfaces;
|
||||
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SettingsExtender {
|
||||
BlockBehaviour.Properties amend(BlockBehaviour.Properties props);
|
||||
}
|
|
@ -53,11 +53,14 @@ public interface SurvivesOnSpecialGround {
|
|||
|
||||
boolean isSurvivable(BlockState state);
|
||||
|
||||
default boolean canSurviveOnTop(BlockState state, LevelReader world, BlockPos pos) {
|
||||
default boolean canSurviveOnTop(LevelReader world, BlockPos pos) {
|
||||
return isSurvivable(world.getBlockState(pos.below()));
|
||||
}
|
||||
|
||||
default boolean canSurviveOnBottom(BlockState state, LevelReader world, BlockPos pos) {
|
||||
default boolean canSurviveOnBottom(LevelReader world, BlockPos pos) {
|
||||
return isSurvivable(world.getBlockState(pos.above()));
|
||||
}
|
||||
default boolean isTerrain(BlockState state) {
|
||||
return isSurvivable(state);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue