Application of Behaviours and Tags as replacement for Materials

This commit is contained in:
Frank 2023-05-24 23:09:21 +02:00
parent f371a562f9
commit fcbfe26811
13 changed files with 160 additions and 32 deletions

View file

@ -184,6 +184,28 @@ public class PostInitAPI {
} }
} }
if (block instanceof BehaviourWaterPlant) {
TagManager.BLOCKS.add(block, CommonBlockTags.WATER_PLANT);
}
if (block instanceof BehaviourPlant) {
TagManager.BLOCKS.add(block, CommonBlockTags.PLANT);
}
if (block instanceof BehaviourSeed) {
TagManager.BLOCKS.add(block, CommonBlockTags.SEEDS);
if (item != null && item != Items.AIR) {
TagManager.ITEMS.add(block, CommonItemTags.SEEDS);
}
}
if (block instanceof BehaviourSapling) {
TagManager.BLOCKS.add(block, CommonBlockTags.SAPLINGS);
if (item != null && item != Items.AIR) {
TagManager.ITEMS.add(block, CommonItemTags.SAPLINGS);
}
}
if (block instanceof BehaviourClimable c) { if (block instanceof BehaviourClimable c) {
TagManager.BLOCKS.add(block, BlockTags.CLIMBABLE); TagManager.BLOCKS.add(block, BlockTags.CLIMBABLE);
} }
@ -209,7 +231,7 @@ public class PostInitAPI {
if (block instanceof BehaviourOre) { if (block instanceof BehaviourOre) {
TagManager.BLOCKS.add(block, CommonBlockTags.ORES); TagManager.BLOCKS.add(block, CommonBlockTags.ORES);
} }
if (block instanceof Fuel fl) { if (block instanceof Fuel fl) {
FuelRegistry.INSTANCE.add(block, fl.getFuelTime()); FuelRegistry.INSTANCE.add(block, fl.getFuelTime());
} }

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 BehaviourPlant extends AddMineableHoe { public interface BehaviourPlant extends AddMineableHoe, BehaviourCompostable {
} }

View file

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

View file

@ -8,5 +8,5 @@ import org.betterx.bclib.interfaces.tools.AddMineableShears;
* <p> * <p>
* This will add the {@link AddMineableShears}, {@link AddMineableHoe} and {@link BehaviourCompostable} behaviours. * This will add the {@link AddMineableShears}, {@link AddMineableHoe} and {@link BehaviourCompostable} behaviours.
*/ */
public interface BehaviourVine extends AddMineableShears, AddMineableHoe, BehaviourCompostable { public interface BehaviourVine extends AddMineableShears, AddMineableHoe, BehaviourCompostable, BehaviourClimable {
} }

View file

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

View file

@ -1,5 +1,8 @@
package org.betterx.bclib.blocks; package org.betterx.bclib.blocks;
import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.behaviours.interfaces.BehaviourWaterPlant;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
@ -10,7 +13,7 @@ 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;
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer { public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer, BehaviourWaterPlant {
public BaseUnderwaterWallPlantBlock() { public BaseUnderwaterWallPlantBlock() {
this(0); this(0);
@ -18,7 +21,10 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im
public BaseUnderwaterWallPlantBlock(int light) { public BaseUnderwaterWallPlantBlock(int light) {
this( this(
UnderwaterPlantBlock.baseUnderwaterPlantSettings(light) UnderwaterPlantBlock.baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
light
)
); );
} }

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.behaviours.interfaces.BehaviourVine;
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.interfaces.RenderLayerProvider; import org.betterx.bclib.interfaces.RenderLayerProvider;
@ -39,7 +40,7 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, BehaviourVine {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape VOXEL_SHAPE = box(2, 0, 2, 14, 16, 14); private static final VoxelShape VOXEL_SHAPE = box(2, 0, 2, 14, 16, 14);

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.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;
@ -37,25 +38,7 @@ import com.google.common.collect.Lists;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer { public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer, BehaviourWaterPlant {
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 ? BehaviourBuilders.createReplaceableWaterPlant() : BehaviourBuilders.createWaterPlant(),
light
);
}
public static Properties baseUnderwaterPlantSettings(BlockBehaviour.Properties props, int light) { public static Properties baseUnderwaterPlantSettings(BlockBehaviour.Properties props, int light) {
props props
@ -75,7 +58,10 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public UnderwaterPlantBlock(Function<Properties, Properties> propMod) { public UnderwaterPlantBlock(Function<Properties, Properties> propMod) {
this( this(
propMod.apply(baseUnderwaterPlantSettings()) propMod.apply(baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
0
))
); );
} }
@ -86,7 +72,10 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public UnderwaterPlantBlock(int light, Function<Properties, Properties> propMod) { public UnderwaterPlantBlock(int light, Function<Properties, Properties> propMod) {
this( this(
propMod.apply(baseUnderwaterPlantSettings(light)) propMod.apply(baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
light
))
); );
} }

View file

@ -1,5 +1,7 @@
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;
@ -13,7 +15,10 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock() { public UnderwaterPlantWithAgeBlock() {
super(baseUnderwaterPlantSettings().randomTicks()); super(baseUnderwaterPlantSettings(
BehaviourBuilders.createWaterPlant(),
0
).randomTicks());
} }
@Override @Override

View file

@ -1,5 +1,7 @@
package org.betterx.bclib.util; package org.betterx.bclib.util;
import org.betterx.bclib.behaviours.interfaces.BehaviourPlant;
import org.betterx.bclib.behaviours.interfaces.BehaviourSeed;
import org.betterx.worlds.together.tag.v3.CommonBlockTags; import org.betterx.worlds.together.tag.v3.CommonBlockTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -8,13 +10,11 @@ import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.LavaFluid; import net.minecraft.world.level.material.LavaFluid;
import net.minecraft.world.level.material.PushReaction;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -348,4 +348,23 @@ public class BlocksHelper {
public static boolean isTerrainOrFluid(BlockState state) { public static boolean isTerrainOrFluid(BlockState state) {
return state.is(CommonBlockTags.TERRAIN) || isFluid(state); return state.is(CommonBlockTags.TERRAIN) || isFluid(state);
} }
public static Boolean replaceableOrPlant(BlockState state) {
final Block block = state.getBlock();
if (state.is(CommonBlockTags.PLANT) || state.is(CommonBlockTags.WATER_PLANT) || block instanceof BehaviourPlant || block instanceof BehaviourSeed) {
return true;
}
if (state.getPistonPushReaction() == PushReaction.DESTROY && block.defaultDestroyTime() == 0) return true;
if (state.getSoundType() == SoundType.GRASS
|| state.getSoundType() == SoundType.WET_GRASS
|| state.getSoundType() == SoundType.CROP
|| state.getSoundType() == SoundType.CAVE_VINES
) {
return true;
}
return state.canBeReplaced();
}
} }

View file

@ -23,6 +23,7 @@ public class CommonBlockTags {
public static final TagKey<Block> ORES = TagManager.BLOCKS.makeCommonTag("ores"); public static final TagKey<Block> ORES = TagManager.BLOCKS.makeCommonTag("ores");
public static final TagKey<Block> END_ORES = TagManager.BLOCKS.makeCommonTag("end_ores"); public static final TagKey<Block> END_ORES = TagManager.BLOCKS.makeCommonTag("end_ores");
public static final TagKey<Block> SAPLINGS = TagManager.BLOCKS.makeCommonTag("saplings"); public static final TagKey<Block> SAPLINGS = TagManager.BLOCKS.makeCommonTag("saplings");
public static final TagKey<Block> SEEDS = TagManager.BLOCKS.makeCommonTag("seeds");
public static final TagKey<Block> SOUL_GROUND = TagManager.BLOCKS.makeCommonTag("soul_ground"); public static final TagKey<Block> SOUL_GROUND = TagManager.BLOCKS.makeCommonTag("soul_ground");
public static final TagKey<Block> SCULK_LIKE = TagManager.BLOCKS.makeCommonTag("sculk_like"); public static final TagKey<Block> SCULK_LIKE = TagManager.BLOCKS.makeCommonTag("sculk_like");
public static final TagKey<Block> WOODEN_BARREL = TagManager.BLOCKS.makeCommonTag("wooden_barrels"); public static final TagKey<Block> WOODEN_BARREL = TagManager.BLOCKS.makeCommonTag("wooden_barrels");
@ -38,8 +39,13 @@ public class CommonBlockTags {
public static final TagKey<Block> TERRAIN = TagManager.BLOCKS.makeCommonTag("terrain"); public static final TagKey<Block> TERRAIN = TagManager.BLOCKS.makeCommonTag("terrain");
public static final TagKey<Block> NETHER_TERRAIN = TagManager.BLOCKS.makeCommonTag("nether_terrain"); public static final TagKey<Block> NETHER_TERRAIN = TagManager.BLOCKS.makeCommonTag("nether_terrain");
public static final TagKey<Block> BUDDING_BLOCKS = TagManager.BLOCKS.makeCommonTag("budding_blocks"); public static final TagKey<Block> BUDDING_BLOCKS = TagManager.BLOCKS.makeCommonTag("budding_blocks");
public static final TagKey<Block> WATER_PLANT = TagManager.BLOCKS.makeCommonTag("water_plant");
;
public static final TagKey<Block> PLANT = TagManager.BLOCKS.makeCommonTag("plant");
;
static void prepareTags() { static void prepareTags() {
TagManager.BLOCKS.addOtherTags(MINABLE_WITH_HAMMER, BlockTags.MINEABLE_WITH_PICKAXE);
TagManager.BLOCKS.add(SCULK_LIKE, Blocks.SCULK); TagManager.BLOCKS.add(SCULK_LIKE, Blocks.SCULK);
TagManager.BLOCKS.addOtherTags(DRAGON_IMMUNE, BlockTags.DRAGON_IMMUNE); TagManager.BLOCKS.addOtherTags(DRAGON_IMMUNE, BlockTags.DRAGON_IMMUNE);
@ -125,5 +131,71 @@ public class CommonBlockTags {
WOODEN_CHEST, WOODEN_CHEST,
WORKBENCHES WORKBENCHES
); );
TagManager.BLOCKS.add(WATER_PLANT, Blocks.KELP, Blocks.KELP_PLANT, Blocks.SEAGRASS, Blocks.TALL_SEAGRASS);
TagManager.BLOCKS.add(
SAPLINGS,
Blocks.OAK_SAPLING,
Blocks.SPRUCE_SAPLING,
Blocks.BIRCH_SAPLING,
Blocks.JUNGLE_SAPLING,
Blocks.ACACIA_SAPLING,
Blocks.DARK_OAK_SAPLING,
Blocks.MANGROVE_PROPAGULE
);
TagManager.BLOCKS.addOtherTags(PLANT, SAPLINGS);
TagManager.BLOCKS.add(
PLANT,
Blocks.MANGROVE_LEAVES,
Blocks.GRASS,
Blocks.FERN,
Blocks.DANDELION,
Blocks.TORCHFLOWER,
Blocks.POPPY,
Blocks.BLUE_ORCHID,
Blocks.ALLIUM,
Blocks.AZURE_BLUET,
Blocks.RED_TULIP,
Blocks.ORANGE_TULIP,
Blocks.WHITE_TULIP,
Blocks.PINK_TULIP,
Blocks.OXEYE_DAISY,
Blocks.CORNFLOWER,
Blocks.WITHER_ROSE,
Blocks.LILY_OF_THE_VALLEY,
Blocks.WHEAT,
Blocks.CACTUS,
Blocks.SUGAR_CANE,
Blocks.ATTACHED_PUMPKIN_STEM,
Blocks.ATTACHED_MELON_STEM,
Blocks.PUMPKIN_STEM,
Blocks.MELON_STEM,
Blocks.VINE,
Blocks.LILY_PAD,
Blocks.COCOA,
Blocks.CARROTS,
Blocks.POTATOES,
Blocks.SUNFLOWER,
Blocks.LILAC,
Blocks.ROSE_BUSH,
Blocks.PEONY,
Blocks.TALL_GRASS,
Blocks.LARGE_FERN,
Blocks.TORCHFLOWER_CROP,
Blocks.PITCHER_CROP,
Blocks.PITCHER_PLANT,
Blocks.BEETROOTS,
Blocks.BAMBOO,
Blocks.SWEET_BERRY_BUSH,
Blocks.CAVE_VINES,
Blocks.CAVE_VINES_PLANT,
Blocks.SPORE_BLOSSOM,
Blocks.AZALEA,
Blocks.FLOWERING_AZALEA,
Blocks.PINK_PETALS,
Blocks.BIG_DRIPLEAF,
Blocks.BIG_DRIPLEAF_STEM,
Blocks.SMALL_DRIPLEAF
);
} }
} }

View file

@ -14,6 +14,7 @@ public class CommonItemTags {
public static final TagKey<Item> IRON_INGOTS = TagManager.ITEMS.makeCommonTag("iron_ingots"); public static final TagKey<Item> IRON_INGOTS = TagManager.ITEMS.makeCommonTag("iron_ingots");
public static final TagKey<Item> LEAVES = TagManager.ITEMS.makeCommonTag("leaves"); public static final TagKey<Item> LEAVES = TagManager.ITEMS.makeCommonTag("leaves");
public static final TagKey<Item> SAPLINGS = TagManager.ITEMS.makeCommonTag("saplings"); public static final TagKey<Item> SAPLINGS = TagManager.ITEMS.makeCommonTag("saplings");
public static final TagKey<Item> SEEDS = TagManager.ITEMS.makeCommonTag("seeds");
public static final TagKey<Item> SOUL_GROUND = TagManager.ITEMS.makeCommonTag("soul_ground"); public static final TagKey<Item> SOUL_GROUND = TagManager.ITEMS.makeCommonTag("soul_ground");
public static final TagKey<Item> WOODEN_BARREL = TagManager.ITEMS.makeCommonTag("wooden_barrels"); public static final TagKey<Item> WOODEN_BARREL = TagManager.ITEMS.makeCommonTag("wooden_barrels");
public static final TagKey<Item> WOODEN_CHEST = TagManager.ITEMS.makeCommonTag("wooden_chests"); public static final TagKey<Item> WOODEN_CHEST = TagManager.ITEMS.makeCommonTag("wooden_chests");

View file

@ -31,6 +31,7 @@
"RegistryDataLoaderMixin", "RegistryDataLoaderMixin",
"ServerLevelMixin", "ServerLevelMixin",
"ShovelItemAccessor", "ShovelItemAccessor",
"SpongeBlockMixin",
"SurfaceRulesContextAccessor", "SurfaceRulesContextAccessor",
"TheEndBiomesMixin", "TheEndBiomesMixin",
"WorldGenRegionMixin", "WorldGenRegionMixin",