mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
* Fix #690 * Clean up * Remove useless check * 1 long line * Reformat
This commit is contained in:
@@ -4,147 +4,38 @@ Date: Sun, 27 Mar 2022 12:48:40 +0800
|
||||
Subject: [PATCH] Redstone Shears Wrench
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||
index 6db566adf2d0df1d26221eda04aa01738df6d3d2..24ebfdf98e343a7892af621d032c35819156deec 100644
|
||||
--- a/net/minecraft/world/item/BlockItem.java
|
||||
+++ b/net/minecraft/world/item/BlockItem.java
|
||||
@@ -56,6 +56,14 @@ public class BlockItem extends Item {
|
||||
if (blockPlaceContext == null) {
|
||||
return InteractionResult.FAIL;
|
||||
} else {
|
||||
+ // Leaves start - shears wrench
|
||||
+ if (org.leavesmc.leaves.util.ShearsWrenchUtil.shouldSkipPlace(context)) {
|
||||
+ if (context.getPlayer() != null) {
|
||||
+ context.getPlayer().containerMenu.forceHeldSlot(blockPlaceContext.getHand());
|
||||
+ }
|
||||
+ return InteractionResult.FAIL;
|
||||
+ }
|
||||
+ // Leaves end - shears wrench
|
||||
BlockState placementState = this.getPlacementState(blockPlaceContext);
|
||||
// CraftBukkit start - special case for handling block placement with water lilies and snow buckets
|
||||
org.bukkit.block.BlockState bukkitState = null;
|
||||
diff --git a/net/minecraft/world/item/ShearsItem.java b/net/minecraft/world/item/ShearsItem.java
|
||||
index 8cf3e51e12f9cf98836657e722edb23943f9e866..7c9b48271012b5d0162ce7e3831384263e478186 100644
|
||||
index 8cf3e51e12f9cf98836657e722edb23943f9e866..5fd5e9fd4e1a79dd1a9d62a5cf0c308805979420 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 {
|
||||
@@ -80,7 +80,10 @@ public class ShearsItem extends Item {
|
||||
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
- return super.useOn(context);
|
||||
+ // Leaves start - shears wrench
|
||||
+ Block block = blockState.getBlock();
|
||||
+ if (org.leavesmc.leaves.LeavesConfig.modify.redstoneShearsWrench && (
|
||||
+ 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;
|
||||
+ }
|
||||
+ InteractionResult result = org.leavesmc.leaves.util.ShearsWrenchUtil.tryApplyRotate(context, blockState);
|
||||
+ return result == null ? super.useOn(context) : result;
|
||||
+ // 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
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ MasaGadget(https://github.com/plusls/MasaGadget)
|
||||
litematica(https://github.com/maruohon/litematica)
|
||||
|
||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||
index 6db566adf2d0df1d26221eda04aa01738df6d3d2..8f112f382190d606a87f38da8bcdf8dd5f31d1c5 100644
|
||||
index 24ebfdf98e343a7892af621d032c35819156deec..8eafee0225377d53650435091c4b1d865e0d487b 100644
|
||||
--- a/net/minecraft/world/item/BlockItem.java
|
||||
+++ b/net/minecraft/world/item/BlockItem.java
|
||||
@@ -149,7 +149,7 @@ public class BlockItem extends Item {
|
||||
@@ -157,7 +157,7 @@ public class BlockItem extends Item {
|
||||
|
||||
@Nullable
|
||||
protected BlockState getPlacementState(BlockPlaceContext context) {
|
||||
|
||||
@@ -85,10 +85,10 @@ index cfbf34964288526e93d0a5b212c1b60296c10430..9cce442c16ced8d9320a5760580ff13f
|
||||
this.debugLogging(pos, true, sequence, message);
|
||||
} else {
|
||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||
index 8f112f382190d606a87f38da8bcdf8dd5f31d1c5..a46a50d1385897cc7fcf0d6976f0de7e8078d260 100644
|
||||
index 8eafee0225377d53650435091c4b1d865e0d487b..bf5ecf388b2ae69a0b093f65acf2169ae9488c4b 100644
|
||||
--- a/net/minecraft/world/item/BlockItem.java
|
||||
+++ b/net/minecraft/world/item/BlockItem.java
|
||||
@@ -65,6 +65,21 @@ public class BlockItem extends Item {
|
||||
@@ -73,6 +73,21 @@ public class BlockItem extends Item {
|
||||
final org.bukkit.block.BlockState oldBukkitState = bukkitState != null ? bukkitState : org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockPlaceContext.getLevel(), blockPlaceContext.getClickedPos()); // Paper - Reset placed block on exception
|
||||
// CraftBukkit end
|
||||
|
||||
|
||||
@@ -69,10 +69,10 @@ index 8ec6f52f58bcc985fdc758a692798a35d6c86378..9e6929e84a4422daa3cd4c92ae641871
|
||||
|
||||
@Override
|
||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||
index a46a50d1385897cc7fcf0d6976f0de7e8078d260..593e65ef3a768d4039047e42e666c8382a5d38eb 100644
|
||||
index bf5ecf388b2ae69a0b093f65acf2169ae9488c4b..a6e15400b927cab2295c14d617c6157ca34252e4 100644
|
||||
--- a/net/minecraft/world/item/BlockItem.java
|
||||
+++ b/net/minecraft/world/item/BlockItem.java
|
||||
@@ -185,8 +185,9 @@ public class BlockItem extends Item {
|
||||
@@ -193,8 +193,9 @@ public class BlockItem extends Item {
|
||||
protected boolean canPlace(BlockPlaceContext context, BlockState state) {
|
||||
Player player = context.getPlayer();
|
||||
// CraftBukkit start
|
||||
|
||||
@@ -5,10 +5,10 @@ Subject: [PATCH] Do not reset placed block on exception
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/item/BlockItem.java b/net/minecraft/world/item/BlockItem.java
|
||||
index 593e65ef3a768d4039047e42e666c8382a5d38eb..cf143589407dc2146c9ce18f509077017fba0b48 100644
|
||||
index a6e15400b927cab2295c14d617c6157ca34252e4..7ddbf7d600120b992a04364fe03675d4e216f3ec 100644
|
||||
--- a/net/minecraft/world/item/BlockItem.java
|
||||
+++ b/net/minecraft/world/item/BlockItem.java
|
||||
@@ -92,20 +92,22 @@ public class BlockItem extends Item {
|
||||
@@ -100,20 +100,22 @@ public class BlockItem extends Item {
|
||||
BlockState blockState = level.getBlockState(clickedPos);
|
||||
if (blockState.is(placementState.getBlock())) {
|
||||
blockState = this.updateBlockStateFromTag(clickedPos, level, itemInHand, blockState);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package org.leavesmc.leaves.util;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.piston.PistonBaseBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.block.state.properties.RailShape;
|
||||
import org.leavesmc.leaves.LeavesConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ShearsWrenchUtil {
|
||||
|
||||
public static InteractionResult tryApplyRotate(UseOnContext context, BlockState blockState) {
|
||||
Level level = context.getLevel();
|
||||
BlockPos clickedPos = context.getClickedPos();
|
||||
Block block = blockState.getBlock();
|
||||
if (!LeavesConfig.modify.redstoneShearsWrench || !(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)) {
|
||||
return null;
|
||||
}
|
||||
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 = cycleState(blockState, iblockstate, player.isSecondaryUseActive());
|
||||
level.setBlock(clickedPos, iblockdata1, 18);
|
||||
message(player, Component.translatable("item.minecraft.debug_stick.update", iblockstate.getName(), getNameHelper(iblockdata1, iblockstate)));
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
public static boolean shouldSkipPlace(BlockPlaceContext context) {
|
||||
return LeavesConfig.modify.redstoneShearsWrench &&
|
||||
context.getPlayer() != null &&
|
||||
context.getPlayer().getItemInHand(InteractionHand.MAIN_HAND).is(Items.SHEARS);
|
||||
}
|
||||
|
||||
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, 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user