From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:27:24 +0800 Subject: [PATCH] No block update command diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index f10018a3f79744ce0c78ee3020ec0f5d95b1ed4d..542531451c63392262fa81ec62ff7143e455e04c 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -2298,6 +2298,7 @@ public class ServerLevel extends Level implements WorldGenLevel, ca.spottedleaf. @Override public void blockUpdated(BlockPos pos, Block block) { + if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update if (!this.isDebug()) { // CraftBukkit start if (this.populating) { diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java index 4a790406e8031feba3b8bdc6e2fb9d17d1a7fbff..8302dad8ce041ca51f860e2ca0d556b1cf16ba29 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java +++ b/src/main/java/net/minecraft/world/item/ItemStack.java @@ -527,7 +527,7 @@ public final class ItemStack implements DataComponentHolder { net.minecraft.world.level.block.state.BlockState block = world.getBlockState(newblockposition); if (!(block.getBlock() instanceof BaseEntityBlock)) { // Containers get placed automatically - block.onPlace(world, newblockposition, oldBlock, true, context); + if (!org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) block.onPlace(world, newblockposition, oldBlock, true, context); // Leaves - no block update } world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java index 382ca565fe1a680ab49b14ac90e4ec3bd903450d..ce5964c1a53b362bcc5fb735684b78c96609cb86 100644 --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java @@ -403,7 +403,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p } else { // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled. if (!this.level.isClientSide && doPlace && (!this.level.captureBlockStates || block instanceof net.minecraft.world.level.block.BaseEntityBlock)) { - iblockdata.onPlace(this.level, blockposition, iblockdata1, flag); + if (!org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) iblockdata.onPlace(this.level, blockposition, iblockdata1, flag); // Leaves - no block update } if (iblockdata.hasBlockEntity()) { diff --git a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java index 1687ab4965433459219bb5d8aaf5ec8e5baeb605..36d49bd355b9c061b1663bcac7c9f590173f34df 100644 --- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java +++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java @@ -506,6 +506,7 @@ public abstract class FlowingFluid extends Fluid { @Override public void tick(Level world, BlockPos pos, FluidState state) { + if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update if (!state.isSource()) { FluidState fluid1 = this.getNewLiquid(world, pos, world.getBlockState(pos)); int i = this.getSpreadDelay(world, pos, state, fluid1); diff --git a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java index 106af2b2c7ff72c7549975aef75cdcff8d9a7d97..ef9f2552367dfa8b708f18d66a4526fea8c24807 100644 --- a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java +++ b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java @@ -48,6 +48,7 @@ public class CollectingNeighborUpdater implements NeighborUpdater { } private void addAndRun(BlockPos pos, CollectingNeighborUpdater.NeighborUpdates entry) { + if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update boolean bl = this.count > 0; boolean bl2 = this.maxChainedNeighborUpdates >= 0 && this.count >= this.maxChainedNeighborUpdates; this.count++; diff --git a/src/main/java/net/minecraft/world/level/redstone/InstantNeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/InstantNeighborUpdater.java index 2708251ebc1995e71fb0e5dca9e158a3005f8a8a..2c39d07e5612b3d435fb782d7861448c470950b4 100644 --- a/src/main/java/net/minecraft/world/level/redstone/InstantNeighborUpdater.java +++ b/src/main/java/net/minecraft/world/level/redstone/InstantNeighborUpdater.java @@ -15,17 +15,20 @@ public class InstantNeighborUpdater implements NeighborUpdater { @Override public void shapeUpdate(Direction direction, BlockState neighborState, BlockPos pos, BlockPos neighborPos, int flags, int maxUpdateDepth) { + if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update NeighborUpdater.executeShapeUpdate(this.level, direction, neighborState, pos, neighborPos, flags, maxUpdateDepth - 1); } @Override public void neighborChanged(BlockPos pos, Block sourceBlock, BlockPos sourcePos) { + if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update BlockState blockState = this.level.getBlockState(pos); this.neighborChanged(blockState, pos, sourceBlock, sourcePos, false); } @Override public void neighborChanged(BlockState state, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { + if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update NeighborUpdater.executeUpdate(this.level, state, pos, sourceBlock, sourcePos, notify); } } diff --git a/src/main/java/org/leavesmc/leaves/command/NoBlockUpdateCommand.java b/src/main/java/org/leavesmc/leaves/command/NoBlockUpdateCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..f60f3409aeb72f8f0195e667ccb139a7f81729b6 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/command/NoBlockUpdateCommand.java @@ -0,0 +1,52 @@ +package org.leavesmc.leaves.command; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.JoinConfiguration; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; +import org.bukkit.plugin.PluginManager; +import org.jetbrains.annotations.NotNull; +import org.leavesmc.leaves.LeavesConfig; + +import java.util.List; + +public class NoBlockUpdateCommand extends Command { + + private static boolean noBlockUpdate = false; + + public NoBlockUpdateCommand(@NotNull String name) { + super(name); + this.description = "No Block Update Command"; + this.usageMessage = "/blockupdate"; + this.setPermission("bukkit.command.blockupdate"); + final PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + if (pluginManager.getPermission("bukkit.command.blockupdate") == null) { + pluginManager.addPermission(new Permission("bukkit.command.blockupdate", PermissionDefault.OP)); + } + } + + @Override + public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { + return List.of(); + } + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) { + if (!testPermission(sender)) return true; + noBlockUpdate = !noBlockUpdate; + Bukkit.broadcast(Component.join(JoinConfiguration.noSeparators(), + Component.text("Block update status: ", NamedTextColor.GRAY), + Component.text(!noBlockUpdate, noBlockUpdate ? NamedTextColor.AQUA : NamedTextColor.GRAY) + ), "bukkit.command.blockupdate"); + + return true; + } + + public static boolean isNoBlockUpdate() { + return LeavesConfig.noBlockUpdateCommand && noBlockUpdate; + } +}