mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 23:10:16 +01:00
net/minecraft/world/entity/animal/goat/
This commit is contained in:
parent
cb84eaf87a
commit
016503a85f
2 changed files with 51 additions and 76 deletions
|
@ -0,0 +1,51 @@
|
|||
--- a/net/minecraft/world/entity/animal/goat/Goat.java
|
||||
+++ b/net/minecraft/world/entity/animal/goat/Goat.java
|
||||
@@ -231,13 +_,22 @@
|
||||
public InteractionResult mobInteract(Player player, InteractionHand hand) {
|
||||
ItemStack itemInHand = player.getItemInHand(hand);
|
||||
if (itemInHand.is(Items.BUCKET) && !this.isBaby()) {
|
||||
+ // CraftBukkit start - Got milk?
|
||||
+ org.bukkit.event.player.PlayerBucketFillEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level(), player, this.blockPosition(), this.blockPosition(), null, itemInHand, Items.MILK_BUCKET, hand);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ player.containerMenu.sendAllDataToRemote(); // Paper - Fix inventory desync
|
||||
+ return InteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
player.playSound(this.getMilkingSound(), 1.0F, 1.0F);
|
||||
- ItemStack itemStack = ItemUtils.createFilledResult(itemInHand, player, Items.MILK_BUCKET.getDefaultInstance());
|
||||
+ ItemStack itemStack = ItemUtils.createFilledResult(itemInHand, player, org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
|
||||
player.setItemInHand(hand, itemStack);
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
+ boolean isFood = this.isFood(itemInHand); // Paper - track before stack is possibly decreased to 0 (Fixes MC-244739)
|
||||
InteractionResult interactionResult = super.mobInteract(player, hand);
|
||||
- if (interactionResult.consumesAction() && this.isFood(itemInHand)) {
|
||||
+ if (interactionResult.consumesAction() && isFood) { // Paper
|
||||
this.playEatingSound();
|
||||
}
|
||||
|
||||
@@ -350,7 +_,7 @@
|
||||
double d2 = Mth.randomBetween(this.random, -0.2F, 0.2F);
|
||||
ItemEntity itemEntity = new ItemEntity(this.level(), vec3.x(), vec3.y(), vec3.z(), itemStack, d, d1, d2);
|
||||
this.level().addFreshEntity(itemEntity);
|
||||
- return true;
|
||||
+ return this.spawnAtLocation((net.minecraft.server.level.ServerLevel) this.level(), itemEntity) != null; // Paper - Call EntityDropItemEvent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,4 +_,14 @@
|
||||
) {
|
||||
return level.getBlockState(pos.below()).is(BlockTags.GOATS_SPAWNABLE_ON) && isBrightEnoughToSpawn(level, pos);
|
||||
}
|
||||
+ // Paper start - Goat ram API
|
||||
+ public void ram(net.minecraft.world.entity.LivingEntity entity) {
|
||||
+ Brain<Goat> brain = this.getBrain();
|
||||
+ brain.setMemory(MemoryModuleType.RAM_TARGET, entity.position());
|
||||
+ brain.eraseMemory(MemoryModuleType.RAM_COOLDOWN_TICKS);
|
||||
+ brain.eraseMemory(MemoryModuleType.BREED_TARGET);
|
||||
+ brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER);
|
||||
+ brain.setActiveActivityIfPossible(net.minecraft.world.entity.schedule.Activity.RAM);
|
||||
+ }
|
||||
+ // Paper end - Goat ram API
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
--- a/net/minecraft/world/entity/animal/goat/Goat.java
|
||||
+++ b/net/minecraft/world/entity/animal/goat/Goat.java
|
||||
@@ -53,6 +53,11 @@
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.pathfinder.PathType;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
+// CraftBukkit end
|
||||
|
||||
public class Goat extends Animal {
|
||||
|
||||
@@ -184,7 +189,7 @@
|
||||
|
||||
@Override
|
||||
public Brain<Goat> getBrain() {
|
||||
- return super.getBrain();
|
||||
+ return (Brain<Goat>) super.getBrain(); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,15 +234,24 @@
|
||||
ItemStack itemstack = player.getItemInHand(hand);
|
||||
|
||||
if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
|
||||
+ // CraftBukkit start - Got milk?
|
||||
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level(), player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, hand);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ player.containerMenu.sendAllDataToRemote(); // Paper - Fix inventory desync
|
||||
+ return InteractionResult.PASS;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
player.playSound(this.getMilkingSound(), 1.0F, 1.0F);
|
||||
- ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, Items.MILK_BUCKET.getDefaultInstance());
|
||||
+ ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
|
||||
|
||||
player.setItemInHand(hand, itemstack1);
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
+ boolean isFood = this.isFood(itemstack); // Paper - track before stack is possibly decreased to 0 (Fixes MC-244739)
|
||||
InteractionResult enuminteractionresult = super.mobInteract(player, hand);
|
||||
|
||||
- if (enuminteractionresult.consumesAction() && this.isFood(itemstack)) {
|
||||
+ if (enuminteractionresult.consumesAction() && isFood) { // Paper
|
||||
this.playEatingSound();
|
||||
}
|
||||
|
||||
@@ -353,8 +367,7 @@
|
||||
double d2 = (double) Mth.randomBetween(this.random, -0.2F, 0.2F);
|
||||
ItemEntity entityitem = new ItemEntity(this.level(), vec3d.x(), vec3d.y(), vec3d.z(), itemstack, d0, d1, d2);
|
||||
|
||||
- this.level().addFreshEntity(entityitem);
|
||||
- return true;
|
||||
+ return this.spawnAtLocation((net.minecraft.server.level.ServerLevel) this.level(), entityitem) != null; // Paper - Call EntityDropItemEvent
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,4 +396,15 @@
|
||||
public static boolean checkGoatSpawnRules(EntityType<? extends Animal> entityType, LevelAccessor world, EntitySpawnReason spawnReason, BlockPos pos, RandomSource random) {
|
||||
return world.getBlockState(pos.below()).is(BlockTags.GOATS_SPAWNABLE_ON) && isBrightEnoughToSpawn(world, pos);
|
||||
}
|
||||
+
|
||||
+ // Paper start - Goat ram API
|
||||
+ public void ram(net.minecraft.world.entity.LivingEntity entity) {
|
||||
+ Brain<Goat> brain = this.getBrain();
|
||||
+ brain.setMemory(MemoryModuleType.RAM_TARGET, entity.position());
|
||||
+ brain.eraseMemory(MemoryModuleType.RAM_COOLDOWN_TICKS);
|
||||
+ brain.eraseMemory(MemoryModuleType.BREED_TARGET);
|
||||
+ brain.eraseMemory(MemoryModuleType.TEMPTING_PLAYER);
|
||||
+ brain.setActiveActivityIfPossible(net.minecraft.world.entity.schedule.Activity.RAM);
|
||||
+ }
|
||||
+ // Paper end - Goat ram API
|
||||
}
|
Loading…
Reference in a new issue