Skip to content

Commit

Permalink
Rebalanced some swimming styles
Browse files Browse the repository at this point in the history
  • Loading branch information
N1nn1 committed May 6, 2024
1 parent 9848831 commit c1182f9
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.ninni.spawn.client.model.SeahorseModel;
import com.ninni.spawn.client.renderer.entity.feature.SeahorsePatternLayer;
import com.ninni.spawn.entity.common.DeepLurker;
import com.ninni.spawn.registry.SpawnEntityModelLayers;
import com.ninni.spawn.entity.Seahorse;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.ColorableHierarchicalModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.layers.TropicalFishPatternLayer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.TropicalFish;

import static com.ninni.spawn.Spawn.MOD_ID;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ninni/spawn/entity/AnglerFish.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import com.ninni.spawn.registry.SpawnTags;
import com.ninni.spawn.entity.common.DeepLurker;
import com.ninni.spawn.entity.common.PathFindingFavors;
import com.ninni.spawn.entity.common.FlopConditionable;
import com.ninni.spawn.registry.SpawnCriteriaTriggers;
import com.ninni.spawn.registry.SpawnItems;
Expand Down Expand Up @@ -35,7 +35,7 @@
import net.minecraft.world.level.LevelReader;
import org.jetbrains.annotations.Nullable;

