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 1f6bba371f827c1151984f8dc89cc461973988b9..d5cc421b0fb4739ccaa57ae8b7bc2b7a27f2f391 100644 --- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java +++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java @@ -112,6 +112,11 @@ public final class LeavesConfig { return LeavesConfig.config.getString(path, dfl); } + public static boolean playerCanEditSign = true; + private static void playerCanEditSign() { + playerCanEditSign = getBoolean("settings.player-can-edit-sign", playerCanEditSign); + } + public static final class WorldConfig { public final String worldName; @@ -145,7 +150,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; }