Skip to content

Commit

Permalink
Merge pull request #421 from Pilzinsel64/feat/lightlevel0
Browse files Browse the repository at this point in the history
Backport light level change from 1.18 [ci skip]
CI skip since I want to edit the commit and I figured I'd just pull it right in first
  • Loading branch information
Roadhog360 authored Feb 11, 2024
2 parents fc9600b + 6d04eff commit 6c8d916
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 reduces 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 6c8d916

Please sign in to comment.