154 lines
7.7 KiB
Diff
154 lines
7.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Wed, 23 Jul 2025 20:28:40 +0800
|
|
Subject: [PATCH] Leaves: Redstone Shears Wrench
|
|
|
|
Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
As a part of : Leaves (https://github.com/LeavesMC/Leaves/blob/bfde470a867b74d177fe1b9a2a3ed5c49cd126c7/leaves-server/minecraft-patches/features/0009-Redstone-Shears-Wrench.patch)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
diff --git a/net/minecraft/world/item/ShearsItem.java b/net/minecraft/world/item/ShearsItem.java
|
|
index 8cf3e51e12f9cf98836657e722edb23943f9e866..155693a18bb641a930a000bc9b1ccfc853e1bae5 100644
|
|
--- a/net/minecraft/world/item/ShearsItem.java
|
|
+++ b/net/minecraft/world/item/ShearsItem.java
|
|
@@ -24,6 +24,30 @@ import net.minecraft.world.level.block.GrowingPlantHeadBlock;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
|
|
+// Leaves start - shears wrench
|
|
+import net.minecraft.Util;
|
|
+import net.minecraft.network.chat.Component;
|
|
+import net.minecraft.world.level.block.ComparatorBlock;
|
|
+import net.minecraft.world.level.block.DispenserBlock;
|
|
+import net.minecraft.world.level.block.HopperBlock;
|
|
+import net.minecraft.world.level.block.ObserverBlock;
|
|
+import net.minecraft.world.level.block.RepeaterBlock;
|
|
+import net.minecraft.world.level.block.CrafterBlock;
|
|
+import net.minecraft.world.level.block.LeverBlock;
|
|
+import net.minecraft.world.level.block.CocoaBlock;
|
|
+import net.minecraft.world.level.block.TrapDoorBlock;
|
|
+import net.minecraft.world.level.block.FenceGateBlock;
|
|
+import net.minecraft.world.level.block.LightningRodBlock;
|
|
+import net.minecraft.world.level.block.RailBlock;
|
|
+import net.minecraft.world.level.block.BaseRailBlock;
|
|
+import net.minecraft.world.level.block.PoweredRailBlock;
|
|
+import net.minecraft.world.level.block.CalibratedSculkSensorBlock;
|
|
+import net.minecraft.world.level.block.piston.PistonBaseBlock;
|
|
+import net.minecraft.world.level.block.state.StateDefinition;
|
|
+import net.minecraft.world.level.block.state.properties.RailShape;
|
|
+import net.minecraft.world.level.block.state.properties.Property;
|
|
+// Leaves end - shears wrench
|
|
+
|
|
public class ShearsItem extends Item {
|
|
public ShearsItem(Item.Properties properties) {
|
|
super(properties);
|
|
@@ -80,7 +104,108 @@ public class ShearsItem extends Item {
|
|
|
|
return InteractionResult.SUCCESS;
|
|
} else {
|
|
+ // Leaves start - shears wrench
|
|
+ Block block = blockState.getBlock();
|
|
+ if (fun.bm.lophine.config.modules.misc.RedStoneConfig.shears && (
|
|
+ block instanceof ObserverBlock ||
|
|
+ block instanceof DispenserBlock ||
|
|
+ block instanceof PistonBaseBlock ||
|
|
+ block instanceof HopperBlock ||
|
|
+ block instanceof RepeaterBlock ||
|
|
+ block instanceof ComparatorBlock ||
|
|
+ block instanceof CrafterBlock ||
|
|
+ block instanceof LeverBlock ||
|
|
+ block instanceof CocoaBlock ||
|
|
+ block instanceof TrapDoorBlock ||
|
|
+ block instanceof FenceGateBlock ||
|
|
+ block instanceof LightningRodBlock ||
|
|
+ block instanceof CalibratedSculkSensorBlock ||
|
|
+ block instanceof BaseRailBlock
|
|
+ )) {
|
|
+ StateDefinition<Block, BlockState> blockstatelist = block.getStateDefinition();
|
|
+ Property<?> iblockstate;
|
|
+ if (block instanceof CrafterBlock) iblockstate = blockstatelist.getProperty("orientation");
|
|
+ else if (block instanceof BaseRailBlock) iblockstate = blockstatelist.getProperty("shape");
|
|
+ else iblockstate = blockstatelist.getProperty("facing");
|
|
+ Player player = context.getPlayer();
|
|
+
|
|
+ if (iblockstate == null || player == null) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+
|
|
+ if (block instanceof BaseRailBlock) {
|
|
+ if (block instanceof RailBlock) {
|
|
+ if (blockState.getValue(RailBlock.SHAPE).isSlope()) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ } else {
|
|
+ if (getNameHelper(blockState, PoweredRailBlock.POWERED).equals("true")) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ if (blockState.getValue(PoweredRailBlock.SHAPE).isSlope()) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (block instanceof PistonBaseBlock) {
|
|
+ if (getNameHelper(blockState, PistonBaseBlock.EXTENDED).equals("true")) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (block instanceof RepeaterBlock || block instanceof ComparatorBlock) {
|
|
+ if (getNameHelper(blockState, ComparatorBlock.POWERED).equals("true")) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ if (block instanceof RepeaterBlock) {
|
|
+ if (getNameHelper(blockState, RepeaterBlock.LOCKED).equals("true")) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (block instanceof CrafterBlock) {
|
|
+ if (getNameHelper(blockState, CrafterBlock.CRAFTING).equals("true")) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ BlockState iblockdata1 = ShearsItem.cycleState(blockState, iblockstate, player.isSecondaryUseActive());
|
|
+ level.setBlock(clickedPos, iblockdata1, 18);
|
|
+ ShearsItem.message(player, Component.translatable("item.minecraft.debug_stick.update", iblockstate.getName(), ShearsItem.getNameHelper(iblockdata1, iblockstate)));
|
|
+ return InteractionResult.CONSUME;
|
|
+ }
|
|
+ // Leaves end - shears wrench
|
|
+
|
|
return super.useOn(context);
|
|
}
|
|
}
|
|
+
|
|
+ // Leaves start - shears wrench
|
|
+ private static <T extends Comparable<T>> BlockState cycleState(BlockState state, Property<T> property, boolean inverse) {
|
|
+ List<T> possibleValues = property.getPossibleValues();
|
|
+ if (possibleValues.getFirst() instanceof RailShape) {
|
|
+ boolean isRailBlock = state.getBlock() instanceof RailBlock;
|
|
+ possibleValues = possibleValues.stream().filter(possibleValue -> {
|
|
+ RailShape shape = (RailShape) possibleValue;
|
|
+ if (isRailBlock) return !shape.isSlope();
|
|
+ return !shape.isSlope() && shape != RailShape.NORTH_EAST && shape != RailShape.NORTH_WEST && shape != RailShape.SOUTH_EAST && shape != RailShape.SOUTH_WEST;
|
|
+ }).toList();
|
|
+ }
|
|
+ return state.setValue(property, ShearsItem.getRelative(possibleValues, state.getValue(property), inverse)); // CraftBukkit - decompile error
|
|
+ }
|
|
+
|
|
+ private static <T> T getRelative(Iterable<T> elements, T current, boolean inverse) {
|
|
+ return inverse ? Util.findPreviousInIterable(elements, current) : Util.findNextInIterable(elements, current);
|
|
+ }
|
|
+
|
|
+ private static void message(Player player, Component message) {
|
|
+ ((ServerPlayer) player).sendSystemMessage(message, true);
|
|
+ }
|
|
+
|
|
+ private static <T extends Comparable<T>> String getNameHelper(BlockState state, Property<T> property) {
|
|
+ return property.getName(state.getValue(property));
|
|
+ }
|
|
+ // Leaves end - shears wrench
|
|
}
|