9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/patches/server/0061-No-block-update-command.patch
violetc de4f3fe832 1.21.3 (#382)
---------

Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
2024-12-02 12:52:54 +08:00

152 lines
9.1 KiB
Diff

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 1b2ba3ff09b27ea74afc96735e48a474cf6ebddd..e52c490540319db13a2b23f839f7fd88aeadda64 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -2453,6 +2453,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@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 f38487562422ebaf59a679f493f956b90cc18ff1..b6b3189f15c9e56f104a788716bb134b352cc83c 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -533,7 +533,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 2fea5a46bba27578366c36f594472c3e38395bee..80c71d08ea7588ba95416296531c5629097d9257 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -427,7 +427,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 f4fbcbb8ff6d2677af1a02a0801a323c06dce9b1..dd9e7b030b64b10d61481e744fe3e53ff80087f8 100644
--- a/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
+++ b/src/main/java/net/minecraft/world/level/material/FlowingFluid.java
@@ -516,6 +516,7 @@ public abstract class FlowingFluid extends Fluid {
@Override
public void tick(ServerLevel world, BlockPos pos, BlockState blockState, FluidState fluidState) {
+ if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update
if (!fluidState.isSource()) {
FluidState fluid1 = this.getNewLiquid(world, pos, world.getBlockState(pos));
int i = this.getSpreadDelay(world, pos, fluidState, 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 3a95e3236eafd14baed035e53503b58c2e21b68a..717d9042a9a67aea771b0b544776a9956eb52eab 100644
--- a/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
+++ b/src/main/java/net/minecraft/world/level/redstone/CollectingNeighborUpdater.java
@@ -49,6 +49,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 e1c3dbd74a009ca8adc6269fd22f9547ee03f347..efb9cc019e804aa4f88d77cbee6d05cb9f65de29 100644
--- a/src/main/java/net/minecraft/world/level/redstone/InstantNeighborUpdater.java
+++ b/src/main/java/net/minecraft/world/level/redstone/InstantNeighborUpdater.java
@@ -16,17 +16,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, pos, neighborPos, neighborState, flags, maxUpdateDepth - 1);
}
@Override
public void neighborChanged(BlockPos pos, Block sourceBlock, @Nullable Orientation orientation) {
+ if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update
BlockState blockState = this.level.getBlockState(pos);
this.neighborChanged(blockState, pos, sourceBlock, orientation, false);
}
@Override
public void neighborChanged(BlockState state, BlockPos pos, Block sourceBlock, @Nullable Orientation orientation, boolean notify) {
+ if (org.leavesmc.leaves.command.NoBlockUpdateCommand.isNoBlockUpdate()) return; // Leaves - no block update
NeighborUpdater.executeUpdate(this.level, state, pos, sourceBlock, orientation, 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..8f25ce0145341d363bb42183a9e64622159663ff
--- /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<String> 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.modify.noBlockUpdateCommand && noBlockUpdate;
+ }
+}