9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00

Make player can edit sign

This commit is contained in:
violetc
2022-01-27 20:13:17 +08:00
parent 499af5be6a
commit b55d29bbab

View File

@@ -0,0 +1,62 @@
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..1f6a310f228386a2bfbe243da323bfe3545f0a19 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);
if (world.isClientSide) {
return bl4 ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
} else {
@@ -82,6 +84,12 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
} else {
SignBlockEntity signBlockEntity = (SignBlockEntity)blockEntity;
boolean bl5 = signBlockEntity.hasGlowingText();
+ 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;
+ }
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..d885749ce15ab55d12f23c67bd2096f9859a7593 100644
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -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);
@@ -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
+}