mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Fix silent equipment change for mobs
This commit is contained in:
parent
675028a699
commit
bf607b1e23
3 changed files with 106 additions and 26 deletions
|
@ -35,13 +35,12 @@
|
||||||
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);
|
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
|
||||||
@@ -157,8 +171,14 @@
|
@@ -158,7 +172,13 @@
|
||||||
if (world instanceof ServerLevel) {
|
|
||||||
this.registerGoals();
|
this.registerGoals();
|
||||||
}
|
}
|
||||||
+
|
|
||||||
+ }
|
|
||||||
|
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ public void setPersistenceRequired(boolean persistenceRequired) {
|
+ public void setPersistenceRequired(boolean persistenceRequired) {
|
||||||
+ this.persistenceRequired = persistenceRequired;
|
+ this.persistenceRequired = persistenceRequired;
|
||||||
|
@ -95,20 +94,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -397,7 +448,13 @@
|
@@ -399,6 +450,12 @@
|
||||||
@Nullable
|
|
||||||
protected SoundEvent getAmbientSound() {
|
|
||||||
return null;
|
return null;
|
||||||
+ }
|
}
|
||||||
+
|
|
||||||
+ // CraftBukkit start - Add delegate method
|
+ // CraftBukkit start - Add delegate method
|
||||||
+ public SoundEvent getAmbientSound0() {
|
+ public SoundEvent getAmbientSound0() {
|
||||||
+ return this.getAmbientSound();
|
+ return this.getAmbientSound();
|
||||||
}
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
|
+
|
||||||
@Override
|
@Override
|
||||||
public void addAdditionalSaveData(CompoundTag nbt) {
|
public void addAdditionalSaveData(CompoundTag nbt) {
|
||||||
|
super.addAdditionalSaveData(nbt);
|
||||||
@@ -473,13 +530,25 @@
|
@@ -473,13 +530,25 @@
|
||||||
nbt.putBoolean("NoAI", this.isNoAi());
|
nbt.putBoolean("NoAI", this.isNoAi());
|
||||||
}
|
}
|
||||||
|
@ -282,21 +280,47 @@
|
||||||
ProfilerFiller gameprofilerfiller = Profiler.get();
|
ProfilerFiller gameprofilerfiller = Profiler.get();
|
||||||
|
|
||||||
gameprofilerfiller.push("sensing");
|
gameprofilerfiller.push("sensing");
|
||||||
@@ -1009,7 +1115,13 @@
|
@@ -994,23 +1100,36 @@
|
||||||
this.onEquipItem(slot, itemstack1, stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
||||||
|
+ // Paper start - Fix silent equipment change
|
||||||
|
+ setItemSlot(slot, stack, false);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) {
|
||||||
|
+ // Paper end - Fix silent equipment change
|
||||||
|
this.verifyEquippedItem(stack);
|
||||||
|
switch (slot.getType()) {
|
||||||
|
case HAND:
|
||||||
|
- this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack);
|
||||||
|
+ this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack, silent); // Paper - Fix silent equipment change
|
||||||
|
break;
|
||||||
|
case HUMANOID_ARMOR:
|
||||||
|
- this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack);
|
||||||
|
+ this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack, silent); // Paper - Fix silent equipment change
|
||||||
|
break;
|
||||||
|
case ANIMAL_ARMOR:
|
||||||
|
ItemStack itemstack1 = this.bodyArmorItem;
|
||||||
|
|
||||||
|
this.bodyArmorItem = stack;
|
||||||
|
- this.onEquipItem(slot, itemstack1, stack);
|
||||||
|
+ this.onEquipItem(slot, itemstack1, stack, silent); // Paper - Fix silent equipment change
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+ // Paper start
|
+ // Paper start
|
||||||
+ protected boolean shouldSkipLoot(EquipmentSlot slot) { // method to avoid to fallback into the global mob loot logic (i.e fox)
|
+ protected boolean shouldSkipLoot(EquipmentSlot slot) { // method to avoid to fallback into the global mob loot logic (i.e fox)
|
||||||
+ return false;
|
+ return false;
|
||||||
}
|
+ }
|
||||||
+ // Paper end
|
+ // Paper end
|
||||||
|
+
|
||||||
@Override
|
@Override
|
||||||
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
|
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
|
||||||
@@ -1018,6 +1130,7 @@
|
super.dropCustomDeathLoot(world, source, causedByPlayer);
|
||||||
|
@@ -1018,6 +1137,7 @@
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
EquipmentSlot enumitemslot = (EquipmentSlot) iterator.next();
|
EquipmentSlot enumitemslot = (EquipmentSlot) iterator.next();
|
||||||
|
@ -304,7 +328,7 @@
|
||||||
ItemStack itemstack = this.getItemBySlot(enumitemslot);
|
ItemStack itemstack = this.getItemBySlot(enumitemslot);
|
||||||
float f = this.getEquipmentDropChance(enumitemslot);
|
float f = this.getEquipmentDropChance(enumitemslot);
|
||||||
|
|
||||||
@@ -1042,7 +1155,13 @@
|
@@ -1042,7 +1162,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.spawnAtLocation(world, itemstack);
|
this.spawnAtLocation(world, itemstack);
|
||||||
|
@ -318,7 +342,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1338,7 +1457,7 @@
|
@@ -1338,7 +1464,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();
|
||||||
|
@ -327,7 +351,7 @@
|
||||||
|
|
||||||
optional.ifPresent((entityinsentient) -> {
|
optional.ifPresent((entityinsentient) -> {
|
||||||
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
this.onOffspringSpawnedFromEgg(player, entityinsentient);
|
||||||
@@ -1389,28 +1508,51 @@
|
@@ -1389,28 +1515,51 @@
|
||||||
return this.restrictRadius != -1.0F;
|
return this.restrictRadius != -1.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +409,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return t0;
|
return t0;
|
||||||
@@ -1420,10 +1562,22 @@
|
@@ -1420,10 +1569,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) {
|
||||||
|
@ -409,7 +433,7 @@
|
||||||
@Override
|
@Override
|
||||||
public Leashable.LeashData getLeashData() {
|
public Leashable.LeashData getLeashData() {
|
||||||
return this.leashData;
|
return this.leashData;
|
||||||
@@ -1458,7 +1612,15 @@
|
@@ -1458,7 +1619,15 @@
|
||||||
boolean flag1 = super.startRiding(entity, force);
|
boolean flag1 = super.startRiding(entity, force);
|
||||||
|
|
||||||
if (flag1 && this.isLeashed()) {
|
if (flag1 && this.isLeashed()) {
|
||||||
|
@ -426,7 +450,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag1;
|
return flag1;
|
||||||
@@ -1542,7 +1704,7 @@
|
@@ -1542,7 +1711,7 @@
|
||||||
|
|
||||||
if (f1 > 0.0F && target instanceof LivingEntity) {
|
if (f1 > 0.0F && target instanceof LivingEntity) {
|
||||||
entityliving = (LivingEntity) target;
|
entityliving = (LivingEntity) target;
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.playSound(SoundEvents.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F));
|
this.playSound(SoundEvents.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F));
|
||||||
@@ -233,9 +249,22 @@
|
@@ -233,11 +249,24 @@
|
||||||
public void readAdditionalSaveData(CompoundTag nbt) {
|
public void readAdditionalSaveData(CompoundTag nbt) {
|
||||||
super.readAdditionalSaveData(nbt);
|
super.readAdditionalSaveData(nbt);
|
||||||
this.reassessWeaponGoal();
|
this.reassessWeaponGoal();
|
||||||
|
@ -58,6 +58,8 @@
|
||||||
|
|
||||||
+ // Paper start - shouldBurnInDay API
|
+ // Paper start - shouldBurnInDay API
|
||||||
@Override
|
@Override
|
||||||
|
- public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
||||||
|
- super.setItemSlot(slot, stack);
|
||||||
+ public void addAdditionalSaveData(CompoundTag nbt) {
|
+ public void addAdditionalSaveData(CompoundTag nbt) {
|
||||||
+ super.addAdditionalSaveData(nbt);
|
+ super.addAdditionalSaveData(nbt);
|
||||||
+ nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay);
|
+ nbt.putBoolean("Paper.ShouldBurnInDay", this.shouldBurnInDay);
|
||||||
|
@ -65,6 +67,8 @@
|
||||||
+ // Paper end - shouldBurnInDay API
|
+ // Paper end - shouldBurnInDay API
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
|
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) { // Paper - Fix silent equipment change
|
||||||
super.setItemSlot(slot, stack);
|
+ super.setItemSlot(slot, stack, silent); // Paper - Fix silent equipment change
|
||||||
if (!this.level().isClientSide) {
|
if (!this.level().isClientSide) {
|
||||||
|
this.reassessWeaponGoal();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package io.papermc.paper.entity;
|
||||||
|
|
||||||
|
import io.github.classgraph.ClassGraph;
|
||||||
|
import io.github.classgraph.ClassInfo;
|
||||||
|
import io.github.classgraph.MethodInfo;
|
||||||
|
import io.github.classgraph.MethodInfoList;
|
||||||
|
import io.github.classgraph.MethodParameterInfo;
|
||||||
|
import io.github.classgraph.ScanResult;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import org.bukkit.support.environment.Normal;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
@Normal
|
||||||
|
public class EntitySetItemSlotSilentOverrideTest {
|
||||||
|
|
||||||
|
public static Stream<ClassInfo> parameters() {
|
||||||
|
final List<ClassInfo> classInfo = new ArrayList<>();
|
||||||
|
try (ScanResult scanResult = new ClassGraph()
|
||||||
|
.enableClassInfo()
|
||||||
|
.enableMethodInfo()
|
||||||
|
.whitelistPackages("net.minecraft")
|
||||||
|
.scan()
|
||||||
|
) {
|
||||||
|
for (final ClassInfo subclass : scanResult.getSubclasses("net.minecraft.world.entity.LivingEntity")) {
|
||||||
|
final MethodInfoList setItemSlot = subclass.getDeclaredMethodInfo("setItemSlot");
|
||||||
|
if (!setItemSlot.isEmpty()) {
|
||||||
|
classInfo.add(subclass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return classInfo.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("parameters")
|
||||||
|
public void checkSetItemSlotSilentOverrides(ClassInfo overridesSetItemSlot) {
|
||||||
|
final MethodInfoList setItemSlot = overridesSetItemSlot.getDeclaredMethodInfo("setItemSlot");
|
||||||
|
for (final MethodInfo methodInfo : setItemSlot) {
|
||||||
|
for (final MethodParameterInfo methodParameterInfo : methodInfo.getParameterInfo()) {
|
||||||
|
if ("boolean".equals(methodParameterInfo.getTypeDescriptor().toStringWithSimpleNames())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail(overridesSetItemSlot.getName() + " needs to override setItemSlot with the boolean silent parameter as well");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue