Skip to content

Commit

Permalink
Adjusted spawning logic to use new tag. Tweaked specular PBR for crys…
Browse files Browse the repository at this point in the history
…tals.
  • Loading branch information
LtxProgrammer committed Sep 28, 2024
1 parent a7193c1 commit e6e2083
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 26 deletions.
23 changes: 21 additions & 2 deletions src/main/java/net/ltxprogrammer/changed/entity/ChangedEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.Difficulty;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -393,13 +394,31 @@ public static boolean isDarkEnoughToSpawn(ServerLevelAccessor world, BlockPos po
}
}

protected static boolean checkSpawnBlock(ServerLevelAccessor world, MobSpawnType reason, BlockPos pos) {
if (reason != MobSpawnType.NATURAL)
return true;
int index = 3;
do {
final BlockPos thisPos = pos;
BlockState state = world.getBlockState(thisPos);
pos = thisPos.below();
if (state.is(ChangedTags.Blocks.LATEX_SPAWNABLE_ON))
return true;
if (state.isAir() || !state.isCollisionShapeFullBlock(world, thisPos))
continue;
return false;
} while (index-- > 0);

return false;
}

public static <T extends ChangedEntity> boolean checkEntitySpawnRules(EntityType<T> entityType, ServerLevelAccessor world, MobSpawnType reason, BlockPos pos, Random random) {
/*if (!isDarkEnoughToSpawn(world, pos, random))
return false;*/
if (pos.getY() < world.getSeaLevel() - 10)
return false;
if (random.nextFloat() < 0.75f)
return false;
if (!checkSpawnBlock(world, reason, pos))
return false;
return Monster.checkAnyLightMonsterSpawnRules(entityType, world, reason, pos, random);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.ltxprogrammer.changed.entity.TransfurMode;
import net.ltxprogrammer.changed.util.Color3;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
Expand All @@ -23,6 +24,8 @@
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ForgeMod;
Expand All @@ -35,14 +38,27 @@ public abstract class AbstractAquaticEntity extends ChangedEntity implements Aqu
protected final WaterBoundPathNavigation waterNavigation;
protected final GroundPathNavigation groundNavigation;

private static boolean isDeepEnoughToSpawn(LevelAccessor p_32367_, BlockPos p_32368_) {
return p_32368_.getY() < p_32367_.getSeaLevel() - 5;
}

public static <T extends ChangedEntity> boolean checkEntitySpawnRules(EntityType<T> entityType, ServerLevelAccessor world, MobSpawnType reason, BlockPos pos, Random random) {
/*if (!isDarkEnoughToSpawn(world, pos, random))
return false;*/
if (!world.canSeeSkyFromBelowWater(pos))
return false;
if (random.nextFloat() < 0.75f)
if (random.nextFloat() < 0.75F)
return false;

if (!world.getFluidState(pos.below()).is(FluidTags.WATER)) {
return false;
return Monster.checkAnyLightMonsterSpawnRules(entityType, world, reason, pos, random);
} else {
Holder<Biome> holder = world.getBiome(pos);
boolean flag = world.getDifficulty() != Difficulty.PEACEFUL && (reason == MobSpawnType.SPAWNER || world.getFluidState(pos).is(FluidTags.WATER));
if (!holder.is(Biomes.RIVER) && !holder.is(Biomes.FROZEN_RIVER)) {
return random.nextInt(40) == 0 && isDeepEnoughToSpawn(world, pos) && flag;
} else {
return random.nextInt(15) == 0 && flag;
}
}
}

@Override
Expand Down Expand Up @@ -180,7 +196,7 @@ public void tick() {
aquaticEntity.updateSwimming();

LivingEntity livingentity = this.aquaticEntity.getTarget();
if (this.aquaticEntity.isInWater()) {
if (this.aquaticEntity.isEyeInFluid(FluidTags.WATER)) {
if (livingentity != null && livingentity.getY() > this.aquaticEntity.getY()) {
double dx = livingentity.getX() - this.aquaticEntity.getX();
double dz = livingentity.getZ() - this.aquaticEntity.getZ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static <T extends ChangedEntity> boolean checkEntitySpawnRules(EntityType
return false;
if (random.nextFloat() < 0.75f)
return false;
if (!checkSpawnBlock(world, reason, pos))
return false;
return Monster.checkAnyLightMonsterSpawnRules(entityType, world, reason, pos, random);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ public AbstractLatexShark(EntityType<? extends AbstractLatexShark> p_19870_, Lev
super(p_19870_, p_19871_);
}

private static boolean isDeepEnoughToSpawn(LevelAccessor p_32367_, BlockPos p_32368_) {
return p_32368_.getY() < p_32367_.getSeaLevel() - 5;
}

public static boolean checkAquaticLatexSpawnRules(EntityType<? extends ChangedEntity> p_32350_, ServerLevelAccessor p_32351_, MobSpawnType p_32352_, BlockPos p_32353_, Random p_32354_) {
if (!p_32351_.getFluidState(p_32353_.below()).is(FluidTags.WATER)) {
return false;
} else {
Holder<Biome> holder = p_32351_.getBiome(p_32353_);
boolean flag = p_32351_.getDifficulty() != Difficulty.PEACEFUL && isDarkEnoughToSpawn(p_32351_, p_32353_, p_32354_) && (p_32352_ == MobSpawnType.SPAWNER || p_32351_.getFluidState(p_32353_).is(FluidTags.WATER));
if (!holder.is(Biomes.RIVER) && !holder.is(Biomes.FROZEN_RIVER)) {
return p_32354_.nextInt(40) == 0 && isDeepEnoughToSpawn(p_32351_, p_32353_) && flag;
} else {
return p_32354_.nextInt(15) == 0 && flag;
}
}
}

@Override
public LatexType getLatexType() {
return LatexType.NEUTRAL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
Expand Down Expand Up @@ -469,7 +470,7 @@ public static void addSpawners(BiomeLoadingEvent event) { // Inject spawns into
ChangedBiomeInterface.addSpawn(spawns, ChangedMobCategories.CHANGED, GREEN_LIZARD, 10, 1, 2, 0.7, 0.15);
}

if (event.getCategory() == Biome.BiomeCategory.BEACH) {
if (event.getCategory() == Biome.BiomeCategory.BEACH && !event.getName().equals(Biomes.STONY_SHORE.getRegistryName())) {
ChangedBiomeInterface.addSpawn(spawns, ChangedMobCategories.CHANGED, LATEX_OTTER, 100, 1, 3, 0.7, 0.15);
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6e2083

Please sign in to comment.