mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-04 06:02:12 -07:00
Alternative item-despawn-rate
Co-authored-by: Noah van der Aa <ndvdaa@gmail.com>
This commit is contained in:
@@ -55,16 +55,17 @@
|
|||||||
|
|
||||||
public class ItemEntity extends Entity implements TraceableEntity {
|
public class ItemEntity extends Entity implements TraceableEntity {
|
||||||
|
|
||||||
@@ -52,6 +60,8 @@
|
@@ -52,6 +60,9 @@
|
||||||
@Nullable
|
@Nullable
|
||||||
public UUID target;
|
public UUID target;
|
||||||
public final float bobOffs;
|
public final float bobOffs;
|
||||||
+ private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
|
+ private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
|
||||||
+ public boolean canMobPickup = true; // Paper - Item#canEntityPickup
|
+ public boolean canMobPickup = true; // Paper - Item#canEntityPickup
|
||||||
|
+ private int despawnRate = -1; // Paper - Alternative item-despawn-rate
|
||||||
|
|
||||||
public ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
|
public ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
@@ -133,12 +143,15 @@
|
@@ -133,12 +144,15 @@
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if (this.getItem().isEmpty()) {
|
if (this.getItem().isEmpty()) {
|
||||||
@@ -84,7 +85,7 @@
|
|||||||
|
|
||||||
this.xo = this.getX();
|
this.xo = this.getX();
|
||||||
this.yo = this.getY();
|
this.yo = this.getY();
|
||||||
@@ -162,7 +175,7 @@
|
@@ -162,7 +176,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@
|
|||||||
this.move(MoverType.SELF, this.getDeltaMovement());
|
this.move(MoverType.SELF, this.getDeltaMovement());
|
||||||
this.applyEffectsFromBlocks();
|
this.applyEffectsFromBlocks();
|
||||||
float f = 0.98F;
|
float f = 0.98F;
|
||||||
@@ -188,9 +201,11 @@
|
@@ -188,9 +202,11 @@
|
||||||
this.mergeWithNeighbours();
|
this.mergeWithNeighbours();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,13 +106,13 @@
|
|||||||
|
|
||||||
this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
||||||
if (!this.level().isClientSide) {
|
if (!this.level().isClientSide) {
|
||||||
@@ -201,14 +216,42 @@
|
@@ -201,14 +217,42 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- if (!this.level().isClientSide && this.age >= 6000) {
|
- if (!this.level().isClientSide && this.age >= 6000) {
|
||||||
- this.discard();
|
- this.discard();
|
||||||
+ if (!this.level().isClientSide && this.age >= this.level().spigotConfig.itemDespawnRate) { // Spigot
|
+ if (!this.level().isClientSide && this.age >= this.despawnRate) { // Spigot // Paper - Alternative item-despawn-rate
|
||||||
+ // CraftBukkit start - fire ItemDespawnEvent
|
+ // CraftBukkit start - fire ItemDespawnEvent
|
||||||
+ if (CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
+ if (CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
||||||
+ this.age = 0;
|
+ this.age = 0;
|
||||||
@@ -134,7 +135,7 @@
|
|||||||
+ this.lastTick = MinecraftServer.currentTick;
|
+ this.lastTick = MinecraftServer.currentTick;
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+
|
+
|
||||||
+ if (!this.level().isClientSide && this.age >= this.level().spigotConfig.itemDespawnRate) { // Spigot
|
+ if (!this.level().isClientSide && this.age >= this.despawnRate) { // Spigot // Paper - Alternative item-despawn-rate
|
||||||
+ // CraftBukkit start - fire ItemDespawnEvent
|
+ // CraftBukkit start - fire ItemDespawnEvent
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
|
||||||
+ this.age = 0;
|
+ this.age = 0;
|
||||||
@@ -150,7 +151,7 @@
|
|||||||
public BlockPos getBlockPosBelowThatAffectsMyMovement() {
|
public BlockPos getBlockPosBelowThatAffectsMyMovement() {
|
||||||
return this.getOnPos(0.999999F);
|
return this.getOnPos(0.999999F);
|
||||||
}
|
}
|
||||||
@@ -229,7 +272,10 @@
|
@@ -229,7 +273,10 @@
|
||||||
|
|
||||||
private void mergeWithNeighbours() {
|
private void mergeWithNeighbours() {
|
||||||
if (this.isMergable()) {
|
if (this.isMergable()) {
|
||||||
@@ -162,7 +163,16 @@
|
|||||||
return entityitem != this && entityitem.isMergable();
|
return entityitem != this && entityitem.isMergable();
|
||||||
});
|
});
|
||||||
Iterator iterator = list.iterator();
|
Iterator iterator = list.iterator();
|
||||||
@@ -259,7 +305,7 @@
|
@@ -251,7 +298,7 @@
|
||||||
|
private boolean isMergable() {
|
||||||
|
ItemStack itemstack = this.getItem();
|
||||||
|
|
||||||
|
- return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < 6000 && itemstack.getCount() < itemstack.getMaxStackSize();
|
||||||
|
+ return this.isAlive() && this.pickupDelay != 32767 && this.age != -32768 && this.age < this.despawnRate && itemstack.getCount() < itemstack.getMaxStackSize(); // Paper - Alternative item-despawn-rate
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryToMerge(ItemEntity other) {
|
||||||
|
@@ -259,7 +306,7 @@
|
||||||
ItemStack itemstack1 = other.getItem();
|
ItemStack itemstack1 = other.getItem();
|
||||||
|
|
||||||
if (Objects.equals(this.target, other.target) && ItemEntity.areMergable(itemstack, itemstack1)) {
|
if (Objects.equals(this.target, other.target) && ItemEntity.areMergable(itemstack, itemstack1)) {
|
||||||
@@ -171,7 +181,7 @@
|
|||||||
ItemEntity.merge(this, itemstack, other, itemstack1);
|
ItemEntity.merge(this, itemstack, other, itemstack1);
|
||||||
} else {
|
} else {
|
||||||
ItemEntity.merge(other, itemstack1, this, itemstack);
|
ItemEntity.merge(other, itemstack1, this, itemstack);
|
||||||
@@ -287,11 +333,16 @@
|
@@ -287,11 +334,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void merge(ItemEntity targetEntity, ItemStack targetStack, ItemEntity sourceEntity, ItemStack sourceStack) {
|
private static void merge(ItemEntity targetEntity, ItemStack targetStack, ItemEntity sourceEntity, ItemStack sourceStack) {
|
||||||
@@ -189,7 +199,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -320,12 +371,17 @@
|
@@ -320,12 +372,17 @@
|
||||||
} else if (!this.getItem().canBeHurtBy(source)) {
|
} else if (!this.getItem().canBeHurtBy(source)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -208,7 +218,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -382,22 +438,86 @@
|
@@ -382,22 +439,86 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getItem().isEmpty()) {
|
if (this.getItem().isEmpty()) {
|
||||||
@@ -225,7 +235,7 @@
|
|||||||
ItemStack itemstack = this.getItem();
|
ItemStack itemstack = this.getItem();
|
||||||
Item item = itemstack.getItem();
|
Item item = itemstack.getItem();
|
||||||
int i = itemstack.getCount();
|
int i = itemstack.getCount();
|
||||||
+
|
|
||||||
+ // CraftBukkit start - fire PlayerPickupItemEvent
|
+ // CraftBukkit start - fire PlayerPickupItemEvent
|
||||||
+ int canHold = player.getInventory().canHold(itemstack);
|
+ int canHold = player.getInventory().canHold(itemstack);
|
||||||
+ int remaining = i - canHold;
|
+ int remaining = i - canHold;
|
||||||
@@ -263,7 +273,7 @@
|
|||||||
+ // Paper end
|
+ // Paper end
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
+ // Call newer event afterwards
|
+ // Call newer event afterwards
|
||||||
+ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((Player) player.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
|
+ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((Player) player.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
|
||||||
+ entityEvent.setCancelled(!entityEvent.getEntity().getCanPickupItems());
|
+ entityEvent.setCancelled(!entityEvent.getEntity().getCanPickupItems());
|
||||||
@@ -298,12 +308,20 @@
|
|||||||
itemstack.setCount(i);
|
itemstack.setCount(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +612,7 @@
|
@@ -438,6 +559,7 @@
|
||||||
|
|
||||||
|
public void setItem(ItemStack stack) {
|
||||||
|
this.getEntityData().set(ItemEntity.DATA_ITEM, stack);
|
||||||
|
+ this.despawnRate = this.level().paperConfig().entities.spawning.altItemDespawnRate.enabled ? this.level().paperConfig().entities.spawning.altItemDespawnRate.items.getOrDefault(stack.getItem(), this.level().spigotConfig.itemDespawnRate) : this.level().spigotConfig.itemDespawnRate; // Paper - Alternative item-despawn-rate
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@@ -492,7 +614,7 @@
|
||||||
|
|
||||||
public void makeFakeItem() {
|
public void makeFakeItem() {
|
||||||
this.setNeverPickUp();
|
this.setNeverPickUp();
|
||||||
- this.age = 5999;
|
- this.age = 5999;
|
||||||
+ this.age = this.level().spigotConfig.itemDespawnRate - 1; // Spigot
|
+ this.age = this.despawnRate - 1; // Spigot // Paper - Alternative item-despawn-rate
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getSpin(float f, float f1) {
|
public static float getSpin(float f, float f1) {
|
||||||
|
Reference in New Issue
Block a user