mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 21:31:25 +01:00
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 <git@md-5.net>
This commit is contained in:
parent
df403168ff
commit
973f52a650
@ -109,7 +109,28 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -287,11 +306,16 @@
|
||||
@@ -229,7 +248,10 @@
|
||||
|
||||
private void mergeWithNeighbours() {
|
||||
if (this.isMergable()) {
|
||||
- List<ItemEntity> 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<ItemEntity> 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());
|
||||
|
@ -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<Entity> 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;
|
||||
}
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user