public class AnglerFish extends AbstractFish implements Bucketable, DeepLurker, FlopConditionable {
public class AnglerFish extends AbstractFish implements Bucketable, PathFindingFavors, FlopConditionable {
public static final Ingredient TEMPT_INGREDIENT = Ingredient.of(SpawnTags.ANGLER_FISH_TEMPTS);
public static final String LAST_EFFECT_GIVEN_KEY = "LastEffectGiven";

Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean doesFlopWhileOutOfWater() {

@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
return this.getLurkingPathfindingFavor(blockPos, levelReader);
return this.getDepthPathfindingFavor(blockPos, levelReader);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ninni/spawn/entity/KrillSwarm.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ninni.spawn.entity;

import com.ninni.spawn.entity.common.DeepLurker;
import com.ninni.spawn.entity.common.PathFindingFavors;
import com.ninni.spawn.entity.common.FlopConditionable;
import com.ninni.spawn.registry.SpawnItems;
import com.ninni.spawn.registry.SpawnParticleTypes;
Expand All @@ -19,7 +19,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;

public class KrillSwarm extends AbstractSchoolingFish implements FlopConditionable, DeepLurker {
public class KrillSwarm extends AbstractSchoolingFish implements FlopConditionable, PathFindingFavors {

public KrillSwarm(EntityType<? extends AbstractSchoolingFish> entityType, Level level) {
super(entityType, level);
Expand Down Expand Up @@ -72,7 +72,7 @@ protected void doPush(Entity entity) {

@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
return this.getLurkingPathfindingFavor(blockPos, levelReader);
return this.getDepthPathfindingFavor(blockPos, levelReader);
}

@Override
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/ninni/spawn/entity/SeaCow.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.ninni.spawn.registry.SpawnTags;
import com.ninni.spawn.entity.ai.goal.EatSeagrassGoal;
import com.ninni.spawn.entity.common.DeepLurker;
import com.ninni.spawn.entity.common.PathFindingFavors;
import com.ninni.spawn.registry.SpawnBlocks;
import com.ninni.spawn.registry.SpawnParticleTypes;
import com.ninni.spawn.registry.SpawnSoundEvents;
Expand Down Expand Up @@ -56,7 +56,7 @@

import static com.ninni.spawn.Spawn.MOD_ID;

public class SeaCow extends WaterAnimal implements Shearable, DeepLurker {
public class SeaCow extends WaterAnimal implements Shearable, PathFindingFavors {
public static final ResourceLocation LOOT_COMMON = new ResourceLocation(MOD_ID, "archaeology/sea_cow_common");
public static final ResourceLocation LOOT_RARE = new ResourceLocation(MOD_ID, "archaeology/sea_cow_rare");
private static final EntityDataAccessor<Integer> ALGAE = SynchedEntityData.defineId(SeaCow.class, EntityDataSerializers.INT);
Expand Down Expand Up @@ -231,6 +231,12 @@ public void shear(SoundSource soundSource) {
this.setAlgaeAmount(0);
}

@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
if (this.getFullness() >= this.maxFullness / 2) return this.getDepthPathfindingFavor(blockPos, levelReader);
return super.getWalkTargetValue(blockPos, levelReader);
}


@Override
protected void defineSynchedData() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ninni/spawn/entity/Seahorse.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ninni.spawn.entity;

import com.mojang.serialization.Codec;
import com.ninni.spawn.entity.common.DeepLurker;
import com.ninni.spawn.entity.common.PathFindingFavors;
import com.ninni.spawn.registry.SpawnItems;
import com.ninni.spawn.registry.SpawnSoundEvents;
import net.minecraft.Util;
Expand Down Expand Up @@ -35,7 +35,7 @@

import java.util.function.IntFunction;

public class Seahorse extends AbstractFish implements VariantHolder<Seahorse.Pattern>, DeepLurker {
public class Seahorse extends AbstractFish implements VariantHolder<Seahorse.Pattern>, PathFindingFavors {
private static final EntityDataAccessor<Integer> DATA_ID_TYPE_VARIANT = SynchedEntityData.defineId(Seahorse.class, EntityDataSerializers.INT);

public Seahorse(EntityType<? extends Seahorse> type, Level world) {
Expand Down Expand Up @@ -74,7 +74,7 @@ protected void registerGoals() {

@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
return this.getLurkingPathfindingFavor(blockPos, levelReader);
return this.getDepthPathfindingFavor(blockPos, levelReader);
}

public static AttributeSupplier.Builder createAttributes() {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/ninni/spawn/entity/Sunfish.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ninni.spawn.entity;

import com.ninni.spawn.entity.common.DeepLurker;
import com.ninni.spawn.entity.common.PathFindingFavors;
import com.ninni.spawn.registry.*;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -50,7 +50,7 @@
import java.util.function.IntFunction;


public class Sunfish extends PathfinderMob implements Bucketable, VariantHolder<Sunfish.Variant>, DeepLurker {
public class Sunfish extends PathfinderMob implements Bucketable, VariantHolder<Sunfish.Variant>, PathFindingFavors {
private static final EntityDataAccessor<Integer> AGE = SynchedEntityData.defineId(Sunfish.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Boolean> FROM_BUCKET = SynchedEntityData.defineId(Sunfish.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> VARIANT = SynchedEntityData.defineId(Sunfish.class, EntityDataSerializers.INT);
Expand Down Expand Up @@ -83,12 +83,6 @@ public static AttributeSupplier.Builder createAttributes() {
return Mob.createMobAttributes().add(Attributes.MAX_HEALTH, 6.0).add(Attributes.MOVEMENT_SPEED, 0.8f);
}

@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
if (this.level().isDay()) return this.getLurkingPathfindingFavor(blockPos, levelReader);
return super.getWalkTargetValue(blockPos, levelReader);
}

@Nullable
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance, MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData, @Nullable CompoundTag compoundTag) {
Expand Down Expand Up @@ -141,6 +135,12 @@ protected InteractionResult mobInteract(Player player, InteractionHand interacti
return super.mobInteract(player, interactionHand);
}

@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
if (this.level().isDay()) return this.getDepthPathfindingFavor(blockPos, levelReader);
return this.getSurfacePathfindingFavor(blockPos, levelReader);
}

//region Love and Breeding


Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/ninni/spawn/entity/common/DeepLurker.java

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/java/com/ninni/spawn/entity/common/PathFindingFavors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ninni.spawn.entity.common;


import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;

public interface PathFindingFavors {
default float getDepthPathfindingFavor(BlockPos pos, LevelReader world) {
int y = pos.getY() + Math.abs(world.getMinBuildHeight());
return 1f / (y == 0 ? 1 : y);
}
default float getSurfacePathfindingFavor(BlockPos pos, LevelReader world) {
int y = Math.abs(world.getMaxBuildHeight()) - pos.getY();
return 1f / (y == 0 ? 1 : y);
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/ninni/spawn/registry/SpawnPose.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

public enum SpawnPose {
NEWBORN,
BABY;
BABY,
BREACHING;

public Pose get() {
return Pose.valueOf(this.name());
Expand Down

0 comments on commit c1182f9

Please sign in to comment.