Change pillar height for the altar from 3 to 4, check for sky visibility on the pillars, and allow the altar to fix itself if the current placement is determined to be valid

This commit is contained in:
Sollace 2023-08-30 21:34:50 +01:00
parent 1f64e6c4a6
commit f4c68bb0c3
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 21 additions and 8 deletions

View file

@ -190,11 +190,18 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
}
if (!getWorld().isClient && age % 15 == 0) {
altar.ifPresent(altar -> {
if (altar.isEmpty()) {
altar = Altar.locateAltar(getWorld(), getBlockPos()).map(altar -> {
altar.generateDecorations(getWorld());
return altar;
});
}
altar = altar.filter(altar -> {
if (!altar.isValid(getWorld())) {
altar.tearDown(null, getWorld());
return;
return false;
}
altar.pillars().forEach(pillar -> {
@ -229,6 +236,8 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
getWorld().setBlockState(pillar, Blocks.CRYING_OBSIDIAN.getDefaultState());
}
});
return true;
});
}
}

View file

@ -123,8 +123,10 @@ public record Altar(BlockPos origin, Set<BlockPos> pillars) {
if (isObsidian(world, pos.move(pillarPos))
&& isObsidian(world, pos.move(Direction.UP))
&& isObsidian(world, pos.move(Direction.UP))) {
pillarPosCollector.accept(pos.toImmutable());
&& isObsidian(world, pos.move(Direction.UP))
&& isObsidian(world, pos.move(Direction.UP))
&& world.isSkyVisible(pos.move(Direction.UP))) {
pillarPosCollector.accept(pos.move(Direction.DOWN).toImmutable());
pos.set(x, y, z);
return true;
}
@ -155,9 +157,6 @@ public record Altar(BlockPos origin, Set<BlockPos> pillars) {
}
public void tearDown(@Nullable Entity except, World world) {
if (!(except instanceof SpellbookEntity)) {
world.getOtherEntities(except, new Box(origin).expand(3), IS_PARTICIPANT).forEach(Entity::kill);
}
pillars.forEach(pillar -> removeExisting(except, world, pillar));
}
@ -169,6 +168,11 @@ public record Altar(BlockPos origin, Set<BlockPos> pillars) {
return checkState(world, origin, Blocks.SOUL_FIRE)
&& checkState(world, origin.down(), Blocks.SOUL_SAND)
&& checkSlab(world, origin.down())
&& pillars.stream().allMatch(pillar -> isObsidian(world, pillar) && isObsidian(world, pillar.down()) && isObsidian(world, pillar.down(2)));
&& pillars.stream().allMatch(pillar ->
isObsidian(world, pillar)
&& world.isSkyVisible(pillar.up())
&& isObsidian(world, pillar.down())
&& isObsidian(world, pillar.down(2))
&& isObsidian(world, pillar.down(3)));
}
}