mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 20:52:12 -07:00
Item#canEntityPickup
This commit is contained in:
@@ -26,15 +26,15 @@
|
|||||||
public GoalSelector targetSelector;
|
public GoalSelector targetSelector;
|
||||||
@Nullable
|
@Nullable
|
||||||
private LivingEntity target;
|
private LivingEntity target;
|
||||||
@@ -131,6 +143,8 @@
|
@@ -132,6 +144,8 @@
|
||||||
private Leashable.LeashData leashData;
|
|
||||||
private BlockPos restrictCenter;
|
private BlockPos restrictCenter;
|
||||||
private float restrictRadius;
|
private float restrictRadius;
|
||||||
+
|
|
||||||
+ public boolean aware = true; // CraftBukkit
|
|
||||||
|
|
||||||
|
+ public boolean aware = true; // CraftBukkit
|
||||||
|
+
|
||||||
protected Mob(EntityType<? extends Mob> type, Level world) {
|
protected Mob(EntityType<? extends Mob> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
|
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
|
||||||
@@ -160,6 +174,12 @@
|
@@ -160,6 +174,12 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
protected void registerGoals() {}
|
protected void registerGoals() {}
|
||||||
|
|
||||||
public static AttributeSupplier.Builder createMobAttributes() {
|
public static AttributeSupplier.Builder createMobAttributes() {
|
||||||
@@ -264,13 +284,44 @@
|
@@ -264,11 +284,42 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected final LivingEntity getTargetFromBrain() {
|
protected final LivingEntity getTargetFromBrain() {
|
||||||
@@ -60,8 +60,8 @@
|
|||||||
- this.target = target;
|
- this.target = target;
|
||||||
+ // CraftBukkit start - fire event
|
+ // CraftBukkit start - fire event
|
||||||
+ this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
+ this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
|
||||||
}
|
+ }
|
||||||
|
+
|
||||||
+ public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
+ public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
|
||||||
+ if (this.getTarget() == entityliving) return false;
|
+ if (this.getTarget() == entityliving) return false;
|
||||||
+ if (fireEvent) {
|
+ if (fireEvent) {
|
||||||
@@ -90,11 +90,9 @@
|
|||||||
+ this.target = entityliving;
|
+ this.target = entityliving;
|
||||||
+ return true;
|
+ return true;
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAttackType(EntityType<?> type) {
|
|
||||||
return type != EntityType.GHAST;
|
|
||||||
@@ -399,6 +450,12 @@
|
@@ -399,6 +450,12 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -148,7 +146,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -623,23 +697,29 @@
|
@@ -608,6 +682,11 @@
|
||||||
|
ItemEntity entityitem = (ItemEntity) iterator.next();
|
||||||
|
|
||||||
|
if (!entityitem.isRemoved() && !entityitem.getItem().isEmpty() && !entityitem.hasPickUpDelay() && this.wantsToPickUp(worldserver, entityitem.getItem())) {
|
||||||
|
+ // Paper start - Item#canEntityPickup
|
||||||
|
+ if (!entityitem.canMobPickup) {
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+ // Paper end - Item#canEntityPickup
|
||||||
|
this.pickUpItem(worldserver, entityitem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -623,23 +702,29 @@
|
||||||
|
|
||||||
protected void pickUpItem(ServerLevel world, ItemEntity itemEntity) {
|
protected void pickUpItem(ServerLevel world, ItemEntity itemEntity) {
|
||||||
ItemStack itemstack = itemEntity.getItem();
|
ItemStack itemstack = itemEntity.getItem();
|
||||||
@@ -182,7 +192,7 @@
|
|||||||
|
|
||||||
if (enumitemslot.isArmor() && !flag) {
|
if (enumitemslot.isArmor() && !flag) {
|
||||||
enumitemslot = EquipmentSlot.MAINHAND;
|
enumitemslot = EquipmentSlot.MAINHAND;
|
||||||
@@ -647,14 +727,22 @@
|
@@ -647,14 +732,22 @@
|
||||||
flag = itemstack1.isEmpty();
|
flag = itemstack1.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +218,7 @@
|
|||||||
|
|
||||||
this.setItemSlotAndDropWhenKilled(enumitemslot, itemstack2);
|
this.setItemSlotAndDropWhenKilled(enumitemslot, itemstack2);
|
||||||
return itemstack2;
|
return itemstack2;
|
||||||
@@ -768,25 +856,29 @@
|
@@ -768,25 +861,29 @@
|
||||||
@Override
|
@Override
|
||||||
public void checkDespawn() {
|
public void checkDespawn() {
|
||||||
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
|
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
|
||||||
@@ -253,7 +263,7 @@
|
|||||||
this.noActionTime = 0;
|
this.noActionTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -799,6 +891,15 @@
|
@@ -799,6 +896,15 @@
|
||||||
@Override
|
@Override
|
||||||
protected final void serverAiStep() {
|
protected final void serverAiStep() {
|
||||||
++this.noActionTime;
|
++this.noActionTime;
|
||||||
@@ -269,7 +279,7 @@
|
|||||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||||
|
|
||||||
gameprofilerfiller.push("sensing");
|
gameprofilerfiller.push("sensing");
|
||||||
@@ -1338,7 +1439,7 @@
|
@@ -1338,7 +1444,7 @@
|
||||||
if (itemstack.getItem() instanceof SpawnEggItem) {
|
if (itemstack.getItem() instanceof SpawnEggItem) {
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
SpawnEggItem itemmonsteregg = (SpawnEggItem) itemstack.getItem();
|
SpawnEggItem itemmonsteregg = (SpawnEggItem) itemstack.getItem();
|
||||||
@@ -278,7 +288,7 @@
|
|||||||
|
|
||||||
optional.ifPresent((entityinsentient) -> {
|
optional.ifPresent((entityinsentient) -> {
|
||||||
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
||||||
@@ -1389,28 +1490,51 @@
|
@@ -1389,28 +1495,51 @@
|
||||||
return this.restrictRadius != -1.0F;
|
return this.restrictRadius != -1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +346,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return t0;
|
return t0;
|
||||||
@@ -1420,10 +1544,22 @@
|
@@ -1420,10 +1549,22 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
|
||||||
@@ -360,7 +370,7 @@
|
|||||||
@Override
|
@Override
|
||||||
public Leashable.LeashData getLeashData() {
|
public Leashable.LeashData getLeashData() {
|
||||||
return this.leashData;
|
return this.leashData;
|
||||||
@@ -1458,6 +1594,7 @@
|
@@ -1458,6 +1599,7 @@
|
||||||
boolean flag1 = super.startRiding(entity, force);
|
boolean flag1 = super.startRiding(entity, force);
|
||||||
|
|
||||||
if (flag1 && this.isLeashed()) {
|
if (flag1 && this.isLeashed()) {
|
||||||
@@ -368,7 +378,7 @@
|
|||||||
this.dropLeash();
|
this.dropLeash();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1542,7 +1679,7 @@
|
@@ -1542,7 +1684,7 @@
|
||||||
|
|
||||||
if (f1 > 0.0F && target instanceof LivingEntity) {
|
if (f1 > 0.0F && target instanceof LivingEntity) {
|
||||||
entityliving = (LivingEntity) target;
|
entityliving = (LivingEntity) target;
|
||||||
|
@@ -54,15 +54,16 @@
|
|||||||
|
|
||||||
public class ItemEntity extends Entity implements TraceableEntity {
|
public class ItemEntity extends Entity implements TraceableEntity {
|
||||||
|
|
||||||
@@ -52,6 +59,7 @@
|
@@ -52,6 +59,8 @@
|
||||||
@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 ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
|
public ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
|
||||||
super(type, world);
|
super(type, world);
|
||||||
@@ -133,12 +141,15 @@
|
@@ -133,12 +142,15 @@
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
if (this.getItem().isEmpty()) {
|
if (this.getItem().isEmpty()) {
|
||||||
@@ -82,7 +83,7 @@
|
|||||||
|
|
||||||
this.xo = this.getX();
|
this.xo = this.getX();
|
||||||
this.yo = this.getY();
|
this.yo = this.getY();
|
||||||
@@ -188,9 +199,11 @@
|
@@ -188,9 +200,11 @@
|
||||||
this.mergeWithNeighbours();
|
this.mergeWithNeighbours();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@
|
|||||||
|
|
||||||
this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing();
|
||||||
if (!this.level().isClientSide) {
|
if (!this.level().isClientSide) {
|
||||||
@@ -201,12 +214,40 @@
|
@@ -201,14 +215,42 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,11 +111,11 @@
|
|||||||
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||||
}
|
}
|
||||||
|
|
||||||
+ }
|
}
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
+ // Spigot start - copied from above
|
+ // Spigot start - copied from above
|
||||||
+ @Override
|
@Override
|
||||||
+ public void inactiveTick() {
|
+ public void inactiveTick() {
|
||||||
+ // CraftBukkit start - Use wall time for pickup and despawn timers
|
+ // CraftBukkit start - Use wall time for pickup and despawn timers
|
||||||
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
|
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
|
||||||
@@ -131,13 +132,15 @@
|
|||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
|
||||||
}
|
+ }
|
||||||
}
|
+ }
|
||||||
+ // Spigot end
|
+ // Spigot end
|
||||||
|
+
|
||||||
@Override
|
+ @Override
|
||||||
public BlockPos getBlockPosBelowThatAffectsMyMovement() {
|
public BlockPos getBlockPosBelowThatAffectsMyMovement() {
|
||||||
@@ -229,7 +270,10 @@
|
return this.getOnPos(0.999999F);
|
||||||
|
}
|
||||||
|
@@ -229,7 +271,10 @@
|
||||||
|
|
||||||
private void mergeWithNeighbours() {
|
private void mergeWithNeighbours() {
|
||||||
if (this.isMergable()) {
|
if (this.isMergable()) {
|
||||||
@@ -149,7 +152,7 @@
|
|||||||
return entityitem != this && entityitem.isMergable();
|
return entityitem != this && entityitem.isMergable();
|
||||||
});
|
});
|
||||||
Iterator iterator = list.iterator();
|
Iterator iterator = list.iterator();
|
||||||
@@ -259,7 +303,7 @@
|
@@ -259,7 +304,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)) {
|
||||||
@@ -158,7 +161,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 +331,16 @@
|
@@ -287,11 +332,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) {
|
||||||
@@ -176,7 +179,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -320,12 +369,17 @@
|
@@ -320,12 +370,17 @@
|
||||||
} else if (!this.getItem().canBeHurtBy(source)) {
|
} else if (!this.getItem().canBeHurtBy(source)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -195,7 +198,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -382,22 +436,62 @@
|
@@ -382,22 +437,62 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getItem().isEmpty()) {
|
if (this.getItem().isEmpty()) {
|
||||||
@@ -212,7 +215,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;
|
||||||
@@ -227,7 +230,7 @@
|
|||||||
+ itemstack.setCount(i); // SPIGOT-5294 - restore count
|
+ itemstack.setCount(i); // SPIGOT-5294 - restore count
|
||||||
+ 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());
|
||||||
@@ -261,7 +264,7 @@
|
|||||||
itemstack.setCount(i);
|
itemstack.setCount(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +586,7 @@
|
@@ -492,7 +587,7 @@
|
||||||
|
|
||||||
public void makeFakeItem() {
|
public void makeFakeItem() {
|
||||||
this.setNeverPickUp();
|
this.setNeverPickUp();
|
||||||
|
@@ -63,6 +63,18 @@ public class CraftItem extends CraftEntity implements Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start
|
||||||
|
@Override
|
||||||
|
public boolean canMobPickup() {
|
||||||
|
return this.getHandle().canMobPickup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCanMobPickup(boolean canMobPickup) {
|
||||||
|
this.getHandle().canMobPickup = canMobPickup;
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOwner(UUID uuid) {
|
public void setOwner(UUID uuid) {
|
||||||
this.getHandle().setTarget(uuid);
|
this.getHandle().setTarget(uuid);
|
||||||
|
Reference in New Issue
Block a user