mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-08 06:26:43 +01:00
Update page contents from the server for debugging purposes
This commit is contained in:
parent
17d3d92416
commit
986c8b67d7
2 changed files with 24 additions and 2 deletions
|
@ -58,6 +58,9 @@ public class Unicopia implements ModInitializer {
|
||||||
|
|
||||||
ServerTickEvents.END_WORLD_TICK.register(w -> {
|
ServerTickEvents.END_WORLD_TICK.register(w -> {
|
||||||
((BlockDestructionManager.Source)w).getDestructionManager().tick();
|
((BlockDestructionManager.Source)w).getDestructionManager().tick();
|
||||||
|
if (SpellbookChapterLoader.DEBUG) {
|
||||||
|
SpellbookChapterLoader.INSTANCE.sendUpdate(w.getServer());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(TreeTypeLoader.INSTANCE);
|
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(TreeTypeLoader.INSTANCE);
|
||||||
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(UEnchantments.POISONED_JOKE);
|
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(UEnchantments.POISONED_JOKE);
|
||||||
|
|
|
@ -12,14 +12,16 @@ import com.minelittlepony.common.client.gui.dimension.Bounds;
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.crafting.IngredientWithSpell;
|
import com.minelittlepony.unicopia.ability.magic.spell.crafting.IngredientWithSpell;
|
||||||
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*;
|
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.*;
|
||||||
|
import com.minelittlepony.unicopia.network.Channel;
|
||||||
|
import com.minelittlepony.unicopia.network.MsgServerResources;
|
||||||
import com.minelittlepony.unicopia.util.Resources;
|
import com.minelittlepony.unicopia.util.Resources;
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
import net.minecraft.resource.JsonDataLoader;
|
import net.minecraft.resource.JsonDataLoader;
|
||||||
import net.minecraft.resource.ResourceManager;
|
import net.minecraft.resource.ResourceManager;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.*;
|
import net.minecraft.util.*;
|
||||||
import net.minecraft.util.profiler.Profiler;
|
import net.minecraft.util.profiler.Profiler;
|
||||||
|
@ -32,6 +34,7 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
||||||
|
|
||||||
public static final SpellbookChapterLoader INSTANCE = new SpellbookChapterLoader();
|
public static final SpellbookChapterLoader INSTANCE = new SpellbookChapterLoader();
|
||||||
|
|
||||||
|
private boolean dirty;
|
||||||
private Map<Identifier, Chapter> chapters = new HashMap<>();
|
private Map<Identifier, Chapter> chapters = new HashMap<>();
|
||||||
|
|
||||||
public SpellbookChapterLoader() {
|
public SpellbookChapterLoader() {
|
||||||
|
@ -47,6 +50,18 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
||||||
return chapters;
|
return chapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendUpdate(MinecraftServer server) {
|
||||||
|
if (dirty) {
|
||||||
|
dirty = false;
|
||||||
|
MsgServerResources msg = new MsgServerResources();
|
||||||
|
server.getWorlds().forEach(world -> {
|
||||||
|
world.getPlayers().forEach(player -> {
|
||||||
|
Channel.SERVER_RESOURCES_SEND.send(player, msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void apply(Map<Identifier, JsonElement> data, ResourceManager manager, Profiler profiler) {
|
protected void apply(Map<Identifier, JsonElement> data, ResourceManager manager, Profiler profiler) {
|
||||||
try {
|
try {
|
||||||
|
@ -60,7 +75,11 @@ public class SpellbookChapterLoader extends JsonDataLoader implements Identifiab
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
reload(CompletableFuture::completedFuture, manager, profiler, profiler, Util.getMainWorkerExecutor(), MinecraftClient.getInstance());
|
try {
|
||||||
|
Util.waitAndApply(executor -> reload(CompletableFuture::completedFuture, manager, profiler, profiler, Util.getMainWorkerExecutor(), executor)).get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
}
|
||||||
|
dirty = true;
|
||||||
}, EXECUTOR);
|
}, EXECUTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue