From 52fb6840addc13e958c1cb0cfcffd9c821d3515b Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Wed, 12 Jun 2024 00:12:07 +0200 Subject: [PATCH] fix: added check in injections and fixed modifiers interactions and Layer drops --- .../reframed/block/ReFramedBlock.java | 11 ---------- .../reframed/block/ReFramedDoorBlock.java | 2 +- .../reframed/block/ReFramedLayerBlock.java | 14 +++++++++++++ .../reframed/mixin/BlockItemMixin.java | 6 ++++++ .../reframed/util/blocks/BlockHelper.java | 5 ++--- .../util/blocks/ReframedInteractible.java | 20 ------------------- 6 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 src/main/java/fr/adrien1106/reframed/util/blocks/ReframedInteractible.java diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java index 0db4a18..236d4eb 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedBlock.java @@ -9,7 +9,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtHelper; import net.minecraft.registry.Registries; @@ -85,16 +84,6 @@ public class ReFramedBlock extends Block implements BlockEntityProvider { if(theme.getBlock() != Blocks.AIR) drops.add(new ItemStack(theme.getBlock())); }); - if(frame_entity.emitsRedstone() - && themes.stream().noneMatch(theme -> theme.getWeakRedstonePower(world, pos, Direction.NORTH) != 0)) - drops.add(new ItemStack(Items.REDSTONE_TORCH)); - if(frame_entity.emitsLight() - && themes.stream().noneMatch(theme -> theme.getLuminance() != 0)) - drops.add(new ItemStack(Items.GLOWSTONE_DUST)); - if(!frame_entity.isSolid() - && themes.stream().anyMatch(AbstractBlockState::isSolid)) - drops.add(new ItemStack(Items.POPPED_CHORUS_FRUIT)); - ItemScatterer.spawn(world, pos, drops); } super.onStateReplaced(state, world, pos, newState, moved); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedDoorBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedDoorBlock.java index 3fd988e..3c587b3 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedDoorBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedDoorBlock.java @@ -113,7 +113,7 @@ public class ReFramedDoorBlock extends WaterloggableReFramedBlock { @Override public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { - if (!world.isClient() && (player.isCreative() || !player.canHarvest(state))) { + if (!world.isClient() && (player.isCreative() || player.canHarvest(state))) { DoubleBlockHalf half = state.get(DOUBLE_BLOCK_HALF); BlockPos other_pos = half == DoubleBlockHalf.LOWER ? pos.up() : pos.down(); BlockState other_state = world.getBlockState(other_pos); diff --git a/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java b/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java index 2b0efe7..46d8037 100644 --- a/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java +++ b/src/main/java/fr/adrien1106/reframed/block/ReFramedLayerBlock.java @@ -6,6 +6,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ShapeContext; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.loot.context.LootContextParameterSet; import net.minecraft.state.StateManager; import net.minecraft.util.BlockMirror; import net.minecraft.util.BlockRotation; @@ -14,6 +16,8 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; import org.jetbrains.annotations.Nullable; +import java.util.List; + import static fr.adrien1106.reframed.util.VoxelHelper.VoxelListBuilder; import static net.minecraft.state.property.Properties.FACING; import static net.minecraft.state.property.Properties.LAYERS; @@ -27,6 +31,16 @@ public class ReFramedLayerBlock extends ReFramedSlabBlock { setDefaultState(getDefaultState().with(LAYERS, 1)); } + @Override + public List getDroppedStacks(BlockState state, LootContextParameterSet.Builder builder) { + List drops = super.getDroppedStacks(state, builder); + drops.forEach((stack) -> { + if (stack.getItem() instanceof BlockItem bi && bi.getBlock() instanceof ReFramedLayerBlock) + stack.setCount(state.get(LAYERS)); + }); + return drops; + } + @Override protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder.add(LAYERS)); diff --git a/src/main/java/fr/adrien1106/reframed/mixin/BlockItemMixin.java b/src/main/java/fr/adrien1106/reframed/mixin/BlockItemMixin.java index 7e081da..c7331a4 100644 --- a/src/main/java/fr/adrien1106/reframed/mixin/BlockItemMixin.java +++ b/src/main/java/fr/adrien1106/reframed/mixin/BlockItemMixin.java @@ -2,6 +2,7 @@ package fr.adrien1106.reframed.mixin; import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import fr.adrien1106.reframed.block.ReFramedBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; import net.minecraft.entity.player.PlayerEntity; @@ -9,6 +10,7 @@ import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtHelper; +import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -32,8 +34,12 @@ public class BlockItemMixin { private static void placeBlockWithOffHandCamo(World world, PlayerEntity player, BlockPos pos, ItemStack stack, CallbackInfoReturnable cir, @Local LocalRef compound) { if (compound.get() != null || player.getOffHandStack().isEmpty() + || player.getMainHandStack().isEmpty() + || !(player.getMainHandStack().getItem() instanceof BlockItem frame) + || !(frame.getBlock() instanceof ReFramedBlock) || !(player.getOffHandStack().getItem() instanceof BlockItem block) || block.getBlock() instanceof BlockEntityProvider + || (world.getBlockState(pos).contains(Properties.LAYERS) && world.getBlockState(pos).get(Properties.LAYERS) > 1) || !Block.isShapeFullCube(block.getBlock().getDefaultState().getCollisionShape(world, pos)) ) return; NbtCompound new_comp = new NbtCompound(); diff --git a/src/main/java/fr/adrien1106/reframed/util/blocks/BlockHelper.java b/src/main/java/fr/adrien1106/reframed/util/blocks/BlockHelper.java index 0306a1e..7de128d 100644 --- a/src/main/java/fr/adrien1106/reframed/util/blocks/BlockHelper.java +++ b/src/main/java/fr/adrien1106/reframed/util/blocks/BlockHelper.java @@ -188,7 +188,6 @@ public class BlockHelper { if(!(world.getBlockEntity(pos) instanceof ReFramedEntity block_entity)) return ActionResult.PASS; ItemStack held = player.getStackInHand(hand); - ReframedInteractible ext = state.getBlock() instanceof ReframedInteractible e ? e : ReframedInteractible.Default.INSTANCE; // frame will emit light if applied with glowstone if(state.contains(LIGHT) && held.getItem() == Items.GLOWSTONE_DUST) { @@ -199,14 +198,14 @@ public class BlockHelper { } // frame will emit redstone if applied with redstone torch can deactivate redstone block camo emission - if(held.getItem() == Items.REDSTONE_TORCH && ext.canAddRedstoneEmission(state, world, pos)) { + if(held.getItem() == Items.REDSTONE_TORCH) { block_entity.toggleRedstone(); world.playSound(player, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1f, 1f); return ActionResult.SUCCESS; } // Frame will lose its collision if applied with popped chorus fruit - if(held.getItem() == Items.POPPED_CHORUS_FRUIT && ext.canRemoveCollision(state, world, pos)) { + if(held.getItem() == Items.POPPED_CHORUS_FRUIT) { block_entity.toggleSolidity(); world.playSound(player, pos, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 1f, 1f); return ActionResult.SUCCESS; diff --git a/src/main/java/fr/adrien1106/reframed/util/blocks/ReframedInteractible.java b/src/main/java/fr/adrien1106/reframed/util/blocks/ReframedInteractible.java deleted file mode 100644 index 4209add..0000000 --- a/src/main/java/fr/adrien1106/reframed/util/blocks/ReframedInteractible.java +++ /dev/null @@ -1,20 +0,0 @@ -package fr.adrien1106.reframed.util.blocks; - -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; - -public interface ReframedInteractible { - default boolean canAddRedstoneEmission(BlockState state, BlockView view, BlockPos pos) { - return state.getWeakRedstonePower(view, pos, Direction.UP) == 0; - } - - default boolean canRemoveCollision(BlockState state, BlockView view, BlockPos pos) { - return !state.getCollisionShape(view, pos).isEmpty(); - } - - class Default implements ReframedInteractible { - public static final Default INSTANCE = new Default(); - } -}