Add missing forceDrop toggles

This commit is contained in:
Jake Potrebic
2021-07-20 21:25:35 -07:00
parent a600754f0d
commit 29ce813416
6 changed files with 125 additions and 32 deletions

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/world/entity/ai/behavior/WorkAtComposter.java
+++ b/net/minecraft/world/entity/ai/behavior/WorkAtComposter.java
@@ -86,7 +86,9 @@
simpleContainer.removeItemType(Items.WHEAT, m);
ItemStack itemStack = simpleContainer.addItem(new ItemStack(Items.BREAD, l));
if (!itemStack.isEmpty()) {
+ villager.forceDrops = true; // Paper - Add missing forceDrop toggles
villager.spawnAtLocation(world, itemStack, 0.5F);
+ villager.forceDrops = false; // Paper - Add missing forceDrop toggles
}
}
}

View File

@@ -22,7 +22,17 @@
} }
} }
@@ -541,14 +548,14 @@ @@ -533,7 +540,9 @@
if (world1 instanceof ServerLevel worldserver) {
if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.dropFromGiftLootTable(worldserver, BuiltInLootTables.PANDA_SNEEZE, this::spawnAtLocation);
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
}
}
@@ -541,14 +550,14 @@
@Override @Override
protected void pickUpItem(ServerLevel world, ItemEntity itemEntity) { protected void pickUpItem(ServerLevel world, ItemEntity itemEntity) {
@@ -39,7 +49,17 @@
} }
} }
@@ -772,7 +779,7 @@ @@ -657,7 +666,9 @@
ItemStack itemstack1 = this.getItemBySlot(EquipmentSlot.MAINHAND);
if (!itemstack1.isEmpty() && !player.hasInfiniteMaterials()) {
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.spawnAtLocation(worldserver, itemstack1);
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
}
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(itemstack.getItem(), 1));
@@ -772,7 +783,7 @@
} }
public static Panda.Gene byName(String name) { public static Panda.Gene byName(String name) {
@@ -48,7 +68,7 @@
} }
public static Panda.Gene getRandom(RandomSource random) { public static Panda.Gene getRandom(RandomSource random) {
@@ -876,10 +883,10 @@ @@ -876,10 +887,10 @@
private final Panda panda; private final Panda panda;
public PandaAvoidGoal(Panda panda, Class<T> fleeFromType, float distance, double slowSpeed, double fastSpeed) { public PandaAvoidGoal(Panda panda, Class<T> fleeFromType, float distance, double slowSpeed, double fastSpeed) {
@@ -62,7 +82,17 @@
this.panda = panda; this.panda = panda;
} }
@@ -1116,7 +1123,7 @@ @@ -935,7 +946,9 @@
ItemStack itemstack = Panda.this.getItemBySlot(EquipmentSlot.MAINHAND);
if (!itemstack.isEmpty()) {
+ Panda.this.forceDrops = true; // Paper - Add missing forceDrop toggles
Panda.this.spawnAtLocation(getServerLevel(Panda.this.level()), itemstack);
+ Panda.this.forceDrops = false; // Paper - Add missing forceDrop toggles
Panda.this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
int i = Panda.this.isLazy() ? Panda.this.random.nextInt(50) + 10 : Panda.this.random.nextInt(150) + 10;
@@ -1116,7 +1129,7 @@
@Override @Override
protected void alertOther(Mob mob, LivingEntity target) { protected void alertOther(Mob mob, LivingEntity target) {
if (mob instanceof Panda && mob.isAggressive()) { if (mob instanceof Panda && mob.isAggressive()) {

View File

@@ -13,3 +13,15 @@
this.shear(worldserver, SoundSource.PLAYERS, itemstack); this.shear(worldserver, SoundSource.PLAYERS, itemstack);
this.gameEvent(GameEvent.SHEAR, player); this.gameEvent(GameEvent.SHEAR, player);
itemstack.hurtAndBreak(1, player, getSlotForHand(hand)); itemstack.hurtAndBreak(1, player, getSlotForHand(hand));
@@ -139,9 +145,11 @@
}
private void spawnShearedMushrooms(ServerLevel world, ItemStack shears) {
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.dropFromShearingLootTable(world, BuiltInLootTables.BOGGED_SHEAR, shears, (worldserver1, itemstack1) -> {
this.spawnAtLocation(worldserver1, itemstack1, this.getBbHeight());
});
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
}
@Override

View File

@@ -88,7 +88,19 @@
} }
@Override @Override
@@ -374,7 +400,7 @@ @@ -300,9 +326,11 @@
@Override
protected void finishConversion(ServerLevel world) {
PiglinAi.cancelAdmiring(world, this);
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.inventory.removeAllItems().forEach((itemstack) -> {
this.spawnAtLocation(world, itemstack);
});
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
super.finishConversion(world);
}
@@ -374,7 +402,7 @@
} }
protected void holdInOffHand(ItemStack stack) { protected void holdInOffHand(ItemStack stack) {
@@ -97,7 +109,7 @@
this.setItemSlot(EquipmentSlot.OFFHAND, stack); this.setItemSlot(EquipmentSlot.OFFHAND, stack);
this.setGuaranteedDrop(EquipmentSlot.OFFHAND); this.setGuaranteedDrop(EquipmentSlot.OFFHAND);
} else { } else {
@@ -401,8 +427,8 @@ @@ -401,8 +429,8 @@
return false; return false;
} else { } else {
TagKey<Item> tagkey = this.getPreferredWeaponType(); TagKey<Item> tagkey = this.getPreferredWeaponType();
@@ -108,7 +120,7 @@
return flag && !flag1 ? true : (!flag && flag1 ? false : super.canReplaceCurrentItem(newStack, currentStack, slot)); return flag && !flag1 ? true : (!flag && flag1 ? false : super.canReplaceCurrentItem(newStack, currentStack, slot));
} }
@@ -431,7 +457,7 @@ @@ -431,7 +459,7 @@
@Override @Override
protected SoundEvent getAmbientSound() { protected SoundEvent getAmbientSound() {

View File

@@ -83,7 +83,17 @@
if (!flag) { if (!flag) {
PiglinAi.putInInventory(piglin, itemstack); PiglinAi.putInInventory(piglin, itemstack);
@@ -272,7 +284,7 @@ @@ -261,7 +273,9 @@
private static void holdInOffhand(ServerLevel world, Piglin piglin, ItemStack stack) {
if (PiglinAi.isHoldingItemInOffHand(piglin)) {
+ piglin.forceDrops = true; // Paper - Add missing forceDrop toggles
piglin.spawnAtLocation(world, piglin.getItemInHand(InteractionHand.OFF_HAND));
+ piglin.forceDrops = false; // Paper - Add missing forceDrop toggles
}
piglin.holdInOffHand(stack);
@@ -272,7 +286,7 @@
ItemStack itemstack1 = itemstack.split(1); ItemStack itemstack1 = itemstack.split(1);
if (itemstack.isEmpty()) { if (itemstack.isEmpty()) {
@@ -92,7 +102,7 @@
} else { } else {
stack.setItem(itemstack); stack.setItem(itemstack);
} }
@@ -287,9 +299,14 @@ @@ -287,9 +301,14 @@
boolean flag1; boolean flag1;
if (piglin.isAdult()) { if (piglin.isAdult()) {
@@ -109,7 +119,7 @@
} else if (!flag1) { } else if (!flag1) {
boolean flag2 = !piglin.equipItemIfPossible(world, itemstack).isEmpty(); boolean flag2 = !piglin.equipItemIfPossible(world, itemstack).isEmpty();
@@ -302,7 +319,7 @@ @@ -302,7 +321,7 @@
if (!flag1) { if (!flag1) {
ItemStack itemstack1 = piglin.getMainHandItem(); ItemStack itemstack1 = piglin.getMainHandItem();
@@ -118,7 +128,17 @@
PiglinAi.putInInventory(piglin, itemstack1); PiglinAi.putInInventory(piglin, itemstack1);
} else { } else {
PiglinAi.throwItems(piglin, Collections.singletonList(itemstack1)); PiglinAi.throwItems(piglin, Collections.singletonList(itemstack1));
@@ -379,14 +396,20 @@ @@ -316,7 +335,9 @@
protected static void cancelAdmiring(ServerLevel world, Piglin piglin) {
if (PiglinAi.isAdmiringItem(piglin) && !piglin.getOffhandItem().isEmpty()) {
+ piglin.forceDrops = true; // Paper - Add missing forceDrop toggles
piglin.spawnAtLocation(world, piglin.getOffhandItem());
+ piglin.forceDrops = false; // Paper - Add missing forceDrop toggles
piglin.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY);
}
@@ -379,7 +400,7 @@
return false; return false;
} else if (PiglinAi.isAdmiringDisabled(piglin) && piglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) { } else if (PiglinAi.isAdmiringDisabled(piglin) && piglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) {
return false; return false;
@@ -127,20 +147,20 @@
return PiglinAi.isNotHoldingLovedItemInOffHand(piglin); return PiglinAi.isNotHoldingLovedItemInOffHand(piglin);
} else { } else {
boolean flag = piglin.canAddToInventory(stack); boolean flag = piglin.canAddToInventory(stack);
@@ -388,6 +409,12 @@
return stack.is(Items.GOLD_NUGGET) ? flag : (PiglinAi.isFood(stack) ? !PiglinAi.hasEatenRecently(piglin) && flag : (!PiglinAi.isLovedItem(stack) ? piglin.canReplaceCurrentItem(stack) : PiglinAi.isNotHoldingLovedItemInOffHand(piglin) && flag));
} }
+ } }
+
+ // CraftBukkit start - Added method to allow checking for custom payment items + // CraftBukkit start - Added method to allow checking for custom payment items
+ protected static boolean isLovedItem(ItemStack itemstack, Piglin piglin) { + protected static boolean isLovedItem(ItemStack itemstack, Piglin piglin) {
+ return PiglinAi.isLovedItem(itemstack) || (piglin.interestItems.contains(itemstack.getItem()) || piglin.allowedBarterItems.contains(itemstack.getItem())); + return PiglinAi.isLovedItem(itemstack) || (piglin.interestItems.contains(itemstack.getItem()) || piglin.allowedBarterItems.contains(itemstack.getItem()));
} + }
+ // CraftBukkit end + // CraftBukkit end
+
protected static boolean isLovedItem(ItemStack stack) { protected static boolean isLovedItem(ItemStack stack) {
return stack.is(ItemTags.PIGLIN_LOVED); return stack.is(ItemTags.PIGLIN_LOVED);
@@ -481,7 +504,7 @@ }
@@ -481,7 +508,7 @@
} }
protected static boolean canAdmire(Piglin piglin, ItemStack nearbyItems) { protected static boolean canAdmire(Piglin piglin, ItemStack nearbyItems) {
@@ -149,21 +169,20 @@
} }
protected static void wasHurtBy(ServerLevel world, Piglin piglin, LivingEntity attacker) { protected static void wasHurtBy(ServerLevel world, Piglin piglin, LivingEntity attacker) {
@@ -733,7 +756,13 @@ @@ -735,6 +762,12 @@
private static boolean isAdmiringItem(Piglin entity) {
return entity.getBrain().hasMemoryValue(MemoryModuleType.ADMIRING_ITEM); return entity.getBrain().hasMemoryValue(MemoryModuleType.ADMIRING_ITEM);
+ } }
+
+ // CraftBukkit start - Changes to allow custom payment for bartering + // CraftBukkit start - Changes to allow custom payment for bartering
+ private static boolean isBarterCurrency(ItemStack itemstack, Piglin piglin) { + private static boolean isBarterCurrency(ItemStack itemstack, Piglin piglin) {
+ return PiglinAi.isBarterCurrency(itemstack) || piglin.allowedBarterItems.contains(itemstack.getItem()); + return PiglinAi.isBarterCurrency(itemstack) || piglin.allowedBarterItems.contains(itemstack.getItem());
} + }
+ // CraftBukkit end + // CraftBukkit end
+
private static boolean isBarterCurrency(ItemStack stack) { private static boolean isBarterCurrency(ItemStack stack) {
return stack.is(PiglinAi.BARTERING_ITEM); return stack.is(PiglinAi.BARTERING_ITEM);
@@ -772,7 +801,7 @@ }
@@ -772,7 +805,7 @@
} }
private static boolean isNotHoldingLovedItemInOffHand(Piglin piglin) { private static boolean isNotHoldingLovedItemInOffHand(Piglin piglin) {

View File

@@ -10,7 +10,15 @@
public abstract class Raider extends PatrollingMonster { public abstract class Raider extends PatrollingMonster {
@@ -236,7 +239,7 @@ @@ -230,13 +233,15 @@
double d0 = (double) this.getEquipmentDropChance(enumitemslot);
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
+ this.forceDrops = true; // Paper - Add missing forceDrop toggles
this.spawnAtLocation(world, itemstack1);
+ this.forceDrops = false; // Paper - Add missing forceDrop toggles
}
this.onItemPickup(itemEntity); this.onItemPickup(itemEntity);
this.setItemSlot(enumitemslot, itemstack); this.setItemSlot(enumitemslot, itemstack);
this.take(itemEntity, itemstack.getCount()); this.take(itemEntity, itemstack.getCount());
@@ -19,7 +27,7 @@
this.getCurrentRaid().setLeader(this.getWave(), this); this.getCurrentRaid().setLeader(this.getWave(), this);
this.setPatrolLeader(true); this.setPatrolLeader(true);
} else { } else {
@@ -290,7 +293,7 @@ @@ -290,7 +295,7 @@
@Nullable @Nullable
private ItemEntity pursuedBannerItemEntity; private ItemEntity pursuedBannerItemEntity;
@@ -28,7 +36,7 @@
this.mob = entityraider; this.mob = entityraider;
this.setFlags(EnumSet.of(Goal.Flag.MOVE)); this.setFlags(EnumSet.of(Goal.Flag.MOVE));
} }
@@ -335,6 +338,7 @@ @@ -335,6 +340,7 @@
} }
private boolean cannotPickUpBanner() { private boolean cannotPickUpBanner() {
@@ -36,7 +44,7 @@
if (!this.mob.hasActiveRaid()) { if (!this.mob.hasActiveRaid()) {
return true; return true;
} else if (this.mob.getCurrentRaid().isOver()) { } else if (this.mob.getCurrentRaid().isOver()) {
@@ -518,7 +522,7 @@ @@ -518,7 +524,7 @@
} }
} }
@@ -45,7 +53,7 @@
private final Raider mob; private final Raider mob;
private final float hostileRadiusSqr; private final float hostileRadiusSqr;
@@ -547,7 +551,7 @@ @@ -547,7 +553,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
Raider entityraider = (Raider) iterator.next(); Raider entityraider = (Raider) iterator.next();
@@ -54,7 +62,7 @@
} }
} }
@@ -564,7 +568,7 @@ @@ -564,7 +570,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
Raider entityraider = (Raider) iterator.next(); Raider entityraider = (Raider) iterator.next();