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