From 05f40bc02352d18f773e26cf072df04116b3e95e Mon Sep 17 00:00:00 2001 From: Mechalopa <92443696+Mechalopa@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:19:57 +0900 Subject: [PATCH] Jade vine internal changes, etc --- .../jafohana/registry/ModBiomeFeatures.java | 5 +- .../mechalopa/jafohana/util/ModTags.java | 4 +- .../level/block/BeachSpiderLilyBlock.java | 2 +- .../world/level/block/JadeVineBlock.java | 195 +---------------- .../world/level/block/VineFlowerBlock.java | 205 ++++++++++++++++++ .../properties/ModBlockStateProperties.java | 2 +- ...{JadeVinePart.java => VineFlowerPart.java} | 4 +- .../levelgen/feature/JadeVinesFeature.java | 100 --------- .../levelgen/feature/VineFlowersFeature.java | 89 ++++++++ .../VineFlowersConfiguration.java | 44 ++++ .../jafohana/blockstates/jade_vine.json | 12 +- .../{jade_vine.json => vine_flowers.json} | 2 +- ...on.json => beach_flower_plantable_on.json} | 0 ..._on.json => vine_flower_plantable_on.json} | 0 .../jafohana/tags/block/vine_flowers.json | 6 + .../data/jafohana/tags/item/vine_flowers.json | 6 + .../configured_feature/jade_vines.json | 5 +- .../data/minecraft/tags/block/flowers.json | 2 +- .../minecraft/tags/block/mineable/axe.json | 2 +- .../tags/block/replaceable_by_trees.json | 2 +- .../minecraft/tags/block/sword_efficient.json | 2 +- .../data/minecraft/tags/item/flowers.json | 2 +- .../neoforge/data_maps/item/compostables.json | 2 +- .../block/unbreakable_infertile_crops.json | 2 +- 24 files changed, 380 insertions(+), 315 deletions(-) create mode 100644 src/main/java/com/github/mechalopa/jafohana/world/level/block/VineFlowerBlock.java rename src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/{JadeVinePart.java => VineFlowerPart.java} (85%) delete mode 100644 src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/JadeVinesFeature.java create mode 100644 src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/VineFlowersFeature.java create mode 100644 src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/configurations/VineFlowersConfiguration.java rename src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/{jade_vine.json => vine_flowers.json} (92%) rename src/main/resources/data/jafohana/tags/block/{beach_spider_lily_plantable_on.json => beach_flower_plantable_on.json} (100%) rename src/main/resources/data/jafohana/tags/block/{jade_vine_plantable_on.json => vine_flower_plantable_on.json} (100%) create mode 100644 src/main/resources/data/jafohana/tags/block/vine_flowers.json create mode 100644 src/main/resources/data/jafohana/tags/item/vine_flowers.json diff --git a/src/main/java/com/github/mechalopa/jafohana/registry/ModBiomeFeatures.java b/src/main/java/com/github/mechalopa/jafohana/registry/ModBiomeFeatures.java index a043372a..e661a3cf 100644 --- a/src/main/java/com/github/mechalopa/jafohana/registry/ModBiomeFeatures.java +++ b/src/main/java/com/github/mechalopa/jafohana/registry/ModBiomeFeatures.java @@ -3,9 +3,10 @@ import java.util.function.Supplier; import com.github.mechalopa.jafohana.JAFOhana; -import com.github.mechalopa.jafohana.world.level.levelgen.feature.JadeVinesFeature; import com.github.mechalopa.jafohana.world.level.levelgen.feature.LayeringFeature; +import com.github.mechalopa.jafohana.world.level.levelgen.feature.VineFlowersFeature; import com.github.mechalopa.jafohana.world.level.levelgen.feature.configurations.LayeringFeatureConfiguration; +import com.github.mechalopa.jafohana.world.level.levelgen.feature.configurations.VineFlowersConfiguration; import net.minecraft.core.registries.Registries; import net.minecraft.world.level.levelgen.feature.Feature; @@ -17,7 +18,7 @@ public class ModBiomeFeatures { private static final DeferredRegister> REGISTRY = DeferredRegister.create(Registries.FEATURE, JAFOhana.MODID); - public static final Supplier> JADE_VINES = REGISTRY.register("jade_vines", () -> new JadeVinesFeature(JadeVinesFeature.JadeVinesConfiguration.CODEC)); + public static final Supplier> JADE_VINES = REGISTRY.register("vine_flowers", () -> new VineFlowersFeature(VineFlowersConfiguration.CODEC)); public static final Supplier> LAYERING_FEATURE = REGISTRY.register("layering", () -> new LayeringFeature(LayeringFeatureConfiguration.CODEC)); @SubscribeEvent diff --git a/src/main/java/com/github/mechalopa/jafohana/util/ModTags.java b/src/main/java/com/github/mechalopa/jafohana/util/ModTags.java index fe8de630..80cb1521 100644 --- a/src/main/java/com/github/mechalopa/jafohana/util/ModTags.java +++ b/src/main/java/com/github/mechalopa/jafohana/util/ModTags.java @@ -14,13 +14,13 @@ public static final class BlockTags { public static final TagKey AFFECTS_FASCIATIONS = createBlockTag("affects_fasciations"); public static final TagKey BADLANDS_FLOWER_PLANTABLE_ON = createBlockTag("badlands_flower_plantable_on"); - public static final TagKey BEACH_SPIDER_LILY_PLANTABLE_ON = createBlockTag("beach_spider_lily_plantable_on"); + public static final TagKey BEACH_FLOWER_PLANTABLE_ON = createBlockTag("beach_flower_plantable_on"); public static final TagKey CONVERTABLE_TO_CREEPANSY = createBlockTag("convertable_to_creepansy"); public static final TagKey CONVERTABLE_TO_FASCIATED_DANDELION = createBlockTag("convertable_to_fasciated_dandelion"); public static final TagKey CONVERTABLE_TO_FASCIATED_OXEYE_DAISY = createBlockTag("convertable_to_fasciated_oxeye_daisy"); public static final TagKey CRIMSON_CLOVER_PLANTABLE_ON = createBlockTag("crimson_clover_plantable_on"); - public static final TagKey JADE_VINE_PLANTABLE_ON = createBlockTag("jade_vine_plantable_on"); public static final TagKey RED_SPIDER_LILY_PLANTABLE_ON = createBlockTag("red_spider_lily_plantable_on"); + public static final TagKey VINE_FLOWER_PLANTABLE_ON = createBlockTag("vine_flower_plantable_on"); } public static final class EntityTypeTags diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/block/BeachSpiderLilyBlock.java b/src/main/java/com/github/mechalopa/jafohana/world/level/block/BeachSpiderLilyBlock.java index 3460d463..a523adc0 100644 --- a/src/main/java/com/github/mechalopa/jafohana/world/level/block/BeachSpiderLilyBlock.java +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/block/BeachSpiderLilyBlock.java @@ -18,6 +18,6 @@ public BeachSpiderLilyBlock(Holder effect, float seconds) @Override protected boolean mayPlaceOn(BlockState state, BlockGetter world, BlockPos pos) { - return state.is(ModTags.BlockTags.BEACH_SPIDER_LILY_PLANTABLE_ON); + return state.is(ModTags.BlockTags.BEACH_FLOWER_PLANTABLE_ON); } } \ No newline at end of file diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/block/JadeVineBlock.java b/src/main/java/com/github/mechalopa/jafohana/world/level/block/JadeVineBlock.java index 0d425bc4..1d955325 100644 --- a/src/main/java/com/github/mechalopa/jafohana/world/level/block/JadeVineBlock.java +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/block/JadeVineBlock.java @@ -1,204 +1,17 @@ package com.github.mechalopa.jafohana.world.level.block; -import java.util.Optional; - -import javax.annotation.Nullable; - import com.github.mechalopa.jafohana.ModConfigs; -import com.github.mechalopa.jafohana.util.ModTags; -import com.github.mechalopa.jafohana.world.level.block.state.properties.JadeVinePart; -import com.github.mechalopa.jafohana.world.level.block.state.properties.ModBlockStateProperties; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.RandomSource; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.LevelReader; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -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.StateDefinition; -import net.minecraft.world.level.block.state.properties.EnumProperty; -import net.minecraft.world.level.material.MapColor; -import net.minecraft.world.level.material.PushReaction; - -public class JadeVineBlock extends Block implements BonemealableBlock +public class JadeVineBlock extends VineFlowerBlock { - public static final EnumProperty PART = ModBlockStateProperties.JADE_VINE_PART; - public JadeVineBlock() { - super(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().instabreak().sound(SoundType.CAVE_VINES).offsetType(BlockBehaviour.OffsetType.XZ).ignitedByLava().pushReaction(PushReaction.DESTROY)); - this.registerDefaultState(this.stateDefinition.any().setValue(PART, JadeVinePart.SINGLE)); - } - - @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState state1, LevelAccessor levelAccerssor, BlockPos pos, BlockPos pos1) - { - if (direction == Direction.UP && !this.canSurvive(state, levelAccerssor, pos)) - { - return Blocks.AIR.defaultBlockState(); - } - else if (direction.getAxis() == Direction.Axis.Y) - { - if (levelAccerssor.getBlockState(pos.above()).is(this)) - { - if (levelAccerssor.getBlockState(pos.below()).is(this)) - { - return state.setValue(PART, JadeVinePart.LONG_BODY); - } - else if (levelAccerssor.getBlockState(pos.above(2)).is(this)) - { - return state.setValue(PART, JadeVinePart.LONG_HEAD); - } - else - { - return state.setValue(PART, JadeVinePart.SHORT_HEAD); - } - } - else if (levelAccerssor.getBlockState(pos.below()).is(this)) - { - if (levelAccerssor.getBlockState(pos.below(2)).is(this)) - { - return state.setValue(PART, JadeVinePart.LONG_STEM); - } - else - { - return state.setValue(PART, JadeVinePart.SHORT_STEM); - } - } - else - { - return state.setValue(PART, JadeVinePart.SINGLE); - } - } - else - { - return super.updateShape(state, direction, state1, levelAccerssor, pos, pos1); - } - } - - @Override - public boolean canSurvive(BlockState state, LevelReader levelReader, BlockPos pos) - { - BlockState state1 = levelReader.getBlockState(pos.above()); - return state1.is(this) || state1.is(ModTags.BlockTags.JADE_VINE_PLANTABLE_ON); - } - - @Nullable - @Override - public BlockState getStateForPlacement(BlockPlaceContext context) - { - BlockState state = this.defaultBlockState(); - BlockPos pos = context.getClickedPos(); - LevelReader levelReader = context.getLevel(); - - if (levelReader.getBlockState(pos.above()).is(this)) - { - if (levelReader.getBlockState(pos.above(2)).is(this)) - { - return state.setValue(PART, JadeVinePart.LONG_HEAD); - } - else - { - return state.setValue(PART, JadeVinePart.SHORT_HEAD); - } - } - else - { - return state.setValue(PART, JadeVinePart.SINGLE); - } - } - - @Override - public boolean isValidBonemealTarget(LevelReader levelReader, BlockPos pos, BlockState state) - { - if (state.getValue(PART).isHead()) - { - return this.canGrowInto(levelReader.getBlockState(pos.relative(Direction.DOWN))); - } - else - { - Optional optional = this.getHeadPos(levelReader, pos, state.getBlock()); - return optional.isPresent() && this.canGrowInto(levelReader.getBlockState(optional.get().relative(Direction.DOWN))); - } - } - - @Override - public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) - { - return (double)level.getRandom().nextFloat() < ModConfigs.cachedServer.JADE_VINE_GROW_CHANCE; - } - - @Override - public void performBonemeal(ServerLevel serverLevel, RandomSource random, BlockPos pos, BlockState state) - { - if (state.getValue(PART).isHead()) - { - BlockPos pos1 = pos.relative(Direction.DOWN); - JadeVinePart jadevinepart = state.getValue(PART); - serverLevel.setBlockAndUpdate(pos1, state.setValue(PART, jadevinepart == JadeVinePart.SINGLE ? JadeVinePart.SHORT_HEAD : JadeVinePart.LONG_HEAD)); - } - else - { - Optional optional = this.getHeadPos(serverLevel, pos, state.getBlock()); - - if (optional.isPresent()) - { - BlockState blockstate = serverLevel.getBlockState(optional.get()); - ((JadeVineBlock)blockstate.getBlock()).performBonemeal(serverLevel, random, optional.get(), blockstate); - } - } - } - - protected boolean canGrowInto(BlockState state) - { - return state.isAir(); - } - - private Optional getHeadPos(BlockGetter getter, BlockPos pos, Block p_153325_) - { - BlockPos.MutableBlockPos blockpos$mutableblockpos = pos.mutable(); - BlockState blockstate; - - do - { - blockpos$mutableblockpos.move(Direction.DOWN); - blockstate = getter.getBlockState(blockpos$mutableblockpos); - } - while (blockstate.is(this) && !blockstate.getValue(PART).isHead()); - - return (blockstate.is(this) && blockstate.getValue(PART).isHead()) ? Optional.of(blockpos$mutableblockpos) : Optional.empty(); - } - - @Override - protected void createBlockStateDefinition(StateDefinition.Builder builder) - { - builder.add(PART); - } - - @Override - public boolean isFlammable(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) - { - return true; - } - - @Override - public int getFlammability(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) - { - return 60; + super(); } @Override - public int getFireSpreadSpeed(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) + public double getGrowChance() { - return 15; + return ModConfigs.cachedServer.JADE_VINE_GROW_CHANCE; } } \ No newline at end of file diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/block/VineFlowerBlock.java b/src/main/java/com/github/mechalopa/jafohana/world/level/block/VineFlowerBlock.java new file mode 100644 index 00000000..a68e6b68 --- /dev/null +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/block/VineFlowerBlock.java @@ -0,0 +1,205 @@ +package com.github.mechalopa.jafohana.world.level.block; + +import java.util.Optional; + +import javax.annotation.Nullable; + +import com.github.mechalopa.jafohana.util.ModTags; +import com.github.mechalopa.jafohana.world.level.block.state.properties.ModBlockStateProperties; +import com.github.mechalopa.jafohana.world.level.block.state.properties.VineFlowerPart; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +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.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.material.MapColor; +import net.minecraft.world.level.material.PushReaction; + +public abstract class VineFlowerBlock extends Block implements BonemealableBlock +{ + public static final EnumProperty PART = ModBlockStateProperties.VINE_FLOWER_PART; + + public VineFlowerBlock() + { + super(BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().instabreak().sound(SoundType.CAVE_VINES).offsetType(BlockBehaviour.OffsetType.XZ).ignitedByLava().pushReaction(PushReaction.DESTROY)); + this.registerDefaultState(this.stateDefinition.any().setValue(PART, VineFlowerPart.SINGLE)); + } + + @Override + protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) + { + if (direction == Direction.UP && !this.canSurvive(state, level, pos)) + { + return Blocks.AIR.defaultBlockState(); + } + else if (direction.getAxis() == Direction.Axis.Y) + { + if (level.getBlockState(pos.above()).is(this)) + { + if (level.getBlockState(pos.below()).is(this)) + { + return state.setValue(PART, VineFlowerPart.LONG_BODY); + } + else if (level.getBlockState(pos.above(2)).is(this)) + { + return state.setValue(PART, VineFlowerPart.LONG_HEAD); + } + else + { + return state.setValue(PART, VineFlowerPart.SHORT_HEAD); + } + } + else if (level.getBlockState(pos.below()).is(this)) + { + if (level.getBlockState(pos.below(2)).is(this)) + { + return state.setValue(PART, VineFlowerPart.LONG_STEM); + } + else + { + return state.setValue(PART, VineFlowerPart.SHORT_STEM); + } + } + else + { + return state.setValue(PART, VineFlowerPart.SINGLE); + } + } + else + { + return super.updateShape(state, direction, neighborState, level, pos, neighborPos); + } + } + + @Override + public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) + { + BlockState state1 = level.getBlockState(pos.above()); + return state1.is(this) || state1.is(ModTags.BlockTags.VINE_FLOWER_PLANTABLE_ON); + } + + @Nullable + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) + { + BlockState state = this.defaultBlockState(); + BlockPos pos = context.getClickedPos(); + LevelReader levelReader = context.getLevel(); + + if (levelReader.getBlockState(pos.above()).is(this)) + { + if (levelReader.getBlockState(pos.above(2)).is(this)) + { + return state.setValue(PART, VineFlowerPart.LONG_HEAD); + } + else + { + return state.setValue(PART, VineFlowerPart.SHORT_HEAD); + } + } + else + { + return state.setValue(PART, VineFlowerPart.SINGLE); + } + } + + @Override + public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) + { + if (state.getValue(PART).isHead()) + { + return this.canGrowInto(level.getBlockState(pos.relative(Direction.DOWN))); + } + else + { + Optional optional = this.getHeadPos(level, pos); + return optional.isPresent() && this.canGrowInto(level.getBlockState(optional.get().relative(Direction.DOWN))); + } + } + + @Override + public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) + { + return (double)level.getRandom().nextFloat() < this.getGrowChance(); + } + + public abstract double getGrowChance(); + + @Override + public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) + { + if (state.getValue(PART).isHead()) + { + BlockPos pos1 = pos.relative(Direction.DOWN); + VineFlowerPart vineflowerpart = state.getValue(PART); + level.setBlockAndUpdate(pos1, state.setValue(PART, vineflowerpart == VineFlowerPart.SINGLE ? VineFlowerPart.SHORT_HEAD : VineFlowerPart.LONG_HEAD)); + } + else + { + Optional optional = this.getHeadPos(level, pos); + + if (optional.isPresent()) + { + BlockState blockstate = level.getBlockState(optional.get()); + ((VineFlowerBlock)blockstate.getBlock()).performBonemeal(level, random, optional.get(), blockstate); + } + } + } + + protected boolean canGrowInto(BlockState state) + { + return state.isAir(); + } + + private Optional getHeadPos(BlockGetter level, BlockPos pos) + { + BlockPos.MutableBlockPos blockpos$mutableblockpos = pos.mutable(); + BlockState blockstate; + + do + { + blockpos$mutableblockpos.move(Direction.DOWN); + blockstate = level.getBlockState(blockpos$mutableblockpos); + } + while (blockstate.is(this) && !blockstate.getValue(PART).isHead()); + + return (blockstate.is(this) && blockstate.getValue(PART).isHead()) ? Optional.of(blockpos$mutableblockpos) : Optional.empty(); + } + + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) + { + builder.add(PART); + } + + @Override + public boolean isFlammable(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) + { + return true; + } + + @Override + public int getFlammability(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) + { + return 60; + } + + @Override + public int getFireSpreadSpeed(BlockState state, BlockGetter getter, BlockPos pos, Direction direction) + { + return 15; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/ModBlockStateProperties.java b/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/ModBlockStateProperties.java index 17422f88..b8e9f379 100644 --- a/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/ModBlockStateProperties.java +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/ModBlockStateProperties.java @@ -6,5 +6,5 @@ public class ModBlockStateProperties { public static final BooleanProperty ON_NYLIUM = BooleanProperty.create("on_nylium"); - public static final EnumProperty JADE_VINE_PART = EnumProperty.create("jade_vine", JadeVinePart.class); + public static final EnumProperty VINE_FLOWER_PART = EnumProperty.create("vine_flower", VineFlowerPart.class); } \ No newline at end of file diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/JadeVinePart.java b/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/VineFlowerPart.java similarity index 85% rename from src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/JadeVinePart.java rename to src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/VineFlowerPart.java index 8cb28052..36e25fa3 100644 --- a/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/JadeVinePart.java +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/block/state/properties/VineFlowerPart.java @@ -2,7 +2,7 @@ import net.minecraft.util.StringRepresentable; -public enum JadeVinePart implements StringRepresentable +public enum VineFlowerPart implements StringRepresentable { SINGLE("single"), SHORT_STEM("short_stem"), @@ -13,7 +13,7 @@ public enum JadeVinePart implements StringRepresentable private final String name; - private JadeVinePart(String name) + private VineFlowerPart(String name) { this.name = name; } diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/JadeVinesFeature.java b/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/JadeVinesFeature.java deleted file mode 100644 index 37547d83..00000000 --- a/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/JadeVinesFeature.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.github.mechalopa.jafohana.world.level.levelgen.feature; - -import com.github.mechalopa.jafohana.registry.ModBlocks; -import com.github.mechalopa.jafohana.world.level.block.JadeVineBlock; -import com.github.mechalopa.jafohana.world.level.block.state.properties.JadeVinePart; -import com.github.mechalopa.jafohana.world.level.levelgen.feature.JadeVinesFeature.JadeVinesConfiguration; -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.util.valueproviders.IntProvider; -import net.minecraft.world.level.WorldGenLevel; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; -import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; - -public class JadeVinesFeature extends Feature -{ - public JadeVinesFeature(Codec config) - { - super(config); - } - - @Override - public boolean place(FeaturePlaceContext context) - { - JadeVinesConfiguration config = context.config(); - BlockState state = ModBlocks.JADE_VINE.get().defaultBlockState(); - int i = config.height().sample(context.random()); - - if (i == 0) - { - return false; - } - else - { - WorldGenLevel level = context.level(); - BlockPos pos = context.origin(); - BlockPos.MutableBlockPos mutableblockpos = pos.mutable(); - - for (int j = 0; j < i; ++j) - { - if (!level.isEmptyBlock(mutableblockpos)) - { - if (j > 1) - { - i = j; - break; - } - else - { - return false; - } - } - - mutableblockpos.move(Direction.DOWN); - } - - if (i == 1) - { - level.setBlock(pos, state.setValue(JadeVineBlock.PART, JadeVinePart.SINGLE), 2); - } - else if (i == 2) - { - level.setBlock(pos, state.setValue(JadeVineBlock.PART, JadeVinePart.SHORT_STEM), 2); - level.setBlock(pos.below(), state.setValue(JadeVineBlock.PART, JadeVinePart.SHORT_HEAD), 2); - } - else - { - BlockPos.MutableBlockPos mutableblockpos1 = pos.mutable(); - - for (int h = 0; h < i; ++h) - { - if (h == i - 1) - { - level.setBlock(mutableblockpos1, state.setValue(JadeVineBlock.PART, JadeVinePart.LONG_HEAD), 2); - break; - } - else - { - level.setBlock(mutableblockpos1, state.setValue(JadeVineBlock.PART, h == 0 ? JadeVinePart.LONG_STEM : JadeVinePart.LONG_BODY), 2); - } - - mutableblockpos1.move(Direction.DOWN); - } - } - - return true; - } - } - - public record JadeVinesConfiguration(IntProvider height) implements FeatureConfiguration - { - public static final Codec CODEC = RecordCodecBuilder.create(p -> { - return p.group(IntProvider.NON_NEGATIVE_CODEC.fieldOf("height").forGetter(JadeVinesConfiguration::height)).apply(p, JadeVinesConfiguration::new); - }); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/VineFlowersFeature.java b/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/VineFlowersFeature.java new file mode 100644 index 00000000..2e0039a5 --- /dev/null +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/VineFlowersFeature.java @@ -0,0 +1,89 @@ +package com.github.mechalopa.jafohana.world.level.levelgen.feature; + +import com.github.mechalopa.jafohana.world.level.block.VineFlowerBlock; +import com.github.mechalopa.jafohana.world.level.block.state.properties.VineFlowerPart; +import com.github.mechalopa.jafohana.world.level.levelgen.feature.configurations.VineFlowersConfiguration; +import com.mojang.serialization.Codec; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; + +public class VineFlowersFeature extends Feature +{ + public VineFlowersFeature(Codec config) + { + super(config); + } + + @Override + public boolean place(FeaturePlaceContext context) + { + VineFlowersConfiguration config = context.config(); + int i = config.height().sample(context.random()); + + if (i == 0) + { + return false; + } + else + { + WorldGenLevel level = context.level(); + BlockState state = config.placeBlock().defaultBlockState(); + BlockPos pos = context.origin(); + BlockPos.MutableBlockPos mutableblockpos = pos.mutable(); + + for (int j = 0; j < i; ++j) + { + if (!level.isEmptyBlock(mutableblockpos)) + { + if (j > 1) + { + i = j; + break; + } + else + { + return false; + } + } + + mutableblockpos.move(Direction.DOWN); + } + + if (i == 1) + { + level.setBlock(pos, state.setValue(VineFlowerBlock.PART, VineFlowerPart.SINGLE), 2); + } + else if (i == 2) + { + level.setBlock(pos, state.setValue(VineFlowerBlock.PART, VineFlowerPart.SHORT_STEM), 2); + level.setBlock(pos.below(), state.setValue(VineFlowerBlock.PART, VineFlowerPart.SHORT_HEAD), 2); + } + else + { + BlockPos.MutableBlockPos mutableblockpos1 = pos.mutable(); + + for (int h = 0; h < i; ++h) + { + if (h == i - 1) + { + level.setBlock(mutableblockpos1, state.setValue(VineFlowerBlock.PART, VineFlowerPart.LONG_HEAD), 2); + break; + } + else + { + level.setBlock(mutableblockpos1, state.setValue(VineFlowerBlock.PART, h == 0 ? VineFlowerPart.LONG_STEM : VineFlowerPart.LONG_BODY), 2); + } + + mutableblockpos1.move(Direction.DOWN); + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/configurations/VineFlowersConfiguration.java b/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/configurations/VineFlowersConfiguration.java new file mode 100644 index 00000000..1a7b3c81 --- /dev/null +++ b/src/main/java/com/github/mechalopa/jafohana/world/level/levelgen/feature/configurations/VineFlowersConfiguration.java @@ -0,0 +1,44 @@ +package com.github.mechalopa.jafohana.world.level.levelgen.feature.configurations; + +import com.github.mechalopa.jafohana.registry.ModBlocks; +import com.github.mechalopa.jafohana.world.level.block.VineFlowerBlock; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.util.valueproviders.IntProvider; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; + +public class VineFlowersConfiguration implements FeatureConfiguration +{ + public static final Codec CODEC = RecordCodecBuilder.create(p -> p.group( + IntProvider.NON_NEGATIVE_CODEC.fieldOf("height").forGetter(p1 -> p1.height), + BuiltInRegistries.BLOCK.byNameCodec().fieldOf("place_block").flatXmap(VineFlowersConfiguration::apply, DataResult::success).orElse((VineFlowerBlock)ModBlocks.JADE_VINE.get()).forGetter(p1 -> p1.placeBlock) + ).apply(p, VineFlowersConfiguration::new)); + + private final IntProvider height; + private final VineFlowerBlock placeBlock; + + public VineFlowersConfiguration(IntProvider height, VineFlowerBlock placeBlock) + { + this.height = height; + this.placeBlock = placeBlock; + } + + public IntProvider height() + { + return this.height; + } + + public VineFlowerBlock placeBlock() + { + return this.placeBlock; + } + + private static DataResult apply(Block block) + { + return block instanceof VineFlowerBlock vineflowerblock ? DataResult.success(vineflowerblock) : DataResult.error(() -> "Growth block should be a vineflower block"); + } +} \ No newline at end of file diff --git a/src/main/resources/assets/jafohana/blockstates/jade_vine.json b/src/main/resources/assets/jafohana/blockstates/jade_vine.json index 38a24bef..9abb1577 100644 --- a/src/main/resources/assets/jafohana/blockstates/jade_vine.json +++ b/src/main/resources/assets/jafohana/blockstates/jade_vine.json @@ -1,21 +1,21 @@ { "variants": { - "jade_vine=single": { + "vine_flower=single": { "model": "jafohana:block/jade_vine_single" }, - "jade_vine=short_stem": { + "vine_flower=short_stem": { "model": "jafohana:block/jade_vine_short_stem" }, - "jade_vine=short_head": { + "vine_flower=short_head": { "model": "jafohana:block/jade_vine_short_head" }, - "jade_vine=long_stem": { + "vine_flower=long_stem": { "model": "jafohana:block/jade_vine_long_stem" }, - "jade_vine=long_body": { + "vine_flower=long_body": { "model": "jafohana:block/jade_vine_long_body" }, - "jade_vine=long_head": { + "vine_flower=long_head": { "model": "jafohana:block/jade_vine_long_head" } } diff --git a/src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/jade_vine.json b/src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/vine_flowers.json similarity index 92% rename from src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/jade_vine.json rename to src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/vine_flowers.json index 79c90b2f..9166d438 100644 --- a/src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/jade_vine.json +++ b/src/main/resources/data/jafohana/recipe/mekanism/crushing/biofuel/vine_flowers.json @@ -17,7 +17,7 @@ "type": "mekanism:crushing", "input": { "count": 1, - "item": "jafohana:jade_vine" + "tag": "jafohana:vine_flowers" }, "output": { "count": 4, diff --git a/src/main/resources/data/jafohana/tags/block/beach_spider_lily_plantable_on.json b/src/main/resources/data/jafohana/tags/block/beach_flower_plantable_on.json similarity index 100% rename from src/main/resources/data/jafohana/tags/block/beach_spider_lily_plantable_on.json rename to src/main/resources/data/jafohana/tags/block/beach_flower_plantable_on.json diff --git a/src/main/resources/data/jafohana/tags/block/jade_vine_plantable_on.json b/src/main/resources/data/jafohana/tags/block/vine_flower_plantable_on.json similarity index 100% rename from src/main/resources/data/jafohana/tags/block/jade_vine_plantable_on.json rename to src/main/resources/data/jafohana/tags/block/vine_flower_plantable_on.json diff --git a/src/main/resources/data/jafohana/tags/block/vine_flowers.json b/src/main/resources/data/jafohana/tags/block/vine_flowers.json new file mode 100644 index 00000000..09579714 --- /dev/null +++ b/src/main/resources/data/jafohana/tags/block/vine_flowers.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "jafohana:jade_vine" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/jafohana/tags/item/vine_flowers.json b/src/main/resources/data/jafohana/tags/item/vine_flowers.json new file mode 100644 index 00000000..09579714 --- /dev/null +++ b/src/main/resources/data/jafohana/tags/item/vine_flowers.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "jafohana:jade_vine" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/jafohana/worldgen/configured_feature/jade_vines.json b/src/main/resources/data/jafohana/worldgen/configured_feature/jade_vines.json index 5eeca4e1..32303547 100644 --- a/src/main/resources/data/jafohana/worldgen/configured_feature/jade_vines.json +++ b/src/main/resources/data/jafohana/worldgen/configured_feature/jade_vines.json @@ -3,7 +3,7 @@ "config": { "feature": { "feature": { - "type": "jafohana:jade_vines", + "type": "jafohana:vine_flowers", "config": { "height": { "type": "minecraft:weighted_list", @@ -21,7 +21,8 @@ "weight": 4 } ] - } + }, + "place_block": "jafohana:jade_vine" } }, "placement": [ diff --git a/src/main/resources/data/minecraft/tags/block/flowers.json b/src/main/resources/data/minecraft/tags/block/flowers.json index 09579714..16d5614b 100644 --- a/src/main/resources/data/minecraft/tags/block/flowers.json +++ b/src/main/resources/data/minecraft/tags/block/flowers.json @@ -1,6 +1,6 @@ { "replace": false, "values": [ - "jafohana:jade_vine" + "#jafohana:vine_flowers" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/block/mineable/axe.json b/src/main/resources/data/minecraft/tags/block/mineable/axe.json index 09579714..16d5614b 100644 --- a/src/main/resources/data/minecraft/tags/block/mineable/axe.json +++ b/src/main/resources/data/minecraft/tags/block/mineable/axe.json @@ -1,6 +1,6 @@ { "replace": false, "values": [ - "jafohana:jade_vine" + "#jafohana:vine_flowers" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/block/replaceable_by_trees.json b/src/main/resources/data/minecraft/tags/block/replaceable_by_trees.json index d614b32e..4778d645 100644 --- a/src/main/resources/data/minecraft/tags/block/replaceable_by_trees.json +++ b/src/main/resources/data/minecraft/tags/block/replaceable_by_trees.json @@ -2,6 +2,6 @@ "replace": false, "values": [ "#jafohana:tall_flowers", - "jafohana:jade_vine" + "#jafohana:vine_flowers" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/block/sword_efficient.json b/src/main/resources/data/minecraft/tags/block/sword_efficient.json index d614b32e..4778d645 100644 --- a/src/main/resources/data/minecraft/tags/block/sword_efficient.json +++ b/src/main/resources/data/minecraft/tags/block/sword_efficient.json @@ -2,6 +2,6 @@ "replace": false, "values": [ "#jafohana:tall_flowers", - "jafohana:jade_vine" + "#jafohana:vine_flowers" ] } \ No newline at end of file diff --git a/src/main/resources/data/minecraft/tags/item/flowers.json b/src/main/resources/data/minecraft/tags/item/flowers.json index 09579714..16d5614b 100644 --- a/src/main/resources/data/minecraft/tags/item/flowers.json +++ b/src/main/resources/data/minecraft/tags/item/flowers.json @@ -1,6 +1,6 @@ { "replace": false, "values": [ - "jafohana:jade_vine" + "#jafohana:vine_flowers" ] } \ No newline at end of file diff --git a/src/main/resources/data/neoforge/data_maps/item/compostables.json b/src/main/resources/data/neoforge/data_maps/item/compostables.json index ac32532a..b33a12cd 100644 --- a/src/main/resources/data/neoforge/data_maps/item/compostables.json +++ b/src/main/resources/data/neoforge/data_maps/item/compostables.json @@ -6,7 +6,7 @@ "#jafohana:tall_flowers": { "chance": 0.65 }, - "jafohana:jade_vine": { + "#jafohana:vine_flowers": { "chance": 0.65 } } diff --git a/src/main/resources/data/sereneseasons/tags/block/unbreakable_infertile_crops.json b/src/main/resources/data/sereneseasons/tags/block/unbreakable_infertile_crops.json index 4d7f92d6..ff5536a8 100644 --- a/src/main/resources/data/sereneseasons/tags/block/unbreakable_infertile_crops.json +++ b/src/main/resources/data/sereneseasons/tags/block/unbreakable_infertile_crops.json @@ -4,6 +4,6 @@ "#jafohana:convertable_to_fasciated_dandelion", "#jafohana:convertable_to_fasciated_oxeye_daisy", "#jafohana:tall_flowers", - "jafohana:jade_vine" + "#jafohana:vine_flowers" ] } \ No newline at end of file