|
| 1 | +package de.dafuqs.spectrum.mixin; |
| 2 | + |
| 3 | +import de.dafuqs.spectrum.registries.*; |
| 4 | +import net.minecraft.core.*; |
| 5 | +import net.minecraft.tags.*; |
| 6 | +import net.minecraft.util.*; |
| 7 | +import net.minecraft.world.entity.*; |
| 8 | +import net.minecraft.world.entity.ai.goal.*; |
| 9 | +import net.minecraft.world.entity.ai.util.*; |
| 10 | +import net.minecraft.world.entity.animal.*; |
| 11 | +import net.minecraft.world.entity.animal.axolotl.*; |
| 12 | +import net.minecraft.world.entity.monster.*; |
| 13 | +import net.minecraft.world.level.*; |
| 14 | +import net.minecraft.world.level.block.state.*; |
| 15 | +import net.minecraft.world.level.pathfinder.*; |
| 16 | +import net.minecraft.world.phys.*; |
| 17 | +import org.spongepowered.asm.mixin.*; |
| 18 | +import org.spongepowered.asm.mixin.injection.*; |
| 19 | +import org.spongepowered.asm.mixin.injection.callback.*; |
| 20 | + |
| 21 | +import javax.annotation.*; |
| 22 | +import java.util.*; |
| 23 | +import java.util.function.*; |
| 24 | + |
| 25 | +@Mixin(Cat.class) |
| 26 | +public abstract class CatMixin extends TamableAnimal { |
| 27 | + |
| 28 | + protected CatMixin(EntityType<? extends TamableAnimal> entityType, Level level) { |
| 29 | + super(entityType, level); |
| 30 | + } |
| 31 | + |
| 32 | + @Inject(method = "setVariant(Lnet/minecraft/core/Holder;)V", at = @At("HEAD")) |
| 33 | + public void setVariant(Holder<CatVariant> variant, CallbackInfo ci) { |
| 34 | + if(variant.equals(SpectrumCatVariants.CATUS)) { |
| 35 | + this.setPathfindingMalus(PathType.WATER_BORDER, 0.0F); |
| 36 | + |
| 37 | + goalSelector.getAvailableGoals().stream() |
| 38 | + .filter( wrappedGoal -> wrappedGoal != null && wrappedGoal.getGoal() instanceof WaterAvoidingRandomStrollGoal) |
| 39 | + .forEach(wrappedGoal -> goalSelector.removeGoal(wrappedGoal.getGoal())); |
| 40 | + goalSelector.addGoal(5, new CatusStrollGoal((Cat) (Object) this, 1.0F)); |
| 41 | + } else if(variant.equals(SpectrumCatVariants.FELIS)) { |
| 42 | + goalSelector.getAvailableGoals().stream() |
| 43 | + .filter(wrappedGoal -> wrappedGoal != null && wrappedGoal.getGoal() instanceof TemptGoal) |
| 44 | + .forEach(wrappedGoal -> goalSelector.removeGoal(wrappedGoal.getGoal())); |
| 45 | + goalSelector.addGoal(4, new TemptGoal(this, 1.75, (stack) -> stack.is(ItemTags.CAT_FOOD), false)); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private static class CatusStrollGoal extends RandomStrollGoal { |
| 50 | + |
| 51 | + private static final int HORIZONTAL_RADIUS = 10; |
| 52 | + private static final int VERTICAL_DISTANCE_SOLID = 2; |
| 53 | + |
| 54 | + private static final int HORIZONTAL_RADIUS_WATER = 7; |
| 55 | + private static final int VERTICAL_DISTANCE_WATER = 1; |
| 56 | + |
| 57 | + public CatusStrollGoal(PathfinderMob mob, double speedModifier) { |
| 58 | + super(mob, speedModifier); |
| 59 | + } |
| 60 | + |
| 61 | + @Nullable |
| 62 | + protected Vec3 getPosition() { |
| 63 | + List<BlockPos> validShore = new ArrayList<>(); |
| 64 | + |
| 65 | + for(BlockPos pos : BlockPos.betweenClosed(Mth.floor(this.mob.getX() - HORIZONTAL_RADIUS_WATER), Mth.floor(this.mob.getY() - VERTICAL_DISTANCE_WATER), Mth.floor(this.mob.getZ() - HORIZONTAL_RADIUS_WATER), Mth.floor(this.mob.getX() + HORIZONTAL_RADIUS_WATER), this.mob.getBlockY() + VERTICAL_DISTANCE_WATER, Mth.floor(this.mob.getZ() + HORIZONTAL_RADIUS_WATER))) { |
| 66 | + if (this.mob.level().getFluidState(pos).is(FluidTags.WATER)) { |
| 67 | + for(Direction direction : Direction.Plane.HORIZONTAL) { |
| 68 | + BlockPos relativePos = pos.relative(direction); |
| 69 | + BlockState relativeState = this.mob.level().getBlockState(relativePos); |
| 70 | + if(relativeState.isSolid()) { |
| 71 | + validShore.add(relativePos); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + if(!validShore.isEmpty()) { |
| 78 | + RandomSource random = this.mob.getRandom(); |
| 79 | + return Vec3.atCenterOf(validShore.get(random.nextInt(validShore.size()))); |
| 80 | + } |
| 81 | + |
| 82 | + return DefaultRandomPos.getPos(this.mob, HORIZONTAL_RADIUS, VERTICAL_DISTANCE_SOLID); |
| 83 | + } |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | +} |
0 commit comments