diff --git a/src/main/java/carpet/fakes/ServerLightingProviderInterface.java b/src/main/java/carpet/fakes/ServerLightingProviderInterface.java index 42aff898..c6858f9e 100644 --- a/src/main/java/carpet/fakes/ServerLightingProviderInterface.java +++ b/src/main/java/carpet/fakes/ServerLightingProviderInterface.java @@ -6,4 +6,5 @@ public interface ServerLightingProviderInterface { void publicUpdateChunkStatus(ChunkPos pos); void flush(); + void resetLight(ChunkPos pos); } diff --git a/src/main/java/carpet/mixins/ServerLightingProvider_scarpetMixin.java b/src/main/java/carpet/mixins/ServerLightingProvider_scarpetMixin.java new file mode 100644 index 00000000..fadf44ad --- /dev/null +++ b/src/main/java/carpet/mixins/ServerLightingProvider_scarpetMixin.java @@ -0,0 +1,49 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import carpet.fakes.ServerLightingProviderInterface; +import net.minecraft.server.world.ServerLightingProvider; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.ChunkSectionPos; +import net.minecraft.world.LightType; +import net.minecraft.world.chunk.ChunkNibbleArray; +import net.minecraft.world.chunk.ChunkProvider; +import net.minecraft.world.chunk.light.LightingProvider; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(ServerLightingProvider.class) +public abstract class ServerLightingProvider_scarpetMixin extends LightingProvider implements ServerLightingProviderInterface +{ + + @Shadow protected abstract void updateChunkStatus(ChunkPos pos); + + + @Shadow public abstract void checkBlock(BlockPos pos); + + public ServerLightingProvider_scarpetMixin(ChunkProvider chunkProvider, boolean hasBlockLight, boolean hasSkyLight) + { + super(chunkProvider, hasBlockLight, hasSkyLight); + } + + @Override + public void resetLight(ChunkPos chpos) + { + //super.setRetainData(pos, false); + //super.setLightEnabled(pos, false); + for (int x = chpos.x-1; x <= chpos.x+1; x++ ) + for (int z = chpos.z-1; z <= chpos.z+1; z++ ) + { + ChunkPos pos = new ChunkPos(x, z); + int j; + for(j = -1; j < 17; ++j) { + super.queueData(LightType.BLOCK, ChunkSectionPos.from(pos, j), new ChunkNibbleArray()); + super.queueData(LightType.SKY, ChunkSectionPos.from(pos, j), new ChunkNibbleArray()); + } + for(j = 0; j < 16; ++j) { + super.updateSectionStatus(ChunkSectionPos.from(pos, j), true); + } + } + } +} diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 711d07d6..eefc7875 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -5,6 +5,7 @@ import carpet.fakes.ChunkTicketManagerInterface; import carpet.fakes.MinecraftServerInterface; import carpet.fakes.BiomeArrayInterface; import carpet.fakes.ServerChunkManagerInterface; +import carpet.fakes.ServerLightingProviderInterface; import carpet.fakes.StatTypeInterface; import carpet.fakes.ThreadedAnvilChunkStorageInterface; import carpet.helpers.FeatureGenerator; @@ -2948,6 +2949,16 @@ public class CarpetExpression return (cc, tt) -> ret; }); + this.expr.addLazyFunction("relight", -1, (c, t, lv) -> + { + CarpetContext cc = (CarpetContext) c; + BlockArgument locator = BlockArgument.findIn(cc, lv, 0); + BlockPos pos = locator.block.getPos(); + ServerWorld world = cc.s.getWorld(); + ((ServerLightingProviderInterface)world.getChunkManager().getLightingProvider()).resetLight(new ChunkPos(pos)); //light(world.getChunk(pos), false); + return LazyValue.TRUE; + }); + this.expr.addLazyFunction("current_dimension", 0, (c, t, lv) -> { ServerCommandSource s = ((CarpetContext)c).s; Value retval = new StringValue(NBTSerializableValue.nameFromRegistryId(Registry.DIMENSION_TYPE.getId(s.getWorld().dimension.getType()))); diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index c527a733..7a8ee568 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -32,6 +32,10 @@ "ThreadedAnvilChunkStorage_scarpetChunkCreationMixin", "ChunkHolder_scarpetChunkCreationMixin", + "ServerLightingProvider_scarpetMixin", + + "ChunkTicketManager_spawnChunksMixin", + "ServerWorld_spawnChunksMixin", "ServerLightingProvider_scarpetChunkCreationMixin", "ChunkTicketManager_spawnChunksMixin",