From 973f52a65000e6206c3b10a55691302dcfb66164 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 23 Mar 2013 09:46:33 +1100 Subject: [PATCH] Merge tweaks and configuration This allows the merging of Experience orbs, as well as the configuration of the merge radius of items. Additionally it refactors the merge algorithm to be a better experience for players. By: md_5 --- .../world/entity/item/ItemEntity.java.patch | 31 ++++++++++++++++--- .../craftbukkit/event/CraftEventFactory.java | 17 ++++++++++ .../java/org/spigotmc/SpigotWorldConfig.java | 14 +++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch index 4f490795db..1d52eb82c4 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/item/ItemEntity.java.patch @@ -109,7 +109,28 @@ } } -@@ -287,11 +306,16 @@ +@@ -229,7 +248,10 @@ + + private void mergeWithNeighbours() { + if (this.isMergable()) { +- List list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(0.5D, 0.0D, 0.5D), (entityitem) -> { ++ // Spigot start ++ double radius = this.level().spigotConfig.itemMerge; ++ List list = this.level().getEntitiesOfClass(ItemEntity.class, this.getBoundingBox().inflate(radius, radius - 0.5D, radius), (entityitem) -> { ++ // Spigot end + return entityitem != this && entityitem.isMergable(); + }); + Iterator iterator = list.iterator(); +@@ -259,7 +281,7 @@ + ItemStack itemstack1 = other.getItem(); + + if (Objects.equals(this.target, other.target) && ItemEntity.areMergable(itemstack, itemstack1)) { +- if (itemstack1.getCount() < itemstack.getCount()) { ++ if (true || itemstack1.getCount() < itemstack.getCount()) { // Spigot + ItemEntity.merge(this, itemstack, other, itemstack1); + } else { + ItemEntity.merge(other, itemstack1, this, itemstack); +@@ -287,11 +309,16 @@ } private static void merge(ItemEntity targetEntity, ItemStack targetStack, ItemEntity sourceEntity, ItemStack sourceStack) { @@ -127,7 +148,7 @@ } } -@@ -320,12 +344,17 @@ +@@ -320,12 +347,17 @@ } else if (!this.getItem().canBeHurtBy(source)) { return false; } else { @@ -146,7 +167,7 @@ } return true; -@@ -382,22 +411,62 @@ +@@ -382,22 +414,62 @@ } if (this.getItem().isEmpty()) { @@ -163,7 +184,7 @@ ItemStack itemstack = this.getItem(); Item item = itemstack.getItem(); int i = itemstack.getCount(); - ++ + // CraftBukkit start - fire PlayerPickupItemEvent + int canHold = player.getInventory().canHold(itemstack); + int remaining = i - canHold; @@ -178,7 +199,7 @@ + itemstack.setCount(i); // SPIGOT-5294 - restore count + return; + } -+ + + // Call newer event afterwards + EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((Player) player.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining); + entityEvent.setCancelled(!entityEvent.getEntity().getCanPickupItems()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 274b24369e..b503478728 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -703,6 +703,23 @@ public class CraftEventFactory { return false; } + // Spigot start - SPIGOT-7523: Merge after spawn event and only merge if the event was not cancelled (gets checked above) + if (entity instanceof net.minecraft.world.entity.ExperienceOrb xp) { + double radius = world.spigotConfig.expMerge; + if (radius > 0) { + List entities = world.getEntities(entity, entity.getBoundingBox().inflate(radius, radius, radius)); + for (Entity e : entities) { + if (e instanceof net.minecraft.world.entity.ExperienceOrb loopItem) { + if (!loopItem.isRemoved()) { + xp.value += loopItem.value; + loopItem.discard(null); // Add Bukkit remove cause + } + } + } + } + } + // Spigot end + return true; } diff --git a/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java b/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java index 5d2a783039..011d129ca4 100644 --- a/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java +++ b/paper-server/src/main/java/org/spigotmc/SpigotWorldConfig.java @@ -134,4 +134,18 @@ public class SpigotWorldConfig this.weepingVinesModifier = this.getAndValidateGrowth( "WeepingVines" ); this.caveVinesModifier = this.getAndValidateGrowth( "CaveVines" ); } + + public double itemMerge; + private void itemMerge() + { + this.itemMerge = this.getDouble("merge-radius.item", 2.5 ); + this.log( "Item Merge Radius: " + this.itemMerge ); + } + + public double expMerge; + private void expMerge() + { + this.expMerge = this.getDouble("merge-radius.exp", 3.0 ); + this.log( "Experience Merge Radius: " + this.expMerge ); + } }