diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Animal.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Animal.java.patch | 269 |
1 files changed, 269 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Animal.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Animal.java.patch new file mode 100644 index 0000000000..92d0f6be99 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Animal.java.patch @@ -0,0 +1,269 @@ +--- a/net/minecraft/world/entity/animal/Animal.java ++++ b/net/minecraft/world/entity/animal/Animal.java +@@ -12,13 +12,13 @@ + import net.minecraft.stats.Stats; + import net.minecraft.tags.BlockTags; + import net.minecraft.util.RandomSource; +-import net.minecraft.world.InteractionHand; ++import net.minecraft.world.EnumHand; + import net.minecraft.world.InteractionResult; + import net.minecraft.world.damagesource.DamageSource; + import net.minecraft.world.entity.AgeableMob; + import net.minecraft.world.entity.EntityType; ++import net.minecraft.world.entity.EnumMobSpawn; + import net.minecraft.world.entity.ExperienceOrb; +-import net.minecraft.world.entity.MobSpawnType; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.item.Items; +@@ -29,12 +29,19 @@ + import net.minecraft.world.level.LevelReader; + import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.level.pathfinder.BlockPathTypes; ++// CraftBukkit start ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.event.entity.EntityBreedEvent; ++import org.bukkit.event.entity.EntityEnterLoveModeEvent; ++// CraftBukkit end + + public abstract class Animal extends AgeableMob { ++ + protected static final int PARENT_AGE_AFTER_BREEDING = 6000; +- private int inLove; ++ public int inLove; + @Nullable +- private UUID loveCause; ++ public UUID loveCause; ++ public ItemStack breedItem; // CraftBukkit - Add breedItem variable + + protected Animal(EntityType<? extends Animal> entityType, Level level) { + super(entityType, level); +@@ -59,14 +66,16 @@ + } + + if (this.inLove > 0) { +- this.inLove--; ++ --this.inLove; + if (this.inLove % 10 == 0) { +- double d = this.random.nextGaussian() * 0.02; +- double d1 = this.random.nextGaussian() * 0.02; +- double d2 = this.random.nextGaussian() * 0.02; +- this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0), this.getRandomY() + 0.5, this.getRandomZ(1.0), d, d1, d2); ++ double d0 = this.random.nextGaussian() * 0.02D; ++ double d1 = this.random.nextGaussian() * 0.02D; ++ double d2 = this.random.nextGaussian() * 0.02D; ++ ++ this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0D), this.getRandomY() + 0.5D, this.getRandomZ(1.0D), d0, d1, d2); + } + } ++ + } + + @Override +@@ -74,8 +83,13 @@ + if (this.isInvulnerableTo(source)) { + return false; + } else { ++ // CraftBukkit start ++ boolean result = super.hurt(source, amount); ++ if (result) { + this.inLove = 0; +- return super.hurt(source, amount); ++ } ++ return result; ++ // CraftBukkit end + } + } + +@@ -91,6 +105,7 @@ + if (this.loveCause != null) { + compound.putUUID("LoveCause", this.loveCause); + } ++ + } + + @Override +@@ -100,10 +115,9 @@ + this.loveCause = compound.hasUUID("LoveCause") ? compound.getUUID("LoveCause") : null; + } + +- public static boolean checkAnimalSpawnRules( +- EntityType<? extends Animal> animal, LevelAccessor level, MobSpawnType spawnType, BlockPos pos, RandomSource random +- ) { +- boolean flag = MobSpawnType.ignoresLightRequirements(spawnType) || isBrightEnoughToSpawn(level, pos); ++ public static boolean checkAnimalSpawnRules(EntityType<? extends Animal> animal, LevelAccessor level, EnumMobSpawn spawnType, BlockPos pos, RandomSource random) { ++ boolean flag = EnumMobSpawn.ignoresLightRequirements(spawnType) || isBrightEnoughToSpawn(level, pos); ++ + return level.getBlockState(pos.below()).is(BlockTags.ANIMALS_SPAWNABLE_ON) && flag; + } + +@@ -131,19 +145,21 @@ + } + + @Override +- public InteractionResult mobInteract(Player player, InteractionHand hand) { +- ItemStack itemInHand = player.getItemInHand(hand); +- if (this.isFood(itemInHand)) { +- int age = this.getAge(); +- if (!this.level().isClientSide && age == 0 && this.canFallInLove()) { +- this.usePlayerItem(player, hand, itemInHand); ++ public InteractionResult mobInteract(Player player, EnumHand hand) { ++ ItemStack itemstack = player.getItemInHand(hand); ++ ++ if (this.isFood(itemstack)) { ++ int i = this.getAge(); ++ ++ if (!this.level().isClientSide && i == 0 && this.canFallInLove()) { ++ this.usePlayerItem(player, hand, itemstack); + this.setInLove(player); + return InteractionResult.SUCCESS; + } + + if (this.isBaby()) { +- this.usePlayerItem(player, hand, itemInHand); +- this.ageUp(getSpeedUpSecondsWhenFeeding(-age), true); ++ this.usePlayerItem(player, hand, itemstack); ++ this.ageUp(getSpeedUpSecondsWhenFeeding(-i), true); + return InteractionResult.sidedSuccess(this.level().isClientSide); + } + +@@ -155,10 +171,11 @@ + return super.mobInteract(player, hand); + } + +- protected void usePlayerItem(Player player, InteractionHand hand, ItemStack stack) { ++ protected void usePlayerItem(Player player, EnumHand hand, ItemStack stack) { + if (!player.getAbilities().instabuild) { + stack.shrink(1); + } ++ + } + + public boolean canFallInLove() { +@@ -166,12 +183,19 @@ + } + + public void setInLove(@Nullable Player player) { +- this.inLove = 600; ++ // CraftBukkit start ++ EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(player, this, 600); ++ if (entityEnterLoveModeEvent.isCancelled()) { ++ return; ++ } ++ this.inLove = entityEnterLoveModeEvent.getTicksInLove(); ++ // CraftBukkit end + if (player != null) { + this.loveCause = player.getUUID(); + } ++ this.breedItem = player.getInventory().getSelected(); // CraftBukkit + +- this.level().broadcastEntityEvent(this, (byte)18); ++ this.level().broadcastEntityEvent(this, (byte) 18); + } + + public void setInLoveTime(int inLove) { +@@ -187,8 +211,9 @@ + if (this.loveCause == null) { + return null; + } else { +- Player playerByUUID = this.level().getPlayerByUUID(this.loveCause); +- return playerByUUID instanceof ServerPlayer ? (ServerPlayer)playerByUUID : null; ++ Player entityhuman = this.level().getPlayerByUUID(this.loveCause); ++ ++ return entityhuman instanceof ServerPlayer ? (ServerPlayer) entityhuman : null; + } + } + +@@ -201,45 +226,72 @@ + } + + public boolean canMate(Animal otherAnimal) { +- return otherAnimal != this && otherAnimal.getClass() == this.getClass() && this.isInLove() && otherAnimal.isInLove(); ++ return otherAnimal == this ? false : (otherAnimal.getClass() != this.getClass() ? false : this.isInLove() && otherAnimal.isInLove()); + } + + public void spawnChildFromBreeding(ServerLevel level, Animal mate) { +- AgeableMob breedOffspring = this.getBreedOffspring(level, mate); +- if (breedOffspring != null) { +- breedOffspring.setBaby(true); +- breedOffspring.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); +- this.finalizeSpawnChildFromBreeding(level, mate, breedOffspring); +- level.addFreshEntityWithPassengers(breedOffspring); ++ AgeableMob entityageable = this.getBreedOffspring(level, mate); ++ ++ if (entityageable != null) { ++ entityageable.setBaby(true); ++ entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); ++ // CraftBukkit start - call EntityBreedEvent ++ ServerPlayer breeder = Optional.ofNullable(this.getLoveCause()).or(() -> { ++ return Optional.ofNullable(mate.getLoveCause()); ++ }).orElse(null); ++ int experience = this.getRandom().nextInt(7) + 1; ++ EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, mate, breeder, this.breedItem, experience); ++ if (entityBreedEvent.isCancelled()) { ++ return; ++ } ++ experience = entityBreedEvent.getExperience(); ++ this.finalizeSpawnChildFromBreeding(level, mate, entityageable, experience); ++ level.addFreshEntityWithPassengers(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); ++ // CraftBukkit end + } + } + + public void finalizeSpawnChildFromBreeding(ServerLevel level, Animal animal, @Nullable AgeableMob baby) { +- Optional.ofNullable(this.getLoveCause()).or(() -> Optional.ofNullable(animal.getLoveCause())).ifPresent(player -> { +- player.awardStat(Stats.ANIMALS_BRED); +- CriteriaTriggers.BRED_ANIMALS.trigger(player, this, animal, baby); ++ // CraftBukkit start ++ this.finalizeSpawnChildFromBreeding(level, animal, baby, this.getRandom().nextInt(7) + 1); ++ } ++ ++ public void finalizeSpawnChildFromBreeding(ServerLevel worldserver, Animal entityanimal, @Nullable AgeableMob entityageable, int experience) { ++ // CraftBukkit end ++ Optional.ofNullable(this.getLoveCause()).or(() -> { ++ return Optional.ofNullable(entityanimal.getLoveCause()); ++ }).ifPresent((entityplayer) -> { ++ entityplayer.awardStat(Stats.ANIMALS_BRED); ++ CriteriaTriggers.BRED_ANIMALS.trigger(entityplayer, this, entityanimal, entityageable); + }); + this.setAge(6000); +- animal.setAge(6000); ++ entityanimal.setAge(6000); + this.resetLove(); +- animal.resetLove(); +- level.broadcastEntityEvent(this, (byte)18); +- if (level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { +- level.addFreshEntity(new ExperienceOrb(level, this.getX(), this.getY(), this.getZ(), this.getRandom().nextInt(7) + 1)); ++ entityanimal.resetLove(); ++ worldserver.broadcastEntityEvent(this, (byte) 18); ++ if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { ++ // CraftBukkit start - use event experience ++ if (experience > 0) { ++ worldserver.addFreshEntity(new ExperienceOrb(worldserver, this.getX(), this.getY(), this.getZ(), experience)); ++ } ++ // CraftBukkit end + } ++ + } + + @Override + public void handleEntityEvent(byte id) { + if (id == 18) { +- for (int i = 0; i < 7; i++) { +- double d = this.random.nextGaussian() * 0.02; +- double d1 = this.random.nextGaussian() * 0.02; +- double d2 = this.random.nextGaussian() * 0.02; +- this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0), this.getRandomY() + 0.5, this.getRandomZ(1.0), d, d1, d2); ++ for (int i = 0; i < 7; ++i) { ++ double d0 = this.random.nextGaussian() * 0.02D; ++ double d1 = this.random.nextGaussian() * 0.02D; ++ double d2 = this.random.nextGaussian() * 0.02D; ++ ++ this.level().addParticle(ParticleTypes.HEART, this.getRandomX(1.0D), this.getRandomY() + 0.5D, this.getRandomZ(1.0D), d0, d1, d2); + } + } else { + super.handleEntityEvent(id); + } ++ + } + } |