9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-23 17:09:26 +00:00
Files
LeavesMC/patches/server/0006-Player-can-edit-sign.patch
2022-01-28 10:10:25 +08:00

83 lines
4.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Thu, 27 Jan 2022 20:11:05 +0800
Subject: [PATCH] Player can edit sign
diff --git a/src/main/java/net/minecraft/world/level/block/SignBlock.java b/src/main/java/net/minecraft/world/level/block/SignBlock.java
index ed3d78494735ceda14ad0ea23adeadc374f3b35e..d0e9fd987687d6a0642a9e312668697f98106a0a 100644
--- a/src/main/java/net/minecraft/world/level/block/SignBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/SignBlock.java
@@ -3,6 +3,7 @@ package net.minecraft.world.level.block;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
+import net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
@@ -73,6 +74,7 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
boolean bl2 = itemStack.is(Items.GLOW_INK_SAC);
boolean bl3 = itemStack.is(Items.INK_SAC);
boolean bl4 = (bl2 || bl || bl3) && player.getAbilities().mayBuild;
+ boolean bl7 = itemStack.is(Items.AIR); // Leaves - Player can edit sign
if (world.isClientSide) {
return bl4 ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
} else {
@@ -82,6 +84,14 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
} else {
SignBlockEntity signBlockEntity = (SignBlockEntity)blockEntity;
boolean bl5 = signBlockEntity.hasGlowingText();
+ // Leaves start - Player can edit sign
+ if (top.leavesmc.leaves.LeavesConfig.playerCanEditSign && bl7 && !signBlockEntity.isEditable) {
+ signBlockEntity.setEditable(true);
+ signBlockEntity.setAllowedPlayerEditor(player.getUUID());
+ ((ServerPlayer) player).connection.send(new ClientboundOpenSignEditorPacket(pos));
+ return InteractionResult.SUCCESS;
+ }
+ // Leaves end - Player can edit sign
if ((!bl2 || !bl5) && (!bl3 || bl5)) {
if (bl4) {
boolean bl6;
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
index 3a7a390f06577720f713e98eb78cc1b6e59548d3..2f8969d20a17ee307f9881da5211b00292ecbb15 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -56,7 +56,7 @@ public final class LeavesConfig {
for (final Method method : LeavesConfig.class.getDeclaredMethods()) {
if (method.getReturnType() != void.class || method.getParameterCount() != 0 ||
- !Modifier.isPrivate(method.getModifiers()) || !Modifier.isStatic(method.getModifiers())) {
+ !Modifier.isPrivate(method.getModifiers()) || !Modifier.isStatic(method.getModifiers())) {
continue;
}
@@ -81,6 +81,11 @@ public final class LeavesConfig {
LeavesConfig.config.set(path, value);
}
+ public static boolean playerCanEditSign = true;
+ private static void playerCanEditSign() {
+ playerCanEditSign = getBoolean("settings.player-can-edit-sign", playerCanEditSign);
+ }
+
static boolean getBoolean(final String path, final boolean dfl) {
LeavesConfig.config.addDefault(path, Boolean.valueOf(dfl));
return LeavesConfig.config.getBoolean(path, dfl);
@@ -139,7 +144,7 @@ public final class LeavesConfig {
public void load() {
for (final Method method : LeavesConfig.WorldConfig.class.getDeclaredMethods()) {
if (method.getReturnType() != void.class || method.getParameterCount() != 0 ||
- !Modifier.isPrivate(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
+ !Modifier.isPrivate(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
continue;
}
@@ -280,4 +285,4 @@ public final class LeavesConfig {
return config == null ? this.worldDefaults.getList(path, dfl) : config.getList(path, this.worldDefaults.getList(path, dfl));
}
}
-}
\ No newline at end of file
+}