Skip to content

Commit

Permalink
Fix skylight & add Poi support
Browse files Browse the repository at this point in the history
  • Loading branch information
Moulberry committed Sep 28, 2023
1 parent 5001765 commit f6cbe97
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
Expand Down Expand Up @@ -246,8 +248,17 @@ private void applyBlockBuffer(ServerPlayer player, MinecraftServer server, Block
world.getChunkSource().blockChanged(blockPos); // todo: maybe simply resend chunk instead of this?

if (LightEngine.hasDifferentLightProperties(chunk, blockPos, old, blockState)) {
chunk.getSkyLightSources().update(chunk, x, by, z);
lightEngine.checkBlock(blockPos);
}

// Update Poi
Optional<Holder<PoiType>> newPoi = PoiTypes.forState(blockState);
Optional<Holder<PoiType>> oldPoi = PoiTypes.forState(old);
if (!Objects.equals(oldPoi, newPoi)) {
if (oldPoi.isPresent()) world.getPoiManager().remove(blockPos);
if (newPoi.isPresent()) world.getPoiManager().add(blockPos, newPoi.get());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.moulberry.axiom.event.AxiomModifyWorldEvent;
import io.netty.buffer.Unpooled;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.SectionPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
Expand All @@ -33,6 +36,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Level;

public class SetBlockPacketListener implements PluginMessageListener {
Expand Down Expand Up @@ -184,8 +189,17 @@ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player buk

level.getChunkSource().blockChanged(blockPos);
if (LightEngine.hasDifferentLightProperties(chunk, blockPos, old, blockState)) {
chunk.getSkyLightSources().update(chunk, x, by, z);
level.getChunkSource().getLightEngine().checkBlock(blockPos);
}

// Update Poi
Optional<Holder<PoiType>> newPoi = PoiTypes.forState(blockState);
Optional<Holder<PoiType>> oldPoi = PoiTypes.forState(old);
if (!Objects.equals(oldPoi, newPoi)) {
if (oldPoi.isPresent()) level.getPoiManager().remove(blockPos);
if (newPoi.isPresent()) level.getPoiManager().add(blockPos, newPoi.get());
}
}

boolean nowHasOnlyAir = section.hasOnlyAir();
Expand Down

0 comments on commit f6cbe97

Please sign in to comment.