Fix tossed items not being able to be picked up by other players. Closes #9412 (#9404)

This commit is contained in:
Dennis C authored and GitHub committed 2023-03-21 19:15:04 -07:00
1 parent 331374dc7a
commit c58d922324
1 file changed
+27 -24
@@ -7,7 +7,7 @@
+ /**
+ * The maximum age of this EntityItem. The item is expired once this is reached.
+ */
+ public int lifespan = 6000;
+ public int lifespan = ItemEntity.f_149659_;
public ItemEntity(EntityType<? extends ItemEntity> p_31991_, Level p_31992_) {
super(p_31991_, p_31992_);
@@ -15,10 +15,18 @@
this.m_6034_(p_149664_, p_149665_, p_149666_);
this.m_20334_(p_149668_, p_149669_, p_149670_);
this.m_32045_(p_149667_);
+ this.lifespan = (p_149667_.m_41720_() == null ? 6000 : p_149667_.getEntityLifespan(p_149663_));
+ this.lifespan = (p_149667_.m_41720_() == null ? ItemEntity.f_149659_ : p_149667_.getEntityLifespan(p_149663_));
}
private ItemEntity(ItemEntity p_31994_) {
@@ -66,6 +_,7 @@
this.m_20359_(p_31994_);
this.f_31985_ = p_31994_.f_31985_;
this.f_31983_ = p_31994_.f_31983_;
+ this.lifespan = p_31994_.lifespan;
}
public boolean m_213854_() {
@@ -94,6 +_,7 @@
}
@@ -46,7 +54,7 @@
}
this.m_20256_(this.m_20184_().m_82542_((double)f1, 0.98D, (double)f1));
@@ -158,7 +_,14 @@
@@ -158,7 +_,16 @@
}
}
@@ -54,11 +62,13 @@
+ ItemStack item = this.m_32055_();
+ if (!this.f_19853_.f_46443_ && this.f_31985_ >= lifespan) {
+ int hook = net.minecraftforge.event.ForgeEventFactory.onItemExpire(this, item);
+ if (hook < 0) this.m_146870_();
+ else this.lifespan += hook;
+ if (hook < 0) {
+ this.m_146870_();
+ } else {
+ this.lifespan += hook;
+ }
+ }
+
+ if (item.m_41619_()) {
+ if (item.m_41619_() && !this.m_213877_()) {
this.m_146870_();
}
@@ -71,14 +81,6 @@
} else {
return !p_32028_.m_41782_() || p_32028_.m_41783_().equals(p_32027_.m_41783_());
}
@@ -249,6 +_,7 @@
}
public boolean m_6469_(DamageSource p_32013_, float p_32014_) {
+ if (this.f_19853_.f_46443_ || this.m_213877_()) return false; //Forge: Fixes MC-53850
if (this.m_6673_(p_32013_)) {
return false;
} else if (!this.m_32055_().m_41619_() && this.m_32055_().m_150930_(Items.f_42686_) && p_32013_.m_269533_(DamageTypeTags.f_268415_)) {
@@ -262,7 +_,7 @@
this.f_31987_ = (int)((float)this.f_31987_ - p_32014_);
this.m_146852_(GameEvent.f_223706_, p_32013_.m_7639_());
@@ -92,19 +94,21 @@
p_32050_.m_128376_("Health", (short)this.f_31987_);
p_32050_.m_128376_("Age", (short)this.f_31985_);
p_32050_.m_128376_("PickupDelay", (short)this.f_31986_);
+ p_32050_.m_128405_("Lifespan", lifespan);
+ p_32050_.m_128405_("Lifespan", this.lifespan);
if (this.f_31988_ != null) {
p_32050_.m_128362_("Thrower", this.f_31988_);
}
@@ -294,6 +_,7 @@
@@ -294,6 +_,9 @@
if (p_32034_.m_128441_("PickupDelay")) {
this.f_31986_ = p_32034_.m_128448_("PickupDelay");
}
+ if (p_32034_.m_128441_("Lifespan")) lifespan = p_32034_.m_128451_("Lifespan");
+ if (p_32034_.m_128441_("Lifespan")) {
+ this.lifespan = p_32034_.m_128451_("Lifespan");
+ }
if (p_32034_.m_128403_("Owner")) {
this.f_265881_ = p_32034_.m_128342_("Owner");
@@ -313,10 +_,18 @@
@@ -313,10 +_,17 @@
public void m_6123_(Player p_32040_) {
if (!this.f_19853_.f_46443_) {
@@ -113,13 +117,12 @@
Item item = itemstack.m_41720_();
int i = itemstack.m_41613_();
- if (this.f_31986_ == 0 && (this.f_265881_ == null || this.f_265881_.equals(p_32040_.m_20148_())) && p_32040_.m_150109_().m_36054_(itemstack)) {
+
+ int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup(this, p_32040_);
+ if (hook < 0) return;
+
+ ItemStack copy = itemstack.m_41777_();
+ if (this.f_31986_ == 0 && (this.m_19749_() == null || lifespan - this.f_31985_ <= 200 || this.m_19749_().m_20148_().equals(p_32040_.m_20148_())) && (hook == 1 || i <= 0 || p_32040_.m_150109_().m_36054_(itemstack))) {
+ copy.m_41764_(copy.m_41613_() - m_32055_().m_41613_());
+ if (this.f_31986_ == 0 && (this.f_265881_ == null || this.f_265881_.equals(p_32040_.m_20148_())) && (hook == 1 || i <= 0 || p_32040_.m_150109_().m_36054_(itemstack))) {
+ i = copy.m_41613_() - itemstack.m_41613_();
+ copy.m_41764_(i);
+ net.minecraftforge.event.ForgeEventFactory.firePlayerItemPickupEvent(p_32040_, this, copy);
p_32040_.m_7938_(this, i);
if (itemstack.m_41619_()) {
@@ -140,7 +143,7 @@
public void m_32065_() {
this.m_32062_();
- this.f_31985_ = 5999;
+ this.f_31985_ = m_32055_().getEntityLifespan(f_19853_) - 1;
+ this.f_31985_ = m_32055_().getEntityLifespan(this.f_19853_) - 1;
}
public float m_32008_(float p_32009_) {