Skip to content

Commit

Permalink
and more
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Nov 21, 2024
1 parent c33238c commit 329244f
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 156 deletions.
65 changes: 11 additions & 54 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1638,10 +1638,10 @@ index 0000000000000000000000000000000000000000..4f5e6e5c1b9d8bd38c98e97fd31b3833
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/BotList.java b/src/main/java/org/leavesmc/leaves/bot/BotList.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb33cad06036f188bd9228556fff6256391085c0
index 0000000000000000000000000000000000000000..3eac675dccfa992d0aad4ebb84fcf6357761be2e
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/BotList.java
@@ -0,0 +1,340 @@
@@ -0,0 +1,297 @@
+package org.leavesmc.leaves.bot;
+
+import com.google.common.collect.Maps;
Expand All @@ -1659,7 +1659,6 @@ index 0000000000000000000000000000000000000000..bb33cad06036f188bd9228556fff6256
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.level.Level;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
Expand All @@ -1675,7 +1674,6 @@ index 0000000000000000000000000000000000000000..bb33cad06036f188bd9228556fff6256
+import org.leavesmc.leaves.event.bot.BotSpawnLocationEvent;
+import org.slf4j.Logger;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
Expand Down Expand Up @@ -1762,7 +1760,10 @@ index 0000000000000000000000000000000000000000..bb33cad06036f188bd9228556fff6256
+ }
+
+ public ServerBot placeNewBot(ServerBot bot, ServerLevel world, Location location, @Nullable CompoundTag nbt) {
+ Optional<CompoundTag> optional = Optional.ofNullable(nbt);
+
+ bot.isRealPlayer = true;
+ bot.loginTime = System.currentTimeMillis();
+ bot.connection = new ServerBotPacketListenerImpl(this.server, bot);
+ bot.setServerLevel(world);
+
Expand All @@ -1771,18 +1772,21 @@ index 0000000000000000000000000000000000000000..bb33cad06036f188bd9228556fff6256
+ location = event.getSpawnLocation();
+
+ bot.spawnIn(world);
+ bot.gameMode.setLevel((ServerLevel) bot.level());
+ bot.gameMode.setLevel(bot.serverLevel());
+
+ bot.setPosRaw(location.getX(), location.getY(), location.getZ());
+ bot.setRot(location.getYaw(), location.getPitch());
+
+ bot.connection.teleport(bot.getX(), bot.getY(), bot.getZ(), bot.getYRot(), bot.getXRot());
+
+ this.bots.add(bot);
+ this.botsByName.put(bot.getScoreboardName().toLowerCase(Locale.ROOT), bot);
+ this.botsByUUID.put(bot.getUUID(), bot);
+
+ bot.supressTrackerForLogin = true;
+ world.addNewPlayer(bot);
+ this.mountSavedVehicle(bot, world, nbt);
+ bot.loadAndSpawnEnderpearls(optional);
+ bot.loadAndSpawnParentVehicle(optional);
+
+ BotJoinEvent event1 = new BotJoinEvent(bot.getBukkitEntity(), PaperAdventure.asAdventure(Component.translatable("multiplayer.player.joined", bot.getDisplayName())).style(Style.style(NamedTextColor.YELLOW)));
+ this.server.server.getPluginManager().callEvent(event1);
Expand All @@ -1794,59 +1798,12 @@ index 0000000000000000000000000000000000000000..bb33cad06036f188bd9228556fff6256
+
+ bot.renderAll();
+ bot.supressTrackerForLogin = false;
+
+ bot.serverLevel().getChunkSource().chunkMap.addEntity(bot);
+ BotList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", bot.getName().getString(), "Local", bot.getId(), bot.serverLevel().serverLevelData.getLevelName(), bot.getX(), bot.getY(), bot.getZ());
+ return bot;
+ }
+
+ private void mountSavedVehicle(ServerPlayer player, ServerLevel worldserver1, @Nullable CompoundTag nbt) {
+ Optional<CompoundTag> optional = Optional.ofNullable(nbt);
+ if (optional.isPresent() && optional.get().contains("RootVehicle", 10)) {
+ CompoundTag nbttagcompound = optional.get().getCompound("RootVehicle");
+ Entity entity = EntityType.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver1, (entity1) -> {
+ return !worldserver1.addWithUUID(entity1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.MOUNT) ? null : entity1;
+ });
+
+ if (entity != null) {
+ UUID uuid;
+
+ if (nbttagcompound.hasUUID("Attach")) {
+ uuid = nbttagcompound.getUUID("Attach");
+ } else {
+ uuid = null;
+ }
+
+ Iterator<Entity> iterator;
+ Entity entity1;
+
+ if (entity.getUUID().equals(uuid)) {
+ player.startRiding(entity, true);
+ } else {
+ iterator = entity.getIndirectPassengers().iterator();
+
+ while (iterator.hasNext()) {
+ entity1 = iterator.next();
+ if (entity1.getUUID().equals(uuid)) {
+ player.startRiding(entity1, true);
+ break;
+ }
+ }
+ }
+
+ if (!player.isPassenger()) {
+ BotList.LOGGER.warn("Couldn't reattach entity to fakeplayer");
+ entity.discard();
+ iterator = entity.getIndirectPassengers().iterator();
+
+ while (iterator.hasNext()) {
+ entity1 = iterator.next();
+ entity1.discard();
+ }
+ }
+ }
+ }
+ }
+
+ public boolean removeBot(@NotNull ServerBot bot, @NotNull BotRemoveEvent.RemoveReason reason, @Nullable CommandSender remover, boolean saved) {
+ return this.removeBot(bot, reason, remover, saved, this.dataStorage);
+ }
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0036-Renewable-Elytra.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Subject: [PATCH] Renewable Elytra
This patch is Powered by Carpet-TIS-Addition(https://github.com/plusls/Carpet-TIS-Addition)

diff --git a/src/main/java/net/minecraft/world/entity/monster/Phantom.java b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
index 150fd890ac65097b5434fd88e8d2b24a89dca79a..defde4529f2db132669ee4c1b36030fb39a32912 100644
index 150fd890ac65097b5434fd88e8d2b24a89dca79a..25bbbfe8ccb8437880d6c27f9a859ed005f30faf 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Phantom.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Phantom.java
@@ -233,6 +233,20 @@ public class Phantom extends FlyingMob implements Enemy {
Expand All @@ -15,13 +15,13 @@ index 150fd890ac65097b5434fd88e8d2b24a89dca79a..defde4529f2db132669ee4c1b36030fb

+ // Leaves start - renewable elytra
+ @Override
+ protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) {
+ super.dropFromLootTable(source, causedByPlayer);
+ protected void dropFromLootTable(ServerLevel level, DamageSource source, boolean causedByPlayer) {
+ super.dropFromLootTable(level, source, causedByPlayer);
+ if (org.leavesmc.leaves.LeavesConfig.renewableElytra > 0.0D) {
+ if (source.getEntity() instanceof Shulker && this.random.nextDouble() < org.leavesmc.leaves.LeavesConfig.renewableElytra) {
+ net.minecraft.world.item.ItemStack item = new net.minecraft.world.item.ItemStack(net.minecraft.world.item.Items.ELYTRA);
+ item.setDamageValue(432);
+ this.spawnAtLocation(item);
+ this.spawnAtLocation(level, item);
+ }
+ }
+ }
Expand Down
27 changes: 13 additions & 14 deletions patches/server/0044-Fix-update-suppression-crash.patch
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ index 8913b80ff4c593369b01fe75b67a11335a852439..3c2db9fa853ade7e429738f9896ad31e
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");

diff --git a/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java b/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
index 155c7240b1112729333e6968122568c707d8f66b..2ae2f899183e3043b524712f0944bb9e894d74ab 100644
index 155c7240b1112729333e6968122568c707d8f66b..96a3f7f46e6afbb6bf2247b14ec787afc8be2523 100644
--- a/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/ShulkerBoxBlock.java
@@ -239,7 +239,17 @@ public class ShulkerBoxBlock extends BaseEntityBlock {
Expand All @@ -52,7 +52,7 @@ index 155c7240b1112729333e6968122568c707d8f66b..2ae2f899183e3043b524712f0944bb9e
+ try {
+ return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(world.getBlockEntity(pos));
+ } catch (ClassCastException ex) {
+ throw new org.leavesmc.leaves.util.UpdateSuppressionException(null, pos);
+ throw new org.leavesmc.leaves.util.UpdateSuppressionException(pos, this);
+ }
+ } else {
+ return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(world.getBlockEntity(pos));
Expand All @@ -62,7 +62,7 @@ index 155c7240b1112729333e6968122568c707d8f66b..2ae2f899183e3043b524712f0944bb9e

@Override
diff --git a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
index be8f34dd222e43b2db7f05e5e5839df8446e1b02..f54ddc20a5510864bff8eda6cf100f4ccade3dcd 100644
index be8f34dd222e43b2db7f05e5e5839df8446e1b02..778d123f6fe4eb29becc42db8deafbfa8b9486be 100644
--- a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
+++ b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
@@ -70,9 +70,17 @@ public interface NeighborUpdater {
Expand All @@ -71,34 +71,35 @@ index be8f34dd222e43b2db7f05e5e5839df8446e1b02..f54ddc20a5510864bff8eda6cf100f4c
} catch (StackOverflowError ex) {
+ // Leaves start - fix update suppression crash
+ if (org.leavesmc.leaves.LeavesConfig.updateSuppressionCrashFix) {
+ throw new org.leavesmc.leaves.util.UpdateSuppressionException(pos, sourcePos);
+ throw new org.leavesmc.leaves.util.UpdateSuppressionException(pos, sourceBlock);
+ }
world.lastPhysicsProblem = new BlockPos(pos);
// Spigot End
} catch (Throwable throwable) {
+ if (org.leavesmc.leaves.LeavesConfig.updateSuppressionCrashFix) {
+ throw new org.leavesmc.leaves.util.UpdateSuppressionException(pos, sourcePos);
+ throw new org.leavesmc.leaves.util.UpdateSuppressionException(pos, sourceBlock);
+ }
+ // Leaves end - fix update suppression crash
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception while updating neighbours");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Block being updated");

diff --git a/src/main/java/org/leavesmc/leaves/util/UpdateSuppressionException.java b/src/main/java/org/leavesmc/leaves/util/UpdateSuppressionException.java
new file mode 100644
index 0000000000000000000000000000000000000000..77fd58a309b5d3c45f963c4bd1f47d7fc212898e
index 0000000000000000000000000000000000000000..150a0813b775a863d8c5c744f299dd248a600a47
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/util/UpdateSuppressionException.java
@@ -0,0 +1,33 @@
@@ -0,0 +1,32 @@
+package org.leavesmc.leaves.util;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.level.block.Block;
+
+public class UpdateSuppressionException extends RuntimeException {
+
+ private final BlockPos pos;
+ private final BlockPos source;
+ private final Block source;
+
+ public UpdateSuppressionException(BlockPos pos, BlockPos source) {
+ public UpdateSuppressionException(BlockPos pos, Block source) {
+ super("Update suppression");
+ this.pos = pos;
+ this.source = source;
Expand All @@ -108,17 +109,15 @@ index 0000000000000000000000000000000000000000..77fd58a309b5d3c45f963c4bd1f47d7f
+ return pos;
+ }
+
+ public BlockPos getSource() {
+ public Block getSource() {
+ return source;
+ }
+
+ public String getMessage() {
+ if (pos != null) {
+ return "An update suppression processed, form [x:%d,y:%d,z:%d] to [x:%d,y:%d,z:%d]"
+ .formatted(source.getX(), source.getY(), source.getZ(), pos.getX(), pos.getY(), pos.getZ());
+ return "An update suppression processed, form [%s] to [x:%d,y:%d,z:%d]".formatted(source.getName(), pos.getX(), pos.getY(), pos.getZ());
+ } else {
+ return "An update suppression processed, form [x:%d,y:%d,z:%d]"
+ .formatted(source.getX(), source.getY(), source.getZ());
+ return "An update suppression processed, form [%s]".formatted(source.getName());
+ }
+ }
+}
4 changes: 2 additions & 2 deletions patches/server/0057-Shave-snow-layers.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Shave snow layers


diff --git a/src/main/java/net/minecraft/world/item/ShovelItem.java b/src/main/java/net/minecraft/world/item/ShovelItem.java
index 55c18f182166f4905d623d6f5e909eefd5ed2483..d41d353a08d4834b3280e20f95416158996fd810 100644
index 55c18f182166f4905d623d6f5e909eefd5ed2483..1a3a4fab67db34c6ca022465f474de3c84167fa7 100644
--- a/src/main/java/net/minecraft/world/item/ShovelItem.java
+++ b/src/main/java/net/minecraft/world/item/ShovelItem.java
@@ -44,6 +44,26 @@ public class ShovelItem extends DiggerItem {
Expand All @@ -16,7 +16,7 @@ index 55c18f182166f4905d623d6f5e909eefd5ed2483..d41d353a08d4834b3280e20f95416158
+ if (org.leavesmc.leaves.LeavesConfig.shaveSnowLayers && blockState.is(Blocks.SNOW)) {
+ int layers = blockState.getValue(net.minecraft.world.level.block.SnowLayerBlock.LAYERS);
+ ItemStack tool = context.getItemInHand();
+ boolean hasSilkTouch = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(level.registryAccess().registryOrThrow(net.minecraft.core.registries.Registries.ENCHANTMENT).getHolder(net.minecraft.world.item.enchantment.Enchantments.SILK_TOUCH).get(), tool) > 0;
+ boolean hasSilkTouch = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(level.registryAccess().lookupOrThrow(net.minecraft.core.registries.Registries.ENCHANTMENT).getOrThrow(net.minecraft.world.item.enchantment.Enchantments.SILK_TOUCH), tool) > 0;
+ BlockState shavedBlockState = layers > 1 ? blockState.setValue(net.minecraft.world.level.block.SnowLayerBlock.LAYERS, layers - 1) : Blocks.AIR.defaultBlockState();
+
+ level.setBlock(blockPos, shavedBlockState, Block.UPDATE_ALL_IMMEDIATE);
Expand Down
17 changes: 0 additions & 17 deletions patches/server/0075-Reduce-array-allocations.patch
Original file line number Diff line number Diff line change
Expand Up @@ -382,23 +382,6 @@ index 91a2619dc11eef5d9ac7450caa43330bac3bbaaa..107a46185ad3db21736c211c603b14ee
private static final int[] SLOTS_FOR_DOWN = new int[]{2, 1};
private static final int[] SLOTS_FOR_SIDES = new int[]{1};
public static final int DATA_LIT_DURATION = 1;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java b/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java
index ae86c45c1d49c7646c721991910592091e7333f8..f3dce7156d518193fe27a69f5792800b72742632 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java
@@ -7,8 +7,10 @@ import org.bukkit.inventory.EquipmentSlot;

public class CraftEquipmentSlot {

- private static final net.minecraft.world.entity.EquipmentSlot[] slots = new net.minecraft.world.entity.EquipmentSlot[EquipmentSlot.values().length];
- private static final EquipmentSlot[] enums = new EquipmentSlot[net.minecraft.world.entity.EquipmentSlot.values().length];
+ // Leaves start - reduce array allocations
+ private static final net.minecraft.world.entity.EquipmentSlot[] slots = net.minecraft.world.entity.EquipmentSlot.VALUES;
+ private static final EquipmentSlot[] enums = new EquipmentSlot[net.minecraft.world.entity.EquipmentSlot.VALUES.length];
+ // Leaves end - reduce array allocations

static {
set(EquipmentSlot.HAND, net.minecraft.world.entity.EquipmentSlot.MAINHAND);
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
index fdcc414f4fa246082ad0732133c870d915ae3084..556247696cde0d31cbb70907648d2970acf81153 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
Expand Down
Loading

0 comments on commit 329244f

Please sign in to comment.