diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Cat.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Cat.java.patch | 744 |
1 files changed, 744 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Cat.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Cat.java.patch new file mode 100644 index 0000000000..9b89e0ff35 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/entity/animal/Cat.java.patch @@ -0,0 +1,744 @@ +--- a/net/minecraft/world/entity/animal/Cat.java ++++ b/net/minecraft/world/entity/animal/Cat.java +@@ -1,10 +1,11 @@ + package net.minecraft.world.entity.animal; + ++import java.util.Iterator; ++import java.util.List; ++import java.util.Objects; ++import java.util.function.Predicate; + import javax.annotation.Nullable; + import net.minecraft.core.BlockPos; +-import net.minecraft.core.Direction; +-import net.minecraft.core.Holder; +-import net.minecraft.core.HolderSet; + import net.minecraft.core.registries.BuiltInRegistries; + import net.minecraft.nbt.CompoundTag; + import net.minecraft.network.syncher.EntityDataAccessor; +@@ -21,19 +22,19 @@ + import net.minecraft.util.Mth; + import net.minecraft.util.RandomSource; + import net.minecraft.world.DifficultyInstance; +-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.Entity; + import net.minecraft.world.entity.EntityDimensions; ++import net.minecraft.world.entity.EntityPose; + import net.minecraft.world.entity.EntitySelector; + import net.minecraft.world.entity.EntityType; ++import net.minecraft.world.entity.EnumMobSpawn; ++import net.minecraft.world.entity.GroupDataEntity; + import net.minecraft.world.entity.LivingEntity; + import net.minecraft.world.entity.Mob; +-import net.minecraft.world.entity.MobSpawnType; +-import net.minecraft.world.entity.Pose; +-import net.minecraft.world.entity.SpawnGroupData; + import net.minecraft.world.entity.TamableAnimal; + import net.minecraft.world.entity.VariantHolder; + import net.minecraft.world.entity.ai.attributes.AttributeSupplier; +@@ -64,7 +65,7 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.level.ServerLevelAccessor; + import net.minecraft.world.level.block.BedBlock; +-import net.minecraft.world.level.block.state.BlockState; ++import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.level.storage.loot.BuiltInLootTables; + import net.minecraft.world.level.storage.loot.LootParams; + import net.minecraft.world.level.storage.loot.LootTable; +@@ -74,9 +75,10 @@ + import org.joml.Vector3f; + + public class Cat extends TamableAnimal implements VariantHolder<CatVariant> { +- public static final double TEMPT_SPEED_MOD = 0.6; +- public static final double WALK_SPEED_MOD = 0.8; +- public static final double SPRINT_SPEED_MOD = 1.33; ++ ++ public static final double TEMPT_SPEED_MOD = 0.6D; ++ public static final double WALK_SPEED_MOD = 0.8D; ++ public static final double SPRINT_SPEED_MOD = 1.33D; + private static final Ingredient TEMPT_INGREDIENT = Ingredient.of(Items.COD, Items.SALMON); + private static final EntityDataAccessor<CatVariant> DATA_VARIANT_ID = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.CAT_VARIANT); + private static final EntityDataAccessor<Boolean> IS_LYING = SynchedEntityData.defineId(Cat.class, EntityDataSerializers.BOOLEAN); +@@ -102,119 +104,114 @@ + + @Override + protected void registerGoals() { +- this.temptGoal = new Cat.CatTemptGoal(this, 0.6, TEMPT_INGREDIENT, true); ++ this.temptGoal = new Cat.CatTemptGoal(this, 0.6D, Cat.TEMPT_INGREDIENT, true); + this.goalSelector.addGoal(1, new FloatGoal(this)); +- this.goalSelector.addGoal(1, new PanicGoal(this, 1.5)); ++ this.goalSelector.addGoal(1, new PanicGoal(this, 1.5D)); + this.goalSelector.addGoal(2, new SitWhenOrderedToGoal(this)); + this.goalSelector.addGoal(3, new Cat.CatRelaxOnOwnerGoal(this)); + this.goalSelector.addGoal(4, this.temptGoal); +- this.goalSelector.addGoal(5, new CatLieOnBedGoal(this, 1.1, 8)); +- this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0, 10.0F, 5.0F, false)); +- this.goalSelector.addGoal(7, new CatSitOnBlockGoal(this, 0.8)); ++ this.goalSelector.addGoal(5, new CatLieOnBedGoal(this, 1.1D, 8)); ++ this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0D, 10.0F, 5.0F, false)); ++ this.goalSelector.addGoal(7, new CatSitOnBlockGoal(this, 0.8D)); + this.goalSelector.addGoal(8, new LeapAtTargetGoal(this, 0.3F)); + this.goalSelector.addGoal(9, new OcelotAttackGoal(this)); +- this.goalSelector.addGoal(10, new BreedGoal(this, 0.8)); +- this.goalSelector.addGoal(11, new WaterAvoidingRandomStrollGoal(this, 0.8, 1.0000001E-5F)); ++ this.goalSelector.addGoal(10, new BreedGoal(this, 0.8D)); ++ this.goalSelector.addGoal(11, new WaterAvoidingRandomStrollGoal(this, 0.8D, 1.0000001E-5F)); + this.goalSelector.addGoal(12, new LookAtPlayerGoal(this, Player.class, 10.0F)); +- this.targetSelector.addGoal(1, new NonTameRandomTargetGoal<>(this, Rabbit.class, false, null)); ++ this.targetSelector.addGoal(1, new NonTameRandomTargetGoal<>(this, Rabbit.class, false, (Predicate) null)); + this.targetSelector.addGoal(1, new NonTameRandomTargetGoal<>(this, Turtle.class, false, Turtle.BABY_ON_LAND_SELECTOR)); + } + + @Override + public CatVariant getVariant() { +- return this.entityData.get(DATA_VARIANT_ID); ++ return (CatVariant) this.entityData.get(Cat.DATA_VARIANT_ID); + } + +- @Override + public void setVariant(CatVariant variant) { +- this.entityData.set(DATA_VARIANT_ID, variant); ++ this.entityData.set(Cat.DATA_VARIANT_ID, variant); + } + + public void setLying(boolean lying) { +- this.entityData.set(IS_LYING, lying); ++ this.entityData.set(Cat.IS_LYING, lying); + } + + public boolean isLying() { +- return this.entityData.get(IS_LYING); ++ return (Boolean) this.entityData.get(Cat.IS_LYING); + } + + public void setRelaxStateOne(boolean relaxStateOne) { +- this.entityData.set(RELAX_STATE_ONE, relaxStateOne); ++ this.entityData.set(Cat.RELAX_STATE_ONE, relaxStateOne); + } + + public boolean isRelaxStateOne() { +- return this.entityData.get(RELAX_STATE_ONE); ++ return (Boolean) this.entityData.get(Cat.RELAX_STATE_ONE); + } + + public DyeColor getCollarColor() { +- return DyeColor.byId(this.entityData.get(DATA_COLLAR_COLOR)); ++ return DyeColor.byId((Integer) this.entityData.get(Cat.DATA_COLLAR_COLOR)); + } + + public void setCollarColor(DyeColor color) { +- this.entityData.set(DATA_COLLAR_COLOR, color.getId()); ++ this.entityData.set(Cat.DATA_COLLAR_COLOR, color.getId()); + } + + @Override + protected void defineSynchedData() { + super.defineSynchedData(); +- this.entityData.define(DATA_VARIANT_ID, BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.BLACK)); +- this.entityData.define(IS_LYING, false); +- this.entityData.define(RELAX_STATE_ONE, false); +- this.entityData.define(DATA_COLLAR_COLOR, DyeColor.RED.getId()); ++ this.entityData.define(Cat.DATA_VARIANT_ID, (CatVariant) BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.BLACK)); ++ this.entityData.define(Cat.IS_LYING, false); ++ this.entityData.define(Cat.RELAX_STATE_ONE, false); ++ this.entityData.define(Cat.DATA_COLLAR_COLOR, DyeColor.RED.getId()); + } + + @Override + public void addAdditionalSaveData(CompoundTag compound) { + super.addAdditionalSaveData(compound); + compound.putString("variant", BuiltInRegistries.CAT_VARIANT.getKey(this.getVariant()).toString()); +- compound.putByte("CollarColor", (byte)this.getCollarColor().getId()); ++ compound.putByte("CollarColor", (byte) this.getCollarColor().getId()); + } + + @Override + public void readAdditionalSaveData(CompoundTag compound) { + super.readAdditionalSaveData(compound); +- CatVariant catVariant = BuiltInRegistries.CAT_VARIANT.get(ResourceLocation.tryParse(compound.getString("variant"))); +- if (catVariant != null) { +- this.setVariant(catVariant); ++ CatVariant catvariant = (CatVariant) BuiltInRegistries.CAT_VARIANT.get(ResourceLocation.tryParse(compound.getString("variant"))); ++ ++ if (catvariant != null) { ++ this.setVariant(catvariant); + } + + if (compound.contains("CollarColor", 99)) { + this.setCollarColor(DyeColor.byId(compound.getInt("CollarColor"))); + } ++ + } + + @Override + public void customServerAiStep() { + if (this.getMoveControl().hasWanted()) { +- double speedModifier = this.getMoveControl().getSpeedModifier(); +- if (speedModifier == 0.6) { +- this.setPose(Pose.CROUCHING); ++ double d0 = this.getMoveControl().getSpeedModifier(); ++ ++ if (d0 == 0.6D) { ++ this.setPose(EntityPose.CROUCHING); + this.setSprinting(false); +- } else if (speedModifier == 1.33) { +- this.setPose(Pose.STANDING); ++ } else if (d0 == 1.33D) { ++ this.setPose(EntityPose.STANDING); + this.setSprinting(true); + } else { +- this.setPose(Pose.STANDING); ++ this.setPose(EntityPose.STANDING); + this.setSprinting(false); + } + } else { +- this.setPose(Pose.STANDING); ++ this.setPose(EntityPose.STANDING); + this.setSprinting(false); + } ++ + } + + @Nullable + @Override + protected SoundEvent getAmbientSound() { +- if (this.isTame()) { +- if (this.isInLove()) { +- return SoundEvents.CAT_PURR; +- } else { +- return this.random.nextInt(4) == 0 ? SoundEvents.CAT_PURREOW : SoundEvents.CAT_AMBIENT; +- } +- } else { +- return SoundEvents.CAT_STRAY_AMBIENT; +- } ++ return this.isTame() ? (this.isInLove() ? SoundEvents.CAT_PURR : (this.random.nextInt(4) == 0 ? SoundEvents.CAT_PURREOW : SoundEvents.CAT_AMBIENT)) : SoundEvents.CAT_STRAY_AMBIENT; + } + + @Override +@@ -237,11 +234,11 @@ + } + + public static AttributeSupplier.Builder createAttributes() { +- return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 10.0).add(Attributes.MOVEMENT_SPEED, 0.3F).add(Attributes.ATTACK_DAMAGE, 3.0); ++ return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 10.0D).add(Attributes.MOVEMENT_SPEED, 0.30000001192092896D).add(Attributes.ATTACK_DAMAGE, 3.0D); + } + + @Override +- protected void usePlayerItem(Player player, InteractionHand hand, ItemStack stack) { ++ protected void usePlayerItem(Player player, EnumHand hand, ItemStack stack) { + if (this.isFood(stack)) { + this.playSound(SoundEvents.CAT_EAT, 1.0F, 1.0F); + } +@@ -250,7 +247,7 @@ + } + + private float getAttackDamage() { +- return (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE); ++ return (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE); + } + + @Override +@@ -287,6 +284,7 @@ + this.lieDownAmount = Math.max(0.0F, this.lieDownAmount - 0.22F); + this.lieDownAmountTail = Math.max(0.0F, this.lieDownAmountTail - 0.13F); + } ++ + } + + private void updateRelaxStateOneAmount() { +@@ -296,6 +294,7 @@ + } else { + this.relaxStateOneAmount = Math.max(0.0F, this.relaxStateOneAmount - 0.13F); + } ++ + } + + public float getLieDownAmount(float partialTicks) { +@@ -313,125 +312,135 @@ + @Nullable + @Override + public Cat getBreedOffspring(ServerLevel level, AgeableMob otherParent) { +- Cat cat = EntityType.CAT.create(level); +- if (cat != null && otherParent instanceof Cat cat1) { ++ Cat entitycat = (Cat) EntityType.CAT.create(level); ++ ++ if (entitycat != null && otherParent instanceof Cat) { ++ Cat entitycat1 = (Cat) otherParent; ++ + if (this.random.nextBoolean()) { +- cat.setVariant(this.getVariant()); ++ entitycat.setVariant(this.getVariant()); + } else { +- cat.setVariant(cat1.getVariant()); ++ entitycat.setVariant(entitycat1.getVariant()); + } + + if (this.isTame()) { +- cat.setOwnerUUID(this.getOwnerUUID()); +- cat.setTame(true); ++ entitycat.setOwnerUUID(this.getOwnerUUID()); ++ entitycat.setTame(true); + if (this.random.nextBoolean()) { +- cat.setCollarColor(this.getCollarColor()); ++ entitycat.setCollarColor(this.getCollarColor()); + } else { +- cat.setCollarColor(cat1.getCollarColor()); ++ entitycat.setCollarColor(entitycat1.getCollarColor()); + } + } + } + +- return cat; ++ return entitycat; + } + + @Override + public boolean canMate(Animal otherAnimal) { +- return this.isTame() && otherAnimal instanceof Cat cat && cat.isTame() && super.canMate(otherAnimal); ++ if (!this.isTame()) { ++ return false; ++ } else if (!(otherAnimal instanceof Cat)) { ++ return false; ++ } else { ++ Cat entitycat = (Cat) otherAnimal; ++ ++ return entitycat.isTame() && super.canMate(otherAnimal); ++ } + } + + @Nullable + @Override +- public SpawnGroupData finalizeSpawn( +- ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType reason, @Nullable SpawnGroupData spawnData, @Nullable CompoundTag dataTag +- ) { +- SpawnGroupData var9 = super.finalizeSpawn(level, difficulty, reason, spawnData, dataTag); ++ public GroupDataEntity finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, EnumMobSpawn reason, @Nullable GroupDataEntity spawnData, @Nullable CompoundTag dataTag) { ++ spawnData = super.finalizeSpawn(level, difficulty, reason, spawnData, dataTag); + boolean flag = level.getMoonBrightness() > 0.9F; +- TagKey<CatVariant> tagKey = flag ? CatVariantTags.FULL_MOON_SPAWNS : CatVariantTags.DEFAULT_SPAWNS; +- BuiltInRegistries.CAT_VARIANT +- .getTag(tagKey) +- .flatMap(named -> named.getRandomElement(level.getRandom())) +- .ifPresent(holder -> this.setVariant(holder.value())); +- ServerLevel level1 = level.getLevel(); +- if (level1.structureManager().getStructureWithPieceAt(this.blockPosition(), StructureTags.CATS_SPAWN_AS_BLACK).isValid()) { +- this.setVariant(BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.ALL_BLACK)); ++ TagKey<CatVariant> tagkey = flag ? CatVariantTags.FULL_MOON_SPAWNS : CatVariantTags.DEFAULT_SPAWNS; ++ ++ BuiltInRegistries.CAT_VARIANT.getTag(tagkey).flatMap((holderset_named) -> { ++ return holderset_named.getRandomElement(level.getRandom()); ++ }).ifPresent((holder) -> { ++ this.setVariant((CatVariant) holder.value()); ++ }); ++ ServerLevel worldserver = level.getLevel(); ++ ++ if (worldserver.structureManager().getStructureWithPieceAt(this.blockPosition(), StructureTags.CATS_SPAWN_AS_BLACK).isValid()) { ++ this.setVariant((CatVariant) BuiltInRegistries.CAT_VARIANT.getOrThrow(CatVariant.ALL_BLACK)); + this.setPersistenceRequired(); + } + +- return var9; ++ return spawnData; + } + + @Override +- public InteractionResult mobInteract(Player player, InteractionHand hand) { +- ItemStack itemInHand = player.getItemInHand(hand); +- Item item = itemInHand.getItem(); ++ public InteractionResult mobInteract(Player player, EnumHand hand) { ++ ItemStack itemstack = player.getItemInHand(hand); ++ Item item = itemstack.getItem(); ++ + if (this.level().isClientSide) { +- if (this.isTame() && this.isOwnedBy(player)) { +- return InteractionResult.SUCCESS; +- } else { +- return !this.isFood(itemInHand) || !(this.getHealth() < this.getMaxHealth()) && this.isTame() +- ? InteractionResult.PASS +- : InteractionResult.SUCCESS; +- } ++ return this.isTame() && this.isOwnedBy(player) ? InteractionResult.SUCCESS : (this.isFood(itemstack) && (this.getHealth() < this.getMaxHealth() || !this.isTame()) ? InteractionResult.SUCCESS : InteractionResult.PASS); + } else { ++ InteractionResult enuminteractionresult; ++ + if (this.isTame()) { + if (this.isOwnedBy(player)) { + if (!(item instanceof DyeItem)) { +- if (item.isEdible() && this.isFood(itemInHand) && this.getHealth() < this.getMaxHealth()) { +- this.usePlayerItem(player, hand, itemInHand); +- this.heal((float)item.getFoodProperties().getNutrition()); ++ if (item.isEdible() && this.isFood(itemstack) && this.getHealth() < this.getMaxHealth()) { ++ this.usePlayerItem(player, hand, itemstack); ++ this.heal((float) item.getFoodProperties().getNutrition()); + return InteractionResult.CONSUME; + } + +- InteractionResult interactionResult = super.mobInteract(player, hand); +- if (!interactionResult.consumesAction() || this.isBaby()) { ++ enuminteractionresult = super.mobInteract(player, hand); ++ if (!enuminteractionresult.consumesAction() || this.isBaby()) { + this.setOrderedToSit(!this.isOrderedToSit()); + } + +- return interactionResult; ++ return enuminteractionresult; + } + +- DyeColor dyeColor = ((DyeItem)item).getDyeColor(); +- if (dyeColor != this.getCollarColor()) { +- this.setCollarColor(dyeColor); ++ DyeColor enumcolor = ((DyeItem) item).getDyeColor(); ++ ++ if (enumcolor != this.getCollarColor()) { ++ this.setCollarColor(enumcolor); + if (!player.getAbilities().instabuild) { +- itemInHand.shrink(1); ++ itemstack.shrink(1); + } + + this.setPersistenceRequired(); + return InteractionResult.CONSUME; + } + } +- } else if (this.isFood(itemInHand)) { +- this.usePlayerItem(player, hand, itemInHand); +- if (this.random.nextInt(3) == 0) { ++ } else if (this.isFood(itemstack)) { ++ this.usePlayerItem(player, hand, itemstack); ++ if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, player).isCancelled()) { // CraftBukkit + this.tame(player); + this.setOrderedToSit(true); +- this.level().broadcastEntityEvent(this, (byte)7); ++ this.level().broadcastEntityEvent(this, (byte) 7); + } else { +- this.level().broadcastEntityEvent(this, (byte)6); ++ this.level().broadcastEntityEvent(this, (byte) 6); + } + + this.setPersistenceRequired(); + return InteractionResult.CONSUME; + } + +- InteractionResult interactionResult = super.mobInteract(player, hand); +- if (interactionResult.consumesAction()) { ++ enuminteractionresult = super.mobInteract(player, hand); ++ if (enuminteractionresult.consumesAction()) { + this.setPersistenceRequired(); + } + +- return interactionResult; ++ return enuminteractionresult; + } + } + + @Override + public boolean isFood(ItemStack stack) { +- return TEMPT_INGREDIENT.test(stack); ++ return Cat.TEMPT_INGREDIENT.test(stack); + } + + @Override +- protected float getStandingEyeHeight(Pose pose, EntityDimensions size) { ++ protected float getStandingEyeHeight(EntityPose pose, EntityDimensions size) { + return size.height * 0.5F; + } + +@@ -443,13 +452,14 @@ + @Override + protected void reassessTameGoals() { + if (this.avoidPlayersGoal == null) { +- this.avoidPlayersGoal = new Cat.CatAvoidEntityGoal<>(this, Player.class, 16.0F, 0.8, 1.33); ++ this.avoidPlayersGoal = new Cat.CatAvoidEntityGoal<>(this, Player.class, 16.0F, 0.8D, 1.33D); + } + + this.goalSelector.removeGoal(this.avoidPlayersGoal); + if (!this.isTame()) { + this.goalSelector.addGoal(4, this.avoidPlayersGoal); + } ++ + } + + @Override +@@ -458,30 +468,45 @@ + } + + @Override +- protected Vector3f getPassengerAttachmentPoint(Entity entity, EntityDimensions entityDimensions, float f) { +- return new Vector3f(0.0F, entityDimensions.height - 0.1875F * f, 0.0F); ++ protected Vector3f getPassengerAttachmentPoint(Entity entity, EntityDimensions entitysize, float f) { ++ return new Vector3f(0.0F, entitysize.height - 0.1875F * f, 0.0F); + } + +- static class CatAvoidEntityGoal<T extends LivingEntity> extends AvoidEntityGoal<T> { ++ private static class CatTemptGoal extends TemptGoal { ++ ++ @Nullable ++ private LivingEntity selectedPlayer; // CraftBukkit + private final Cat cat; + +- public CatAvoidEntityGoal(Cat cat, Class<T> entityClassToAvoid, float maxDist, double walkSpeedModifier, double sprintSpeedModifier) { +- super(cat, entityClassToAvoid, maxDist, walkSpeedModifier, sprintSpeedModifier, EntitySelector.NO_CREATIVE_OR_SPECTATOR::test); ++ public CatTemptGoal(Cat cat, double speedModifier, Ingredient recipeitemstack, boolean items) { ++ super(cat, speedModifier, recipeitemstack, items); + this.cat = cat; + } + + @Override +- public boolean canUse() { +- return !this.cat.isTame() && super.canUse(); ++ public void tick() { ++ super.tick(); ++ if (this.selectedPlayer == null && this.mob.getRandom().nextInt(this.adjustedTickDelay(600)) == 0) { ++ this.selectedPlayer = this.player; ++ } else if (this.mob.getRandom().nextInt(this.adjustedTickDelay(500)) == 0) { ++ this.selectedPlayer = null; ++ } ++ + } + + @Override +- public boolean canContinueToUse() { +- return !this.cat.isTame() && super.canContinueToUse(); ++ protected boolean canScare() { ++ return this.selectedPlayer != null && this.selectedPlayer.equals(this.player) ? false : super.canScare(); + } ++ ++ @Override ++ public boolean canUse() { ++ return super.canUse() && !this.cat.isTame(); ++ } + } + +- static class CatRelaxOnOwnerGoal extends Goal { ++ private static class CatRelaxOnOwnerGoal extends Goal { ++ + private final Cat cat; + @Nullable + private Player ownerPlayer; +@@ -500,23 +525,27 @@ + } else if (this.cat.isOrderedToSit()) { + return false; + } else { +- LivingEntity owner = this.cat.getOwner(); +- if (owner instanceof Player) { +- this.ownerPlayer = (Player)owner; +- if (!owner.isSleeping()) { ++ LivingEntity entityliving = this.cat.getOwner(); ++ ++ if (entityliving instanceof Player) { ++ this.ownerPlayer = (Player) entityliving; ++ if (!entityliving.isSleeping()) { + return false; + } + +- if (this.cat.distanceToSqr(this.ownerPlayer) > 100.0) { ++ if (this.cat.distanceToSqr((Entity) this.ownerPlayer) > 100.0D) { + return false; + } + +- BlockPos blockPos = this.ownerPlayer.blockPosition(); +- BlockState blockState = this.cat.level().getBlockState(blockPos); +- if (blockState.is(BlockTags.BEDS)) { +- this.goalPos = blockState.getOptionalValue(BedBlock.FACING) +- .map(pos -> blockPos.relative(pos.getOpposite())) +- .orElseGet(() -> new BlockPos(blockPos)); ++ BlockPos blockposition = this.ownerPlayer.blockPosition(); ++ IBlockData iblockdata = this.cat.level().getBlockState(blockposition); ++ ++ if (iblockdata.is(BlockTags.BEDS)) { ++ this.goalPos = (BlockPos) iblockdata.getOptionalValue(BedBlock.FACING).map((enumdirection) -> { ++ return blockposition.relative(enumdirection.getOpposite()); ++ }).orElseGet(() -> { ++ return new BlockPos(blockposition); ++ }); + return !this.spaceIsOccupied(); + } + } +@@ -526,41 +555,44 @@ + } + + private boolean spaceIsOccupied() { +- for (Cat cat : this.cat.level().getEntitiesOfClass(Cat.class, new AABB(this.goalPos).inflate(2.0))) { +- if (cat != this.cat && (cat.isLying() || cat.isRelaxStateOne())) { +- return true; +- } +- } ++ List<Cat> list = this.cat.level().getEntitiesOfClass(Cat.class, (new AABB(this.goalPos)).inflate(2.0D)); ++ Iterator iterator = list.iterator(); + +- return false; ++ Cat entitycat; ++ ++ do { ++ do { ++ if (!iterator.hasNext()) { ++ return false; ++ } ++ ++ entitycat = (Cat) iterator.next(); ++ } while (entitycat == this.cat); ++ } while (!entitycat.isLying() && !entitycat.isRelaxStateOne()); ++ ++ return true; + } + + @Override + public boolean canContinueToUse() { +- return this.cat.isTame() +- && !this.cat.isOrderedToSit() +- && this.ownerPlayer != null +- && this.ownerPlayer.isSleeping() +- && this.goalPos != null +- && !this.spaceIsOccupied(); ++ return this.cat.isTame() && !this.cat.isOrderedToSit() && this.ownerPlayer != null && this.ownerPlayer.isSleeping() && this.goalPos != null && !this.spaceIsOccupied(); + } + + @Override + public void start() { + if (this.goalPos != null) { + this.cat.setInSittingPose(false); +- this.cat.getNavigation().moveTo((double)this.goalPos.getX(), (double)this.goalPos.getY(), (double)this.goalPos.getZ(), 1.1F); ++ this.cat.getNavigation().moveTo((double) this.goalPos.getX(), (double) this.goalPos.getY(), (double) this.goalPos.getZ(), 1.100000023841858D); + } ++ + } + + @Override + public void stop() { + this.cat.setLying(false); +- float timeOfDay = this.cat.level().getTimeOfDay(1.0F); +- if (this.ownerPlayer.getSleepTimer() >= 100 +- && (double)timeOfDay > 0.77 +- && (double)timeOfDay < 0.8 +- && (double)this.cat.level().getRandom().nextFloat() < 0.7) { ++ float f = this.cat.level().getTimeOfDay(1.0F); ++ ++ if (this.ownerPlayer.getSleepTimer() >= 100 && (double) f > 0.77D && (double) f < 0.8D && (double) this.cat.level().getRandom().nextFloat() < 0.7D) { + this.giveMorningGift(); + } + +@@ -570,45 +602,40 @@ + } + + private void giveMorningGift() { +- RandomSource random = this.cat.getRandom(); +- BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); +- mutableBlockPos.set(this.cat.isLeashed() ? this.cat.getLeashHolder().blockPosition() : this.cat.blockPosition()); +- this.cat +- .randomTeleport( +- (double)(mutableBlockPos.getX() + random.nextInt(11) - 5), +- (double)(mutableBlockPos.getY() + random.nextInt(5) - 2), +- (double)(mutableBlockPos.getZ() + random.nextInt(11) - 5), +- false +- ); +- mutableBlockPos.set(this.cat.blockPosition()); +- LootTable lootTable = this.cat.level().getServer().getLootData().getLootTable(BuiltInLootTables.CAT_MORNING_GIFT); +- LootParams lootParams = new LootParams.Builder((ServerLevel)this.cat.level()) +- .withParameter(LootContextParams.ORIGIN, this.cat.position()) +- .withParameter(LootContextParams.THIS_ENTITY, this.cat) +- .create(LootContextParamSets.GIFT); ++ RandomSource randomsource = this.cat.getRandom(); ++ BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos(); + +- for (ItemStack itemStack : lootTable.getRandomItems(lootParams)) { +- this.cat +- .level() +- .addFreshEntity( +- new ItemEntity( +- this.cat.level(), +- (double)mutableBlockPos.getX() - (double)Mth.sin(this.cat.yBodyRot * (float) (Math.PI / 180.0)), +- (double)mutableBlockPos.getY(), +- (double)mutableBlockPos.getZ() + (double)Mth.cos(this.cat.yBodyRot * (float) (Math.PI / 180.0)), +- itemStack +- ) +- ); ++ blockposition_mutableblockposition.set(this.cat.isLeashed() ? this.cat.getLeashHolder().blockPosition() : this.cat.blockPosition()); ++ this.cat.randomTeleport((double) (blockposition_mutableblockposition.getX() + randomsource.nextInt(11) - 5), (double) (blockposition_mutableblockposition.getY() + randomsource.nextInt(5) - 2), (double) (blockposition_mutableblockposition.getZ() + randomsource.nextInt(11) - 5), false); ++ blockposition_mutableblockposition.set(this.cat.blockPosition()); ++ LootTable loottable = this.cat.level().getServer().getLootData().getLootTable(BuiltInLootTables.CAT_MORNING_GIFT); ++ LootParams lootparams = (new LootParams.Builder((ServerLevel) this.cat.level())).withParameter(LootContextParams.ORIGIN, this.cat.position()).withParameter(LootContextParams.THIS_ENTITY, this.cat).create(LootContextParamSets.GIFT); ++ List<ItemStack> list = loottable.getRandomItems(lootparams); ++ Iterator iterator = list.iterator(); ++ ++ while (iterator.hasNext()) { ++ ItemStack itemstack = (ItemStack) iterator.next(); ++ ++ // CraftBukkit start ++ ItemEntity entityitem = new ItemEntity(this.cat.level(), (double) blockposition_mutableblockposition.getX() - (double) Mth.sin(this.cat.yBodyRot * 0.017453292F), (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + (double) Mth.cos(this.cat.yBodyRot * 0.017453292F), itemstack); ++ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.cat.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); ++ entityitem.level().getCraftServer().getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ continue; ++ } ++ this.cat.level().addFreshEntity(entityitem); ++ // CraftBukkit end + } ++ + } + + @Override + public void tick() { + if (this.ownerPlayer != null && this.goalPos != null) { + this.cat.setInSittingPose(false); +- this.cat.getNavigation().moveTo((double)this.goalPos.getX(), (double)this.goalPos.getY(), (double)this.goalPos.getZ(), 1.1F); +- if (this.cat.distanceToSqr(this.ownerPlayer) < 2.5) { +- this.onBedTicks++; ++ this.cat.getNavigation().moveTo((double) this.goalPos.getX(), (double) this.goalPos.getY(), (double) this.goalPos.getZ(), 1.100000023841858D); ++ if (this.cat.distanceToSqr((Entity) this.ownerPlayer) < 2.5D) { ++ ++this.onBedTicks; + if (this.onBedTicks > this.adjustedTickDelay(16)) { + this.cat.setLying(true); + this.cat.setRelaxStateOne(false); +@@ -620,37 +647,30 @@ + this.cat.setLying(false); + } + } ++ + } + } + +- static class CatTemptGoal extends TemptGoal { +- @Nullable +- private Player selectedPlayer; ++ private static class CatAvoidEntityGoal<T extends LivingEntity> extends AvoidEntityGoal<T> { ++ + private final Cat cat; + +- public CatTemptGoal(Cat cat, double speedModifier, Ingredient items, boolean canScare) { +- super(cat, speedModifier, items, canScare); ++ public CatAvoidEntityGoal(Cat cat, Class<T> entityClassToAvoid, float maxDist, double walkSpeedModifier, double d1) { ++ // Predicate predicate = IEntitySelector.NO_CREATIVE_OR_SPECTATOR; // CraftBukkit - decompile error ++ ++ // Objects.requireNonNull(predicate); // CraftBukkit - decompile error ++ super(cat, entityClassToAvoid, maxDist, walkSpeedModifier, d1, EntitySelector.NO_CREATIVE_OR_SPECTATOR::test); // CraftBukkit - decompile error + this.cat = cat; + } + + @Override +- public void tick() { +- super.tick(); +- if (this.selectedPlayer == null && this.mob.getRandom().nextInt(this.adjustedTickDelay(600)) == 0) { +- this.selectedPlayer = this.player; +- } else if (this.mob.getRandom().nextInt(this.adjustedTickDelay(500)) == 0) { +- this.selectedPlayer = null; +- } ++ public boolean canUse() { ++ return !this.cat.isTame() && super.canUse(); + } + + @Override +- protected boolean canScare() { +- return (this.selectedPlayer == null || !this.selectedPlayer.equals(this.player)) && super.canScare(); ++ public boolean canContinueToUse() { ++ return !this.cat.isTame() && super.canContinueToUse(); + } +- +- @Override +- public boolean canUse() { +- return super.canUse() && !this.cat.isTame(); +- } + } + } |