From be579174f3c7c249ef49247eeeaafe3d2648f313 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Wed, 5 Feb 2025 15:31:30 -0800 Subject: [PATCH] Fix Silkworms not applying to certain modded leaves like TFC --- changelog.md | 1 + .../exdeorum/block/InfestedLeavesBlock.java | 9 ++++++++- .../exdeorum/blockentity/InfestedLeavesBlockEntity.java | 6 +----- .../java/thedarkcolour/exdeorum/item/SilkwormItem.java | 6 ++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/changelog.md b/changelog.md index dcc2815f..e087fad6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ ## Ex Deorum 3.6 - Implement custom Compressed Sieve types. Works the same as with sieves, just replace `sieve_materials` with `compressed_sieve_materials` +- Fix silkworms not applying to certain modded leaves like TFC ## Ex Deorum 3.5 - Remove Yellorium Dust sieve drop (#116) diff --git a/src/main/java/thedarkcolour/exdeorum/block/InfestedLeavesBlock.java b/src/main/java/thedarkcolour/exdeorum/block/InfestedLeavesBlock.java index 3e941e49..2daa3199 100644 --- a/src/main/java/thedarkcolour/exdeorum/block/InfestedLeavesBlock.java +++ b/src/main/java/thedarkcolour/exdeorum/block/InfestedLeavesBlock.java @@ -38,7 +38,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.HitResult; - import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.loading.FMLEnvironment; import org.jetbrains.annotations.Nullable; @@ -46,6 +45,7 @@ import thedarkcolour.exdeorum.blockentity.InfestedLeavesBlockEntity; import thedarkcolour.exdeorum.client.RenderUtil; import thedarkcolour.exdeorum.config.EConfig; import thedarkcolour.exdeorum.registry.EBlockEntities; +import thedarkcolour.exdeorum.registry.EBlocks; public class InfestedLeavesBlock extends LeavesBlock implements EntityBlock { public static final BooleanProperty FULLY_INFESTED = BooleanProperty.create("fully_infested"); @@ -55,6 +55,13 @@ public class InfestedLeavesBlock extends LeavesBlock implements EntityBlock { registerDefaultState(defaultBlockState().setValue(FULLY_INFESTED, false)); } + public static void setBlock(Level level, BlockPos pos, BlockState fromState) { + level.setBlock(pos, EBlocks.INFESTED_LEAVES.get().defaultBlockState() + .setValue(LeavesBlock.DISTANCE, fromState.hasProperty(LeavesBlock.DISTANCE) ? fromState.getValue(LeavesBlock.DISTANCE) : 0) + .setValue(LeavesBlock.PERSISTENT, fromState.hasProperty(LeavesBlock.PERSISTENT) ? fromState.getValue(LeavesBlock.PERSISTENT) : false), + 2); + } + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); diff --git a/src/main/java/thedarkcolour/exdeorum/blockentity/InfestedLeavesBlockEntity.java b/src/main/java/thedarkcolour/exdeorum/blockentity/InfestedLeavesBlockEntity.java index 646f13ea..aee02821 100644 --- a/src/main/java/thedarkcolour/exdeorum/blockentity/InfestedLeavesBlockEntity.java +++ b/src/main/java/thedarkcolour/exdeorum/blockentity/InfestedLeavesBlockEntity.java @@ -28,7 +28,6 @@ import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.tags.BlockTags; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.state.BlockState; @@ -92,10 +91,7 @@ public class InfestedLeavesBlockEntity extends EBlockEntity { // DO NOT SPREAD TO ALREADY INFESTED LEAVES if (state.is(BlockTags.LEAVES) && state.getBlock() != EBlocks.INFESTED_LEAVES.get()) { // Spread and keep distance/persistent properties - level.setBlock(targetPos, EBlocks.INFESTED_LEAVES.get().defaultBlockState() - .setValue(LeavesBlock.DISTANCE, state.getValue(LeavesBlock.DISTANCE)) - .setValue(LeavesBlock.PERSISTENT, state.getValue(LeavesBlock.PERSISTENT)), - 2); + InfestedLeavesBlock.setBlock(level, targetPos, state); var te = level.getBlockEntity(targetPos); // Set mimic state of other block diff --git a/src/main/java/thedarkcolour/exdeorum/item/SilkwormItem.java b/src/main/java/thedarkcolour/exdeorum/item/SilkwormItem.java index 8ce3be24..d7d1b48e 100644 --- a/src/main/java/thedarkcolour/exdeorum/item/SilkwormItem.java +++ b/src/main/java/thedarkcolour/exdeorum/item/SilkwormItem.java @@ -25,7 +25,7 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; -import net.minecraft.world.level.block.LeavesBlock; +import thedarkcolour.exdeorum.block.InfestedLeavesBlock; import thedarkcolour.exdeorum.blockentity.InfestedLeavesBlockEntity; import thedarkcolour.exdeorum.registry.EBlocks; import thedarkcolour.exdeorum.registry.ESounds; @@ -45,9 +45,7 @@ public class SilkwormItem extends Item { if (state.is(BlockTags.LEAVES) && state.getBlock() != EBlocks.INFESTED_LEAVES.get()) { if (!level.isClientSide) { // Replace with infested block - level.setBlock(pos, EBlocks.INFESTED_LEAVES.get().defaultBlockState() - .setValue(LeavesBlock.DISTANCE, state.getValue(LeavesBlock.DISTANCE)) - .setValue(LeavesBlock.PERSISTENT, state.getValue(LeavesBlock.PERSISTENT)), 2); + InfestedLeavesBlock.setBlock(level, pos, state); level.playSound(null, pos, ESounds.SILK_WORM_INFEST.get(), SoundSource.BLOCKS);