diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java index 57df789d..910ab5a0 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java @@ -9,12 +9,14 @@ import eu.pb4.polymer.common.impl.CommonNetworkHandlerExt; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import net.fabricmc.api.ModInitializer; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.packet.s2c.common.ResourcePackSendS2CPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.Util; +import java.nio.file.Files; import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; @@ -33,6 +35,7 @@ public class AutoHost implements ModInitializer { public static void init(MinecraftServer server) { var config = CommonImpl.loadConfig("auto-host", AutoHostConfig.class); AutoHost.config = config; + AutoHost.config.enabled |= Files.exists(FabricLoader.getInstance().getGameDir().resolve("polymer/.force_autohost")); if (!config.enabled) { return; diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHostConfig.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHostConfig.java index 5c297d25..1e634afb 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHostConfig.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHostConfig.java @@ -5,7 +5,7 @@ import com.google.gson.JsonPrimitive; import com.google.gson.annotations.SerializedName; import eu.pb4.polymer.common.impl.CommonImpl; -import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; + public class AutoHostConfig { public String _c1 = "Enables Polymer's ResourcePack Auto Hosting"; diff --git a/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java b/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java index 80189a38..63f7bd5b 100644 --- a/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java +++ b/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java @@ -7,10 +7,8 @@ import eu.pb4.polymer.common.impl.compat.FloodGateUtils; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.ClientConnection; -import net.minecraft.network.packet.s2c.play.PlaySoundFromEntityS2CPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerCommonNetworkHandler; -import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -29,7 +27,7 @@ private PolymerCommonUtils(){} public static final SimpleEvent ON_RESOURCE_PACK_STATUS_CHANGE = new SimpleEvent<>(); private static Path cachedClientPath; - private final static String SAFE_CLIENT_SHA1 = "224c056f3cc6c6e1b5b90e63a0c621811f6a0681"; + private final static String SAFE_CLIENT_SHA1 = "fd19469fed4a4b4c15b2d5133985f0e3e7816a8a"; private final static String SAFE_CLIENT_URL = "https://piston-data.mojang.com/v1/objects/" + SAFE_CLIENT_SHA1 + "/client.jar"; private static Path cachedClientJarRoot; diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/block/ServerChunkManagerMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/block/ServerChunkManagerMixin.java index 698aac18..5f652738 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/block/ServerChunkManagerMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/block/ServerChunkManagerMixin.java @@ -31,54 +31,63 @@ @Mixin(ServerChunkManager.class) public abstract class ServerChunkManagerMixin { + @Unique + private final Object2LongMap polymer$lastUpdates = new Object2LongArrayMap<>(); @Shadow @Final public ThreadedAnvilChunkStorage threadedAnvilChunkStorage; - @Shadow @Final private ServerWorld world; + @Shadow + @Final + private ServerLightingProvider lightingProvider; @Shadow @Nullable public abstract WorldChunk getWorldChunk(int chunkX, int chunkZ); - @Shadow @Final private ServerLightingProvider lightingProvider; - - @Shadow public abstract ServerLightingProvider getLightingProvider(); - - @Unique - private final Object2LongMap polymer$lastUpdates = new Object2LongArrayMap<>(); + @Shadow + public abstract ServerLightingProvider getLightingProvider(); @Inject(method = "tickChunks", at = @At("TAIL")) private void polymer$sendChunkUpdates(CallbackInfo ci) { - this.world.getServer().execute(() -> { - if (this.polymer$lastUpdates.size() != 0) { - var t = this.world.getServer().getTicks(); - for (var entry : new ArrayList<>(this.polymer$lastUpdates.object2LongEntrySet())) { - var pos = entry.getKey(); - var time = entry.getLongValue(); + if (!this.polymer$lastUpdates.isEmpty()) { + var t = this.world.getServer().getTicks(); + for (var entry : new ArrayList<>(this.polymer$lastUpdates.object2LongEntrySet())) { + var pos = entry.getKey(); + var time = entry.getLongValue(); - if (t - time > PolymerImpl.LIGHT_UPDATE_TICK_DELAY) { - BitSet bitSet = new BitSet(); - int i = this.lightingProvider.getBottomY(); - int j = this.lightingProvider.getTopY(); - int y = pos.getSectionY(); - if (y >= i && y <= j) { - bitSet.set(y - i); - } + if (t - time > PolymerImpl.LIGHT_UPDATE_TICK_DELAY) { + this.polymer$lastUpdates.removeLong(pos); + + var chunk = this.getWorldChunk(pos.getX(), pos.getZ()); + if (chunk == null) { + continue; + } + BitSet bitSet = new BitSet(); + int i = this.lightingProvider.getBottomY(); + int j = this.lightingProvider.getTopY(); + int y = pos.getSectionY(); + if (y >= i && y <= j) { + bitSet.set(y - i); + } + + var section = chunk.getSection(chunk.sectionCoordToIndex(pos.getSectionY())); + if (section != null) { + ((PolymerBlockPosStorage) section).polymer$setRequireLights(false); + } + + List players = this.threadedAnvilChunkStorage.getPlayersWatchingChunk(pos.toChunkPos(), false); + if (!players.isEmpty()) { Packet packet = new LightUpdateS2CPacket(pos.toChunkPos(), this.getLightingProvider(), new BitSet(this.world.getTopSectionCoord() + 2), bitSet); - List players = this.threadedAnvilChunkStorage.getPlayersWatchingChunk(pos.toChunkPos(), false); - if (players.size() > 0) { - for (ServerPlayerEntity player : players) { - player.networkHandler.sendPacket(packet); - } + for (ServerPlayerEntity player : players) { + player.networkHandler.sendPacket(packet); } - this.polymer$lastUpdates.removeLong(pos); } } } - }); + } } @Inject(method = "onLightUpdate", at = @At("TAIL")) @@ -96,7 +105,6 @@ public abstract class ServerChunkManagerMixin { var section = sections[i]; if (section != null && !section.isEmpty() && ((PolymerBlockPosStorage) section).polymer$requireLights()) { this.polymer$lastUpdates.put(pos, this.world.getServer().getTicks()); - ((PolymerBlockPosStorage) section).polymer$setRequireLights(false); return; } }