Skip to content

Commit

Permalink
Some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Nov 20, 2024
1 parent aad07eb commit c33238c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 56 deletions.
58 changes: 31 additions & 27 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2169,10 +2169,10 @@ index 0000000000000000000000000000000000000000..517e3321b866abe9d17a6fe9e919528b
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a79a459dee
index 0000000000000000000000000000000000000000..5ade407ff2f3f770592ace5a0f7c82e0a2228ad3
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,548 @@
@@ -0,0 +1,561 @@
+package org.leavesmc.leaves.bot;
+
+import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -2204,6 +2204,7 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+import net.minecraft.world.damagesource.DamageSource;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EquipmentSlot;
+import net.minecraft.world.entity.PositionMoveRotation;
+import net.minecraft.world.entity.ai.attributes.Attributes;
+import net.minecraft.world.entity.item.ItemEntity;
+import net.minecraft.world.entity.player.Player;
Expand All @@ -2212,7 +2213,7 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+import net.minecraft.world.level.GameRules;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.gameevent.GameEvent;
+import net.minecraft.world.level.portal.DimensionTransition;
+import net.minecraft.world.level.portal.TeleportTransition;
+import net.minecraft.world.phys.EntityHitResult;
+import net.minecraft.world.phys.Vec3;
+import org.bukkit.Bukkit;
Expand Down Expand Up @@ -2330,7 +2331,7 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+
+ @Override
+ public void die(@NotNull DamageSource damageSource) {
+ boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+ boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
+ Component defaultMessage = this.getCombatTracker().getDeathMessage();
+
+ BotDeathEvent event = new BotDeathEvent(this.getBukkitEntity(), PaperAdventure.asAdventure(defaultMessage), flag);
Expand All @@ -2357,10 +2358,23 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+ this.sendPacket(new ClientboundPlayerInfoRemovePacket(List.of(this.getUUID())));
+ }
+
+ @Nullable
+ @Override
+ public Entity changeDimension(@NotNull DimensionTransition teleportTarget) {
+ return this; // disable dimension change
+ public @Nullable ServerBot teleport(@NotNull TeleportTransition teleportTarget) {
+ if (this.isSleeping() || this.isRemoved()) {
+ return null;
+ }
+ if (teleportTarget.newLevel().dimension() != this.serverLevel().dimension()) {
+ return null;
+ } else {
+ if (!teleportTarget.asPassenger()) {
+ this.stopRiding();
+ }
+
+ this.connection.internalTeleport(PositionMoveRotation.of(teleportTarget), teleportTarget.relatives());
+ this.connection.resetPosition();
+ teleportTarget.postTeleportTransition().onTransition(this);
+ return this;
+ }
+ }
+
+ @Override
Expand Down Expand Up @@ -2419,8 +2433,7 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+ BotInventoryOpenEvent event = new BotInventoryOpenEvent(this.getBukkitEntity(), player1.getBukkitEntity());
+ this.server.server.getPluginManager().callEvent(event);
+ if (!event.isCancelled()) {
+ Component menuName = this.getDisplayName() != null ? this.getDisplayName() : Component.literal(this.createState.name());
+ player.openMenu(new SimpleMenuProvider((i, inventory, p) -> ChestMenu.sixRows(i, inventory, this.container), menuName));
+ player.openMenu(new SimpleMenuProvider((i, inventory, p) -> ChestMenu.sixRows(i, inventory, this.container), this.getDisplayName()));
+ return InteractionResult.SUCCESS;
+ }
+ }
Expand Down Expand Up @@ -2501,7 +2514,7 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+ this.addDeltaMovement(knockback);
+ this.knockback = Vec3.ZERO;
+
+ this.server.tell(this.server.wrapRunnable(this::runAction));
+ this.server.scheduleOnMain(this::runAction);
+
+ this.livingEntityTick();
+
Expand Down Expand Up @@ -2723,10 +2736,10 @@ index 0000000000000000000000000000000000000000..1a50c4efbec7ff4000e23a477c2f60a7
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/ServerBotGameMode.java b/src/main/java/org/leavesmc/leaves/bot/ServerBotGameMode.java
new file mode 100644
index 0000000000000000000000000000000000000000..bc1e29f6080c4783940848456620be8c06c32cce
index 0000000000000000000000000000000000000000..87ea98ab920a604bdd51281e0656c65160d30118
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBotGameMode.java
@@ -0,0 +1,138 @@
@@ -0,0 +1,137 @@
+package org.leavesmc.leaves.bot;
+
+import net.kyori.adventure.text.Component;
Expand All @@ -2736,7 +2749,6 @@ index 0000000000000000000000000000000000000000..bc1e29f6080c4783940848456620be8c
+import net.minecraft.server.level.ServerPlayerGameMode;
+import net.minecraft.world.InteractionHand;
+import net.minecraft.world.InteractionResult;
+import net.minecraft.world.ItemInteractionResult;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.context.UseOnContext;
+import net.minecraft.world.level.GameType;
Expand Down Expand Up @@ -2826,7 +2838,7 @@ index 0000000000000000000000000000000000000000..bc1e29f6080c4783940848456620be8c
+ return InteractionResult.FAIL;
+ }
+
+ if (player.getCooldowns().isOnCooldown(stack.getItem())) {
+ if (player.getCooldowns().isOnCooldown(stack)) {
+ return InteractionResult.PASS;
+ }
+
Expand All @@ -2840,13 +2852,13 @@ index 0000000000000000000000000000000000000000..bc1e29f6080c4783940848456620be8c
+ boolean flag1 = player.isSecondaryUseActive() && flag;
+
+ if (!flag1) {
+ ItemInteractionResult iteminteractionresult = iblockdata.useItemOn(player.getItemInHand(hand), world, player, hand, hitResult);
+ InteractionResult iteminteractionresult = iblockdata.useItemOn(player.getItemInHand(hand), world, player, hand, hitResult);
+
+ if (iteminteractionresult.consumesAction()) {
+ return iteminteractionresult.result();
+ return iteminteractionresult;
+ }
+
+ if (iteminteractionresult == ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION && hand == InteractionHand.MAIN_HAND) {
+ if (iteminteractionresult == InteractionResult.PASS && hand == InteractionHand.MAIN_HAND) {
+ enuminteractionresult = iblockdata.useWithoutItem(world, player, hitResult);
+ if (enuminteractionresult.consumesAction()) {
+ return enuminteractionresult;
Expand Down Expand Up @@ -4429,22 +4441,16 @@ index f50c3871e3ab435abc6de5bfb67b85b09d235733..d110bf39788503ec662d6f0c737ce9aa
import org.checkerframework.checker.nullness.qual.NonNull;
diff --git a/src/main/java/org/leavesmc/leaves/entity/CraftBot.java b/src/main/java/org/leavesmc/leaves/entity/CraftBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..b33a3ca0e2b6a06668252048ce064dd294c28bee
index 0000000000000000000000000000000000000000..aaa5f8a3a70cac4483003c4a4a7ac2db72791ef9
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/entity/CraftBot.java
@@ -0,0 +1,102 @@
@@ -0,0 +1,94 @@
+package org.leavesmc.leaves.entity;
+
+import com.google.common.base.Preconditions;
+import io.papermc.paper.entity.TeleportFlag;
+import net.minecraft.world.level.portal.DimensionTransition;
+import net.minecraft.world.phys.Vec3;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.player.PlayerTeleportEvent;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
Expand All @@ -4456,7 +4462,6 @@ index 0000000000000000000000000000000000000000..b33a3ca0e2b6a06668252048ce064dd2
+import org.leavesmc.leaves.event.bot.BotActionStopEvent;
+import org.leavesmc.leaves.event.bot.BotRemoveEvent;
+
+import java.util.Set;
+import java.util.UUID;
+
+public class CraftBot extends CraftPlayer implements Bot {
Expand Down Expand Up @@ -4515,7 +4520,6 @@ index 0000000000000000000000000000000000000000..b33a3ca0e2b6a06668252048ce064dd2
+
+ @Override
+ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause, io.papermc.paper.entity.TeleportFlag... flags) {
+ // Paper end
+ Preconditions.checkArgument(location != null, "location cannot be null");
+ Preconditions.checkState(location.getWorld().equals(this.getWorld()), "[Leaves] Fakeplayers do not support changing world, Please use leaves fakeplayer-api instead!");
+ return super.teleport(location, cause, flags);
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0037-Stackable-ShulkerBoxes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ index 33e7d2884195677c4d6340d8b84c1dd85c636ec1..f38487562422ebaf59a679f493f956b9
private Entity entityRepresentation;

diff --git a/src/main/java/net/minecraft/world/level/block/AbstractCauldronBlock.java b/src/main/java/net/minecraft/world/level/block/AbstractCauldronBlock.java
index e00ab1ed8088a1970249313ed63e09070fc6192d..726d395d12520102f5e189d177017b75f264771d 100644
index e00ab1ed8088a1970249313ed63e09070fc6192d..6a3ba2fdcdedb248257003f7214b81e8651286e8 100644
--- a/src/main/java/net/minecraft/world/level/block/AbstractCauldronBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/AbstractCauldronBlock.java
@@ -56,9 +56,27 @@ public abstract class AbstractCauldronBlock extends Block {
Expand All @@ -346,13 +346,13 @@ index e00ab1ed8088a1970249313ed63e09070fc6192d..726d395d12520102f5e189d177017b75
}

+ // Leaves start - stackable shulker boxes
+ private ItemInteractionResult wrapInteractor(CauldronInteraction cauldronBehavior, BlockState blockState, Level world, BlockPos blockPos, Player playerEntity, InteractionHand hand, ItemStack itemStack, net.minecraft.core.Direction hitDirection) {
+ private InteractionResult wrapInteractor(CauldronInteraction cauldronBehavior, BlockState blockState, Level world, BlockPos blockPos, Player playerEntity, InteractionHand hand, ItemStack itemStack, net.minecraft.core.Direction hitDirection) {
+ int count = -1;
+ if (org.leavesmc.leaves.LeavesConfig.shulkerBoxStackSize > 1 && itemStack.getItem() instanceof net.minecraft.world.item.BlockItem bi &&
+ bi.getBlock() instanceof ShulkerBoxBlock) {
+ count = itemStack.getCount();
+ }
+ ItemInteractionResult result = cauldronBehavior.interact(blockState, world, blockPos, playerEntity, hand, itemStack, hitDirection);
+ InteractionResult result = cauldronBehavior.interact(blockState, world, blockPos, playerEntity, hand, itemStack, hitDirection);
+ if (count > 0 && result.consumesAction()) {
+ ItemStack current = playerEntity.getItemInHand(hand);
+ if (current.getItem() instanceof net.minecraft.world.item.BlockItem bi && bi.getBlock() instanceof ShulkerBoxBlock) {
Expand Down
12 changes: 0 additions & 12 deletions patches/server/0075-Reduce-array-allocations.patch
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,6 @@ index 87393a181c64af6a02ebddfccae674c4fbcb3903..09a402e95cdb8c75881fbeff66ca8537
private final int size;

public ZeroBitStorage(int size) {
diff --git a/src/main/java/net/minecraft/world/entity/EquipmentSlot.java b/src/main/java/net/minecraft/world/entity/EquipmentSlot.java
index 1a3c9a2b572f7caaf21beb3054d0d1b19c3a174b..40d46ad488192cb2261f8b431e9f2a13f929cb0c 100644
--- a/src/main/java/net/minecraft/world/entity/EquipmentSlot.java
+++ b/src/main/java/net/minecraft/world/entity/EquipmentSlot.java
@@ -28,6 +28,7 @@ public enum EquipmentSlot implements StringRepresentable {
private final int countLimit;
private final int id;
private final String name;
+ public static final EquipmentSlot[] VALUES = EquipmentSlot.values(); // Leaves - reduce array allocations

private EquipmentSlot(final EquipmentSlot.Type type, final int entityId, final int maxCount, final int index, final String name) {
this.type = type;
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a611be936c3ff43a083daa2504567eb1c342b485..7e98ac3fdb721889f22909e26f978c8a3734b28a 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
Expand Down
24 changes: 18 additions & 6 deletions patches/server/0083-Fix-villagers-dont-release-memory.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@ Date: Sat, 22 Jul 2023 12:00:59 +0800
Subject: [PATCH] Fix villagers dont release memory


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index fa536b952668de17ace1e1c7538c48004010f047..2a9ef9770e3b08ad0041593dcce04876b935bd25 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4057,7 +4057,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this;
}

- private Entity teleportCrossDimension(ServerLevel world, TeleportTransition teleportTarget) {
+ protected Entity teleportCrossDimension(ServerLevel world, TeleportTransition teleportTarget) { // Leaves - private -> protected
List<Entity> list = this.getPassengers();
List<Entity> list1 = new ArrayList(list.size());

diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
index b7a34f1c4d7b5ef3f7a843d152e33c839dcdedd5..a98f9c22f8485ff3a9812cce19d47a0b08f2c054 100644
index b7a34f1c4d7b5ef3f7a843d152e33c839dcdedd5..662c46e465feaf3917a93a6f8942febb25590922 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -1045,4 +1045,20 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
@@ -1045,4 +1045,19 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
return worldTime - olong < 24000L;
}).isPresent();
}
+
+ // Leaves start - fixes a memory leak when villagers get moved to another world
+ @Nullable
+ @Override
+ public Entity changeDimension(net.minecraft.world.level.portal.DimensionTransition destination) {
+ public Entity teleportCrossDimension(ServerLevel world, net.minecraft.world.level.portal.TeleportTransition transition) {
+ if (org.leavesmc.leaves.LeavesConfig.villagersDontReleaseMemoryFix) {
+ this.releaseAllPois();
+ this.getBrain().eraseMemory(MemoryModuleType.HOME);
+ this.getBrain().eraseMemory(MemoryModuleType.JOB_SITE);
+ this.getBrain().eraseMemory(MemoryModuleType.POTENTIAL_JOB_SITE);
+ this.getBrain().eraseMemory(MemoryModuleType.MEETING_POINT);
+ this.refreshBrain(destination.newLevel());
+ this.refreshBrain(transition.newLevel());
+ }
+ return super.changeDimension(destination);
+ return super.teleportCrossDimension(world, transition);
+ }
+ // Leaves end - fixes a memory leak when villagers get moved to another world
}
14 changes: 6 additions & 8 deletions patches/server/0089-Replay-Mod-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ index 0000000000000000000000000000000000000000..0e8cd7e878ec1294d6cb830a004eeefd
+}
diff --git a/src/main/java/org/leavesmc/leaves/replay/Recorder.java b/src/main/java/org/leavesmc/leaves/replay/Recorder.java
new file mode 100644
index 0000000000000000000000000000000000000000..49cf69a916eed2ec4753f286e3a53cc8d0429a41
index 0000000000000000000000000000000000000000..ba0dde3f006b43ef04d252f970ea1315566c45e6
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/replay/Recorder.java
@@ -0,0 +1,288 @@
@@ -0,0 +1,286 @@
+package org.leavesmc.leaves.replay;
+
+import com.mojang.serialization.DynamicOps;
Expand Down Expand Up @@ -732,7 +732,7 @@ index 0000000000000000000000000000000000000000..49cf69a916eed2ec4753f286e3a53cc8
+import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
+import net.minecraft.network.protocol.game.ClientboundSetTimePacket;
+import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
+import net.minecraft.network.protocol.login.ClientboundGameProfilePacket;
+import net.minecraft.network.protocol.login.ClientboundLoginFinishedPacket;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.RegistryLayer;
+import net.minecraft.server.packs.repository.KnownPack;
Expand Down Expand Up @@ -797,7 +797,7 @@ index 0000000000000000000000000000000000000000..49cf69a916eed2ec4753f286e3a53cc8
+ metaData.mcversion = SharedConstants.getCurrentVersion().getName();
+
+ // TODO start event
+ savePacket(new ClientboundGameProfilePacket(photographer.getGameProfile(), true), ConnectionProtocol.LOGIN);
+ savePacket(new ClientboundLoginFinishedPacket(photographer.getGameProfile()), ConnectionProtocol.LOGIN);
+ startConfiguration();
+
+ if (recorderOption.forceWeather != null) {
Expand Down Expand Up @@ -880,9 +880,7 @@ index 0000000000000000000000000000000000000000..49cf69a916eed2ec4753f286e3a53cc8
+ public void send(@NotNull Packet<?> packet, @Nullable PacketSendListener callbacks, boolean flush) {
+ if (!stopped) {
+ if (packet instanceof BundlePacket<?> packet1) {
+ packet1.subPackets().forEach(subPacket -> {
+ send(subPacket, null);
+ });
+ packet1.subPackets().forEach(subPacket -> send(subPacket, null));
+ return;
+ }
+
Expand All @@ -898,7 +896,7 @@ index 0000000000000000000000000000000000000000..49cf69a916eed2ec4753f286e3a53cc8
+ }
+
+ if (recorderOption.forceDayTime != -1 && packet instanceof ClientboundSetTimePacket packet1) {
+ packet = new ClientboundSetTimePacket(packet1.getDayTime(), recorderOption.forceDayTime, false);
+ packet = new ClientboundSetTimePacket(packet1.dayTime(), recorderOption.forceDayTime, false);
+ }
+
+ if (recorderOption.forceWeather != null && packet instanceof ClientboundGameEventPacket packet1) {
Expand Down

0 comments on commit c33238c

Please sign in to comment.