Skip to content

Commit

Permalink
Fix Silkworms not applying to certain modded leaves like TFC
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkcolour committed Nov 19, 2024
1 parent 1c317f2 commit 903913c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Ex Deorum 1.44
- Fix Silkworms not applying to certain modded leaves like TFC

## Ex Deorum 1.43
- Fix sieve recipe bug with latest version of JEI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
package thedarkcolour.exdeorum.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.BlockParticleOption;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
Expand All @@ -42,14 +38,14 @@
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.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.loading.FMLEnvironment;
import org.jetbrains.annotations.Nullable;
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");
Expand All @@ -59,6 +55,13 @@ public InfestedLeavesBlock(Properties properties) {
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<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@
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.BlockEntityTicker;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.client.model.data.ModelProperty;
import org.jetbrains.annotations.NotNull;
import thedarkcolour.exdeorum.block.InfestedLeavesBlock;
import thedarkcolour.exdeorum.registry.EBlockEntities;
import thedarkcolour.exdeorum.registry.EBlocks;
Expand Down Expand Up @@ -76,10 +72,7 @@ private void trySpread(Level level) {
// 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.hasProperty(LeavesBlock.DISTANCE) ? state.getValue(LeavesBlock.DISTANCE) : 0)
.setValue(LeavesBlock.PERSISTENT, state.hasProperty(LeavesBlock.PERSISTENT) ? state.getValue(LeavesBlock.PERSISTENT) : false),
2);
InfestedLeavesBlock.setBlock(level, targetPos, state);
var te = level.getBlockEntity(targetPos);

// Set mimic state of other block
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/thedarkcolour/exdeorum/item/SilkWormItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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;
Expand All @@ -45,9 +45,7 @@ public InteractionResult useOn(UseOnContext context) {
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);

Expand Down

0 comments on commit 903913c

Please sign in to comment.