Skip to content

Commit

Permalink
set light level to 0 for mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzinsel64 committed Feb 8, 2024
1 parent 998f193 commit f83dbd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ConfigEntities extends ConfigBase {
public static boolean enableNetherEndermen;
public static boolean enableShearableSnowGolems;
public static boolean enableBees;
public static boolean enableLightLevel0;

static final String catHostile = "hostile";
static final String catNeutral = "neutral";
Expand Down Expand Up @@ -63,6 +64,7 @@ protected void syncConfigOptions() {
enableVillagerTurnsIntoWitch = getBoolean("enableVillagerTurnsIntoWitch", catMisc, true, "Villagers turn into Witches when struck by lightning");
enableDragonRespawn = getBoolean("enableDragonRespawn", catMisc, true, "Crude implementation of respawning the dragon using four End crystals.");
enableNetherEndermen = getBoolean("enableNetherEndermen", catMisc, true, "Allow endermen to rarely spawn in the Nether");
enableLightLevel0 = getBoolean("enableLightLevel0", catMisc, false, "This config reducec the required light level for mobs to spawn to light level 0, like in Minecraft 1.18+.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,19 @@ public void onWorldLoad(WorldEvent.Load e) {
e.world.getGameRules().addGameRule("disableElytraMovementCheck", "false");
}

@SubscribeEvent
public void onEntitySpawn(LivingSpawnEvent.CheckSpawn event) {
if (ConfigEntities.enableLightLevel0 && event.entityLiving instanceof IMob) {
int x = MathHelper.floor_double(event.entityLiving.posX);
int y = MathHelper.floor_double(event.entityLiving.boundingBox.minY);
int z = MathHelper.floor_double(event.entityLiving.posZ);

if (event.entityLiving.worldObj.getBlockLightValue(x, y, z) > 0) {
event.setResult(Result.DENY);
}
}
}

static MovingObjectPosition getMovingObjectPositionFromPlayer(World worldIn, EntityPlayer playerIn, boolean useLiquids) {
float f = 1.0F;
float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * f;
Expand Down

0 comments on commit f83dbd0

Please sign in to comment.