From b3132ef1f1ad9d6a3a4e376f6a933b3b03733345 Mon Sep 17 00:00:00 2001 From: Forstride Date: Tue, 9 Jan 2024 16:33:25 -0500 Subject: [PATCH] Flesh blocks now slowly grow flesh decorations (Hair, Flesh Tendons, etc.) when adjacent to Blood source blocks. Flesh blocks can also now be crafted with Rotten Flesh and Blood Buckets --- .../common/block/FleshBlock.java | 95 +++++++++++++++++++ .../java/biomesoplenty/init/ModBlocks.java | 4 +- .../recipes/building_blocks/flesh.json | 33 +++++++ .../data/biomesoplenty/recipes/flesh.json | 19 ++++ 4 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/data/biomesoplenty/advancements/recipes/building_blocks/flesh.json create mode 100644 src/main/resources/data/biomesoplenty/recipes/flesh.json diff --git a/src/main/java/biomesoplenty/common/block/FleshBlock.java b/src/main/java/biomesoplenty/common/block/FleshBlock.java index 6f67ab964..dc696e9a3 100644 --- a/src/main/java/biomesoplenty/common/block/FleshBlock.java +++ b/src/main/java/biomesoplenty/common/block/FleshBlock.java @@ -4,11 +4,28 @@ ******************************************************************************/ package biomesoplenty.common.block; +import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.block.BOPFluids; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.stats.Stats; +import net.minecraft.util.RandomSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.DoublePlantBlock; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.BlockHitResult; public class FleshBlock extends Block { @@ -22,4 +39,82 @@ public void stepOn(Level worldIn, BlockPos pos, BlockState blockState, Entity en { entityIn.setDeltaMovement(entityIn.getDeltaMovement().multiply(0.95D, 1.0D, 0.95D)); } + + @Override + public void randomTick(BlockState state, ServerLevel worldIn, BlockPos pos, RandomSource p_221787_) + { + boolean bloodAdjacent = false; + for (Direction direction : Direction.values()) + { + if (worldIn.getFluidState(pos.relative(direction)).is(BOPFluids.BLOOD.get())) + { + bloodAdjacent = true; + } + } + + if (bloodAdjacent && p_221787_.nextInt(15) == 0) + { + switch (p_221787_.nextInt(4)) + { + default: + case 0: + if (worldIn.isEmptyBlock(pos.above())) + { + worldIn.setBlock(pos.above(), BOPBlocks.HAIR.get().defaultBlockState(), 2); + } + break; + + case 1: + if (worldIn.isEmptyBlock(pos.above())) + { + worldIn.setBlock(pos.above(), BOPBlocks.PUS_BUBBLE.get().defaultBlockState(), 2); + } + break; + + case 2: + if (worldIn.isEmptyBlock(pos.above()) && worldIn.isEmptyBlock(pos.above(2))) + { + DoublePlantBlock.placeAt(worldIn, BOPBlocks.EYEBULB.get().defaultBlockState(), pos.above(), 2); + } + break; + + case 3: + if (worldIn.isEmptyBlock(pos.below())) + { + worldIn.setBlock(pos.below(), BOPBlocks.FLESH_TENDONS.get().defaultBlockState(), 2); + } + break; + } + } + } + + @Override + public InteractionResult use(BlockState p_55289_, Level p_55290_, BlockPos p_55291_, Player p_55292_, InteractionHand p_55293_, BlockHitResult p_55294_) + { + ItemStack itemstack = p_55292_.getItemInHand(p_55293_); + if (p_55289_.getBlock() == BOPBlocks.FLESH.get() && itemstack.canPerformAction(net.minecraftforge.common.ToolActions.SHEARS_CARVE)) + { + if (!p_55290_.isClientSide) + { + Direction direction = p_55294_.getDirection(); + Direction direction1 = direction.getAxis() == Direction.Axis.Y ? p_55292_.getDirection().getOpposite() : direction; + p_55290_.playSound((Player)null, p_55291_, SoundEvents.PUMPKIN_CARVE, SoundSource.BLOCKS, 1.0F, 1.0F); + p_55290_.setBlock(p_55291_, BOPBlocks.POROUS_FLESH.get().defaultBlockState(), 11); + ItemEntity itementity = new ItemEntity(p_55290_, (double)p_55291_.getX() + 0.5D + (double)direction1.getStepX() * 0.65D, (double)p_55291_.getY() + 0.1D, (double)p_55291_.getZ() + 0.5D + (double)direction1.getStepZ() * 0.65D, new ItemStack(Items.ROTTEN_FLESH, 1)); + itementity.setDeltaMovement(0.05D * (double)direction1.getStepX() + p_55290_.random.nextDouble() * 0.02D, 0.05D, 0.05D * (double)direction1.getStepZ() + p_55290_.random.nextDouble() * 0.02D); + p_55290_.addFreshEntity(itementity); + itemstack.hurtAndBreak(1, p_55292_, (p_55287_) -> { + p_55287_.broadcastBreakEvent(p_55293_); + }); + p_55290_.gameEvent(p_55292_, GameEvent.SHEAR, p_55291_); + p_55292_.awardStat(Stats.ITEM_USED.get(Items.SHEARS)); + } + + return InteractionResult.sidedSuccess(p_55290_.isClientSide); + } + else + { + return super.use(p_55289_, p_55290_, p_55291_, p_55292_, p_55293_, p_55294_); + } + } } diff --git a/src/main/java/biomesoplenty/init/ModBlocks.java b/src/main/java/biomesoplenty/init/ModBlocks.java index 21859b55a..2a7a9f5f4 100644 --- a/src/main/java/biomesoplenty/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/init/ModBlocks.java @@ -105,8 +105,8 @@ public static void registerBlocks() THERMAL_CALCITE = registerBlock(() -> new ThermalCalciteBlock(BlockBehaviour.Properties.of().mapColor((blockState) -> blockState.getValue(ThermalCalciteBlock.DISTANCE) == 1 ? tc1 : blockState.getValue(ThermalCalciteBlock.DISTANCE) == 2 ? tc2 : blockState.getValue(ThermalCalciteBlock.DISTANCE) == 3 ? tc3 : blockState.getValue(ThermalCalciteBlock.DISTANCE) == 4 ? tc4 : tc5).instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.CALCITE).requiresCorrectToolForDrops().strength(0.75F)), "thermal_calcite"); THERMAL_CALCITE_VENT = registerBlock(() -> new ThermalCalciteVentBlock(BlockBehaviour.Properties.of().mapColor((blockState) -> blockState.getValue(ThermalCalciteBlock.DISTANCE) == 1 ? tc1 : blockState.getValue(ThermalCalciteBlock.DISTANCE) == 2 ? tc2 : blockState.getValue(ThermalCalciteBlock.DISTANCE) == 3 ? tc3 : blockState.getValue(ThermalCalciteBlock.DISTANCE) == 4 ? tc4 : tc5).instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.CALCITE).requiresCorrectToolForDrops().strength(0.75F)), "thermal_calcite_vent"); - FLESH = registerBlock(() -> new FleshBlock(BlockBehaviour.Properties.of().mapColor(MapColor.TERRACOTTA_RED).strength(0.4F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL))), "flesh"); - POROUS_FLESH = registerBlock(() -> new FleshBlock(BlockBehaviour.Properties.of().mapColor(MapColor.TERRACOTTA_RED).strength(0.4F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL))), "porous_flesh"); + FLESH = registerBlock(() -> new FleshBlock(BlockBehaviour.Properties.of().randomTicks().mapColor(MapColor.TERRACOTTA_RED).strength(0.4F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL))), "flesh"); + POROUS_FLESH = registerBlock(() -> new FleshBlock(BlockBehaviour.Properties.of().randomTicks().mapColor(MapColor.TERRACOTTA_RED).strength(0.4F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL))), "porous_flesh"); FLESH_TENDONS = registerBlock(() -> new FleshTendonsBottomBlock(BlockBehaviour.Properties.of().pushReaction(PushReaction.DESTROY).mapColor(MapColor.TERRACOTTA_RED).noCollission().strength(0.2F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL))), "flesh_tendons"); FLESH_TENDONS_STRAND = registerBlock(() -> new FleshTendonsBlock(BlockBehaviour.Properties.of().pushReaction(PushReaction.DESTROY).mapColor(MapColor.TERRACOTTA_RED).noCollission().strength(0.2F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL))), "flesh_tendons_strand"); EYEBULB = registerBlock(() -> new EyebulbBlock(BlockBehaviour.Properties.of().pushReaction(PushReaction.DESTROY).mapColor(MapColor.TERRACOTTA_RED).pushReaction(PushReaction.DESTROY).noCollission().strength(0.2F).sound(new SoundType(1.0F, 0.5F, SoundEvents.CORAL_BLOCK_BREAK, SoundEvents.CORAL_BLOCK_STEP, SoundEvents.CORAL_BLOCK_PLACE, SoundEvents.CORAL_BLOCK_HIT, SoundEvents.CORAL_BLOCK_FALL)).offsetType(BlockBehaviour.OffsetType.NONE)), "eyebulb"); diff --git a/src/main/resources/data/biomesoplenty/advancements/recipes/building_blocks/flesh.json b/src/main/resources/data/biomesoplenty/advancements/recipes/building_blocks/flesh.json new file mode 100644 index 000000000..c5fd3cb5b --- /dev/null +++ b/src/main/resources/data/biomesoplenty/advancements/recipes/building_blocks/flesh.json @@ -0,0 +1,33 @@ +{ + "rewards": { + "recipes": [ + "biomesoplenty:flesh" + ] + }, + "criteria": { + "has_the_recipe": { + "trigger": "minecraft:recipe_unlocked", + "conditions": { + "recipe": "biomesoplenty:flesh" + } + }, + "has_blood_bucket": { + "trigger": "minecraft:inventory_changed", + "conditions": { + "items": [ + { + "items": [ + "biomesoplenty:blood_bucket" + ] + } + ] + } + } + }, + "requirements": [ + [ + "has_the_recipe", + "has_blood_bucket" + ] + ] +} \ No newline at end of file diff --git a/src/main/resources/data/biomesoplenty/recipes/flesh.json b/src/main/resources/data/biomesoplenty/recipes/flesh.json new file mode 100644 index 000000000..bb9985be7 --- /dev/null +++ b/src/main/resources/data/biomesoplenty/recipes/flesh.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " R ", + "RBR", + " R " + ], + "key": { + "R": { + "item": "minecraft:rotten_flesh" + }, + "B": { + "item": "biomesoplenty:blood_bucket" + } + }, + "result": { + "item": "biomesoplenty:flesh" + } +} \ No newline at end of file