From 75734fa6319a4e79a92c8a788b3f31aa267772f8 Mon Sep 17 00:00:00 2001 From: Waterpicker Date: Wed, 22 Jun 2022 00:17:59 -0500 Subject: [PATCH] Stuff --- src/main/java/net/montoyo/wd/SharedProxy.java | 7 +- src/main/java/net/montoyo/wd/WebDisplays.java | 165 ++++++++++-------- .../net/montoyo/wd/client/ClientProxy.java | 3 +- .../montoyo/wd/client/gui/GuiKeyboard.java | 1 + .../net/montoyo/wd/client/gui/WDScreen.java | 93 ++++++---- .../wd/client/gui/controls/Container.java | 4 +- .../wd/client/gui/controls/Control.java | 49 +++--- .../wd/client/gui/loading/GuiLoader.java | 6 +- .../java/net/montoyo/wd/config/ModConfig.java | 120 +++++++++++++ .../net/montoyo/wd/data/KeyboardData.java | 2 +- .../montoyo/wd/entity/TileEntityScreen.java | 3 +- .../net/montoyo/wd/miniserv/PacketWriter.java | 2 +- 12 files changed, 317 insertions(+), 138 deletions(-) create mode 100644 src/main/java/net/montoyo/wd/config/ModConfig.java diff --git a/src/main/java/net/montoyo/wd/SharedProxy.java b/src/main/java/net/montoyo/wd/SharedProxy.java index a07df9f..c8a902b 100644 --- a/src/main/java/net/montoyo/wd/SharedProxy.java +++ b/src/main/java/net/montoyo/wd/SharedProxy.java @@ -8,6 +8,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; +import net.minecraftforge.server.ServerLifecycleHooks; import net.montoyo.wd.utilities.Log; import net.montoyo.wd.core.HasAdvancement; import net.montoyo.wd.core.JSServerRequest; @@ -17,6 +18,8 @@ import net.montoyo.wd.utilities.*; import javax.annotation.Nonnull; +import static net.minecraftforge.api.distmarker.Dist.CLIENT; + public class SharedProxy { public static final int CURRENT_DIMENSION = Integer.MAX_VALUE; @@ -38,7 +41,7 @@ public class SharedProxy { } public void enqueue(Runnable r) { - FMLServerHandler.instance().getServer().addScheduledTask(r); + ServerLifecycleHooks.getCurrentServer().addTickable(r); } public void displayGui(GuiData data) { @@ -86,7 +89,7 @@ public class SharedProxy { } public MinecraftServer getServer() { - return FMLServerHandler.instance().getServer(); + return ServerLifecycleHooks.getCurrentServer();CLIENT } public void setMiniservClientPort(int port) { diff --git a/src/main/java/net/montoyo/wd/WebDisplays.java b/src/main/java/net/montoyo/wd/WebDisplays.java index e2af2d7..b76c09c 100644 --- a/src/main/java/net/montoyo/wd/WebDisplays.java +++ b/src/main/java/net/montoyo/wd/WebDisplays.java @@ -5,6 +5,9 @@ package net.montoyo.wd; import com.google.gson.Gson; +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.ConfigHolder; +import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; import net.minecraft.ChatFormatting; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.CriteriaTriggers; @@ -29,13 +32,15 @@ import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.server.ServerStoppingEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.network.NetworkRegistry; -import net.montoyo.mcef.easy_forge_compat.Configuration; import net.montoyo.wd.block.BlockKeyboardRight; import net.montoyo.wd.block.BlockPeripheral; import net.montoyo.wd.block.BlockScreen; +import net.montoyo.wd.client.ClientProxy; +import net.montoyo.wd.config.ModConfig; import net.montoyo.wd.core.*; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.item.*; @@ -49,6 +54,7 @@ import java.io.*; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import java.util.List; import java.util.UUID; @Mod("webdisplays") @@ -58,7 +64,7 @@ public class WebDisplays { public static WebDisplays INSTANCE; - public static SharedProxy PROXY; + public static SharedProxy PROXY = DistExecutor.runForDist(() -> ClientProxy::new, () -> SharedProxy::new); public static SimpleNetworkWrapper NET_HANDLER; public static WDCreativeTab CREATIVE_TAB; @@ -105,7 +111,7 @@ public class WebDisplays { public boolean doHardRecipe; private boolean hasOC; private boolean hasCC; - private String[] blacklist; + private List blacklist; public boolean disableOwnershipThief; public double unloadDistance2; public double loadDistance2; @@ -121,81 +127,86 @@ public class WebDisplays { public float avDist0; public WebDisplays() { - Configuration cfg = new Configuration(); - cfg.load(); + AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new); + ConfigHolder configHolder = AutoConfig.getConfigHolder(ModConfig.class); +// Configuration cfg = new Configuration(); +// cfg.load(); +// +// //CAT: Main +// Property blacklist = cfg.get("main", "blacklist", new String[0]); +// Property padHeight = cfg.get("main", "padHeight", 480); +// Property hardRecipe = cfg.get("main", "hardRecipes", true); +// Property homePage = cfg.get("main", "homepage", "mod://webdisplays/main.html"); +// Property disableOT = cfg.get("main", "disableOwnershipThief", false); +// Property maxResX = cfg.get("main", "maxResolutionX", 1920); +// Property maxResY = cfg.get("main", "maxResolutionY", 1080); +// Property miniservPort = cfg.get("main", "miniservPort", 25566); +// Property miniservQuota = cfg.get("main", "miniservQuota", 1024); //It's stored as a string anyway +// Property maxScreenX = cfg.get("main", "maxScreenSizeX", 16); +// Property maxScreenY = cfg.get("main", "maxScreenSizeY", 16); +// +// //CAT: Client options +// Property loadDistance = cfg.get("client", "loadDistance", 30.0); +// Property unloadDistance = cfg.get("client", "unloadDistance", 32.0); +// +// //CAT: Auto volume config (client-side) +// Property enableAutoVol = cfg.get("clientAutoVolume", "enableAutoVolume", true); +// Property ytVolume = cfg.get("clientAutoVolume", "ytVolume", 100.0); +// Property dist100 = cfg.get("clientAutoVolume", "dist100", 10.0); +// Property dist0 = cfg.get("clientAutoVolume", "dist0", 30.0); +// +// +// //Comments & shit +// blacklist.setComment("An array of domain names you don't want to load."); +// padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO); +// hardRecipe.setComment("If true, breaking the minePad is required to craft upgrades."); +// homePage.setComment("The URL that will be loaded each time you create a screen"); +// disableOT.setComment("If true, the ownership thief item will be disabled"); +// loadDistance.setComment("All screens outside this range will be unloaded"); +// unloadDistance.setComment("All unloaded screens inside this range will be loaded"); +// maxResX.setComment("Maximum horizontal screen resolution, in pixels"); +// maxResY.setComment("Maximum vertical screen resolution, in pixels"); +// miniservPort.setComment("The port used by miniserv. 0 to disable."); +// miniservPort.setMaxValue(Short.MAX_VALUE); +// miniservQuota.setComment("The amount of data that can be uploaded to miniserv, in KiB (so 1024 = 1 MiO)"); +// maxScreenX.setComment("Maximum screen width, in blocks. Resolution will be clamped by maxResolutionX."); +// maxScreenY.setComment("Maximum screen height, in blocks. Resolution will be clamped by maxResolutionY."); +// enableAutoVol.setComment("If true, the volume of YouTube videos will change depending on how far you are"); +// ytVolume.setComment("Volume for YouTube videos. This will have no effect if enableSoundDistance is set to false"); +// ytVolume.setMinValue(0.0); +// ytVolume.setMaxValue(100.0); +// dist100.setComment("Distance after which the sound starts dropping (in blocks)"); +// dist100.setMinValue(0.0); +// dist0.setComment("Distance after which you can't hear anything (in blocks)"); +// dist0.setMinValue(0.0); +// +// if(unloadDistance.getDouble() < loadDistance.getDouble() + 2.0) +// unloadDistance.set(loadDistance.getDouble() + 2.0); +// +// if(dist0.getDouble() < dist100.getDouble() + 0.1) +// dist0.set(dist100.getDouble() + 0.1); +// +// cfg.save(); - //CAT: Main - Property blacklist = cfg.get("main", "blacklist", new String[0]); - Property padHeight = cfg.get("main", "padHeight", 480); - Property hardRecipe = cfg.get("main", "hardRecipes", true); - Property homePage = cfg.get("main", "homepage", "mod://webdisplays/main.html"); - Property disableOT = cfg.get("main", "disableOwnershipThief", false); - Property maxResX = cfg.get("main", "maxResolutionX", 1920); - Property maxResY = cfg.get("main", "maxResolutionY", 1080); - Property miniservPort = cfg.get("main", "miniservPort", 25566); - Property miniservQuota = cfg.get("main", "miniservQuota", 1024); //It's stored as a string anyway - Property maxScreenX = cfg.get("main", "maxScreenSizeX", 16); - Property maxScreenY = cfg.get("main", "maxScreenSizeY", 16); + ModConfig config = configHolder.getConfig(); + configHolder.save(); - //CAT: Client options - Property loadDistance = cfg.get("client", "loadDistance", 30.0); - Property unloadDistance = cfg.get("client", "unloadDistance", 32.0); - - //CAT: Auto volume config (client-side) - Property enableAutoVol = cfg.get("clientAutoVolume", "enableAutoVolume", true); - Property ytVolume = cfg.get("clientAutoVolume", "ytVolume", 100.0); - Property dist100 = cfg.get("clientAutoVolume", "dist100", 10.0); - Property dist0 = cfg.get("clientAutoVolume", "dist0", 30.0); - - - //Comments & shit - blacklist.setComment("An array of domain names you don't want to load."); - padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO); - hardRecipe.setComment("If true, breaking the minePad is required to craft upgrades."); - homePage.setComment("The URL that will be loaded each time you create a screen"); - disableOT.setComment("If true, the ownership thief item will be disabled"); - loadDistance.setComment("All screens outside this range will be unloaded"); - unloadDistance.setComment("All unloaded screens inside this range will be loaded"); - maxResX.setComment("Maximum horizontal screen resolution, in pixels"); - maxResY.setComment("Maximum vertical screen resolution, in pixels"); - miniservPort.setComment("The port used by miniserv. 0 to disable."); - miniservPort.setMaxValue(Short.MAX_VALUE); - miniservQuota.setComment("The amount of data that can be uploaded to miniserv, in KiB (so 1024 = 1 MiO)"); - maxScreenX.setComment("Maximum screen width, in blocks. Resolution will be clamped by maxResolutionX."); - maxScreenY.setComment("Maximum screen height, in blocks. Resolution will be clamped by maxResolutionY."); - enableAutoVol.setComment("If true, the volume of YouTube videos will change depending on how far you are"); - ytVolume.setComment("Volume for YouTube videos. This will have no effect if enableSoundDistance is set to false"); - ytVolume.setMinValue(0.0); - ytVolume.setMaxValue(100.0); - dist100.setComment("Distance after which the sound starts dropping (in blocks)"); - dist100.setMinValue(0.0); - dist0.setComment("Distance after which you can't hear anything (in blocks)"); - dist0.setMinValue(0.0); - - if(unloadDistance.getDouble() < loadDistance.getDouble() + 2.0) - unloadDistance.set(loadDistance.getDouble() + 2.0); - - if(dist0.getDouble() < dist100.getDouble() + 0.1) - dist0.set(dist100.getDouble() + 0.1); - - cfg.save(); - - this.blacklist = blacklist.getStringList(); - doHardRecipe = hardRecipe.getBoolean(); - this.homePage = homePage.getString(); - disableOwnershipThief = disableOT.getBoolean(); - unloadDistance2 = unloadDistance.getDouble() * unloadDistance.getDouble(); - loadDistance2 = loadDistance.getDouble() * loadDistance.getDouble(); - this.maxResX = maxResX.getInt(); - this.maxResY = maxResY.getInt(); - this.miniservPort = miniservPort.getInt(); - this.miniservQuota = miniservQuota.getLong() * 1024L; - this.maxScreenX = maxScreenX.getInt(); - this.maxScreenY = maxScreenY.getInt(); - enableSoundDistance = enableAutoVol.getBoolean(); - this.ytVolume = (float) ytVolume.getDouble(); - avDist100 = (float) dist100.getDouble(); - avDist0 = (float) dist0.getDouble(); + this.blacklist = config.main.blacklist; + doHardRecipe = config.main.hardRecipes; + this.homePage = config.main.homepage; + disableOwnershipThief = config.main.disableOwnershipThief; + unloadDistance2 = config.client.unloadDistance * config.client.unloadDistance; + loadDistance2 = config.client.loadDistance * config.client.loadDistance; + this.maxResX = config.main.maxResolutionX; + this.maxResY = config.main.maxResolutionY; + this.miniservPort = config.main.miniservPort; + this.miniservQuota = config.main.miniservQuota * 1024L; + this.maxScreenX = config.main.maxScreenSizeX; + this.maxScreenY = config.main.maxScreenSizeY; + enableSoundDistance = config.client.autoVolumeControl.enableAutoVolume; + this.ytVolume = (float) config.client.autoVolumeControl.ytVolume; + avDist100 = (float) config.client.autoVolumeControl.dist100; + avDist0 = (float) config.client.autoVolumeControl.dist0; CREATIVE_TAB = new WDCreativeTab(); @@ -207,7 +218,7 @@ public class WebDisplays { registerTrigger(criterionPadBreak, criterionUpgradeScreen, criterionLinkPeripheral, criterionKeyboardCat); //Read configuration - padResY = (double) padHeight.getInt(); + padResY = config.main.padHeight; padResX = padResY * PAD_RATIO; //Init blocks diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index a9e5645..7d6dec4 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -11,6 +11,7 @@ import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ClientAdvancementManager; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.texture.TextureMap; @@ -91,7 +92,7 @@ public class ClientProxy extends SharedProxy implements ISelectiveResourceReload private MinePadRenderer minePadRenderer; private JSQueryDispatcher jsDispatcher; private LaserPointerRenderer laserPointerRenderer; - private GuiScreen nextScreen; + private Screen nextScreen; private boolean isF1Down; //Miniserv handling diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java b/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java index e4d5739..ff89046 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiKeyboard.java @@ -4,6 +4,7 @@ package net.montoyo.wd.client.gui; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.relauncher.Side; diff --git a/src/main/java/net/montoyo/wd/client/gui/WDScreen.java b/src/main/java/net/montoyo/wd/client/gui/WDScreen.java index c3e74b3..d19dfa4 100644 --- a/src/main/java/net/montoyo/wd/client/gui/WDScreen.java +++ b/src/main/java/net/montoyo/wd/client/gui/WDScreen.java @@ -7,11 +7,17 @@ package net.montoyo.wd.client.gui; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.core.BlockPos; import net.minecraft.item.ItemStack; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.item.ItemStack; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.client.gui.controls.Container; import net.montoyo.wd.client.gui.controls.Control; @@ -39,7 +45,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -public abstract class WDScreen extends GuiScreen { +public abstract class WDScreen extends Screen { public static WDScreen CURRENT_SCREEN = null; @@ -51,7 +57,8 @@ public abstract class WDScreen extends GuiScreen { protected int syncTicks = 40; private int syncTicksLeft = -1; - public WDScreen() { + public WDScreen(Component component) { + super(component); Method[] methods = getClass().getMethods(); for(Method m : methods) { @@ -74,22 +81,22 @@ public abstract class WDScreen extends GuiScreen { } public int screen2DisplayX(int x) { - double ret = ((double) x) / ((double) width) * ((double) mc.displayWidth); + double ret = ((double) x) / ((double) width) * ((double) minecraft.getWindow().getWidth()); return (int) ret; } public int screen2DisplayY(int y) { - double ret = ((double) y) / ((double) height) * ((double) mc.displayHeight); + double ret = ((double) y) / ((double) height) * ((double) minecraft.getWindow().getHeight(); return (int) ret; } public int display2ScreenX(int x) { - double ret = ((double) x) / ((double) mc.displayWidth) * ((double) width); + double ret = ((double) x) / ((double) minecraft.getWindow().getWidth()) * ((double) width); return (int) ret; } public int display2ScreenY(int y) { - double ret = ((double) y) / ((double) mc.displayHeight) * ((double) height); + double ret = ((double) y) / ((double) minecraft.getWindow().getHeight()) * ((double) height); return (int) ret; } @@ -111,9 +118,9 @@ public abstract class WDScreen extends GuiScreen { } @Override - public void drawScreen(int mouseX, int mouseY, float ptt) { + public void render(PoseStack poseStack, int mouseX, int mouseY, float ptt) { if(defaultBackground) - drawDefaultBackground(); + renderBackground(poseStack); for(Control ctrl: controls) ctrl.draw(mouseX, mouseY, ptt); @@ -123,26 +130,38 @@ public abstract class WDScreen extends GuiScreen { } @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - if(quitOnEscape && keyCode == Keyboard.KEY_ESCAPE) { - mc.displayGuiScreen(null); - return; + public boolean charTyped(char codePoint, int modifiers) { + if(quitOnEscape && codePoint == Keyboard.KEY_ESCAPE) { + minecraft.setScreen(null); + return false; } + boolean typed = false; + for(Control ctrl: controls) - ctrl.keyTyped(typedChar, keyCode); + typed = typed || ctrl.keyTyped(codePoint, modifiers); + + return typed; } @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + public boolean mouseClicked(double mouseX, double mouseY, int button) { + boolean clicked = false; + for(Control ctrl: controls) - ctrl.mouseClicked(mouseX, mouseY, mouseButton); + clicked = clicked || ctrl.mouseClicked(mouseX, mouseY, button); + + return clicked; } @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { + public boolean mouseReleased(double mouseX, double mouseY, int button) { + boolean mouseReleased = false; + for(Control ctrl: controls) - ctrl.mouseReleased(mouseX, mouseY, state); + mouseReleased = mouseReleased || ctrl.mouseReleased(mouseX, mouseY, button); + + return mouseReleased; } @Override @@ -152,13 +171,13 @@ public abstract class WDScreen extends GuiScreen { } @Override - public void initGui() { + protected void init() { CURRENT_SCREEN = this; - Keyboard.enableRepeatEvents(true); + minecraft.keyboardHandler.setSendRepeatsToGui(true); } @Override - public void onGuiClosed() { + public void onClose() { if(syncTicksLeft >= 0) { sync(); syncTicksLeft = -1; @@ -167,10 +186,22 @@ public abstract class WDScreen extends GuiScreen { for(Control ctrl : controls) ctrl.destroy(); - Keyboard.enableRepeatEvents(false); + minecraft.keyboardHandler.setSendRepeatsToGui(false); CURRENT_SCREEN = null; } + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) { + return super.mouseDragged(mouseX, mouseY, button, dragX, dragY); + + + } + + @Override + public void mouseMoved(double mouseX, double mouseY) { + onMouseMove(mouseX, mouseY); + } + @Override public void handleMouseInput() throws IOException { super.handleMouseInput(); @@ -184,7 +215,7 @@ public abstract class WDScreen extends GuiScreen { else if(Mouse.getEventButton() == -1) onMouseMove(x, y); } - + @Override public void handleKeyboardInput() throws IOException { super.handleKeyboardInput(); @@ -207,8 +238,7 @@ public abstract class WDScreen extends GuiScreen { } public void onMouseMove(int mouseX, int mouseY) { - for(Control ctrl : controls) - ctrl.mouseMove(mouseX, mouseY); + } public Object actionPerformed(Event ev) { @@ -257,8 +287,8 @@ public abstract class WDScreen extends GuiScreen { HashMap vars = new HashMap<>(); vars.put("width", (double) width); vars.put("height", (double) height); - vars.put("displayWidth", (double) mc.displayWidth); - vars.put("displayHeight", (double) mc.displayHeight); + vars.put("displayWidth", (double) minecraft.getWindow().getWidth()); + vars.put("displayHeight", (double) minecraft.getWindow().getHeight()); addLoadCustomVariables(vars); JsonArray content = root.get("controls").getAsJsonArray(); @@ -298,12 +328,12 @@ public abstract class WDScreen extends GuiScreen { } @Override - public void onResize(@Nonnull Minecraft mcIn, int w, int h) { + public void resize(Minecraft minecraft, int width, int height) { for(Control ctrl : controls) ctrl.destroy(); controls.clear(); - super.onResize(mcIn, w, h); + super.resize(minecraft, width, height); } protected void requestAutocomplete(String beginning, boolean matchExact) { @@ -332,7 +362,7 @@ public abstract class WDScreen extends GuiScreen { } @Override - public void updateScreen() { + public void tick() { if(syncTicksLeft >= 0) { if(--syncTicksLeft < 0) sync(); @@ -340,11 +370,12 @@ public abstract class WDScreen extends GuiScreen { } public void drawItemStackTooltip(ItemStack is, int x, int y) { + renderToolTip(is, x, y); //Since it's protected... } public void drawTooltip(java.util.List lines, int x, int y) { - drawHoveringText(lines, x, y, fontRenderer); //This is also protected... + drawHoveringText(lines, x, y, font); //This is also protected... } public void requirePostDraw(Control ctrl) { @@ -353,7 +384,7 @@ public abstract class WDScreen extends GuiScreen { } @Override - public boolean doesGuiPauseGame() { + public boolean isPauseScreen() { return false; } diff --git a/src/main/java/net/montoyo/wd/client/gui/controls/Container.java b/src/main/java/net/montoyo/wd/client/gui/controls/Container.java index 2bba909..4f585c2 100644 --- a/src/main/java/net/montoyo/wd/client/gui/controls/Container.java +++ b/src/main/java/net/montoyo/wd/client/gui/controls/Container.java @@ -24,10 +24,10 @@ public abstract class Container extends BasicControl { } @Override - public void keyTyped(char typedChar, int keyCode) throws IOException { + public void keyTyped(int keyCode, int scanCode, int modifiers) throws IOException { if(!disabled) { for(Control ctrl : childs) - ctrl.keyTyped(typedChar, keyCode); + ctrl.keyTyped(keyCode, scanCode, modifiers); } } diff --git a/src/main/java/net/montoyo/wd/client/gui/controls/Control.java b/src/main/java/net/montoyo/wd/client/gui/controls/Control.java index a96a2bb..c8b4af0 100644 --- a/src/main/java/net/montoyo/wd/client/gui/controls/Control.java +++ b/src/main/java/net/montoyo/wd/client/gui/controls/Control.java @@ -4,7 +4,12 @@ package net.montoyo.wd.client.gui.controls; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexFormat; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; @@ -33,18 +38,18 @@ public abstract class Control { public static final int COLOR_YELLOW = 0xFFFFFF00; protected final Minecraft mc; - protected final FontRenderer font; - protected final Tessellator tessellator; + protected final Font font; + protected final Tesselator tessellator; protected final BufferBuilder vBuffer; protected final WDScreen parent; protected String name; protected Object userdata; public Control() { - mc = Minecraft.getMinecraft(); - font = mc.fontRenderer; - tessellator = Tessellator.getInstance(); - vBuffer = tessellator.getBuffer(); + mc = Minecraft.getInstance(); + font = mc.font; + tessellator = Tesselator.getInstance(); + vBuffer = tessellator.getBuilder(); parent = WDScreen.CURRENT_SCREEN; } @@ -56,28 +61,32 @@ public abstract class Control { this.userdata = userdata; } - public void keyTyped(char typedChar, int keyCode) throws IOException { + public boolean keyTyped(char typedChar, int keyCode) { } - public void keyUp(int key) { + public boolean keyUp(int key) { } - public void keyDown(int key) { + public boolean keyDown(int key) { } - public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { } - public void mouseReleased(int mouseX, int mouseY, int state) { + public boolean mouseReleased(double mouseX, double mouseY, int state) { + return false; } - public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + public boolean mouseClickMove(double mouseX, double mouseY, int clickedMouseButton, long timeSinceLastClick) { + return false; } - public void mouseMove(int mouseX, int mouseY) { + public boolean mouseMove(double mouseX, double mouseY) { + return false; } - public void mouseScroll(int mouseX, int mouseY, int amount) { + public boolean mouseScroll(int mouseX, int mouseY, int amount) { + return false; } public void draw(int mouseX, int mouseY, float ptt) { @@ -114,12 +123,12 @@ public abstract class Control { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - vBuffer.begin(GL_QUADS, DefaultVertexFormats.POSITION); - vBuffer.pos(x1, y2, 0.0).endVertex(); - vBuffer.pos(x2, y2, 0.0).endVertex(); - vBuffer.pos(x2, y1, 0.0).endVertex(); - vBuffer.pos(x1, y1, 0.0).endVertex(); - tessellator.draw(); + vBuffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION); + vBuffer.vertex(x1, y2, 0.0).endVertex(); + vBuffer.vertex(x2, y2, 0.0).endVertex(); + vBuffer.vertex(x2, y1, 0.0).endVertex(); + vBuffer.vertex(x1, y1, 0.0).endVertex(); + tessellator.end(); glDisable(GL_BLEND); glEnable(GL_TEXTURE_2D); diff --git a/src/main/java/net/montoyo/wd/client/gui/loading/GuiLoader.java b/src/main/java/net/montoyo/wd/client/gui/loading/GuiLoader.java index e94a9f1..5eea88d 100644 --- a/src/main/java/net/montoyo/wd/client/gui/loading/GuiLoader.java +++ b/src/main/java/net/montoyo/wd/client/gui/loading/GuiLoader.java @@ -8,6 +8,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.IResource; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.Resource; import net.minecraft.util.ResourceLocation; import net.montoyo.wd.client.gui.controls.*; import net.montoyo.wd.utilities.Log; @@ -65,10 +67,10 @@ public class GuiLoader { public static JsonObject getJson(ResourceLocation resLoc) { JsonObject ret = RESOURCES.get(resLoc); if(ret == null) { - IResource resource; + Resource resource; try { - resource = Minecraft.getMinecraft().getResourceManager().getResource(resLoc); + resource = Minecraft.getInstance().getResourceManager().getResource(resLoc); } catch(IOException e) { Log.errorEx("Couldn't load JSON UI from file", e); throw new RuntimeException(e); diff --git a/src/main/java/net/montoyo/wd/config/ModConfig.java b/src/main/java/net/montoyo/wd/config/ModConfig.java new file mode 100644 index 0000000..6d2a9d9 --- /dev/null +++ b/src/main/java/net/montoyo/wd/config/ModConfig.java @@ -0,0 +1,120 @@ +package net.montoyo.wd.config; + +import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.annotation.Config; +import me.shedaniel.autoconfig.annotation.ConfigEntry; +import net.minecraft.util.Mth; +import net.montoyo.mcef.easy_forge_compat.Configuration; + +import java.util.List; + +public class ModConfig implements ConfigData { + @ConfigEntry.Category("main") + public Main main = new Main(); + + @ConfigEntry.Category("client") + public Client client = new Client(); + + public static class Main { + @ConfigEntry.Gui.Tooltip + public List blacklist = List.of(); + + @ConfigEntry.Gui.Tooltip + public int padHeight = 480; + + @ConfigEntry.Gui.Tooltip + public boolean hardRecipes = true; + + @ConfigEntry.Gui.Tooltip + public String homepage = "mod://webdisplays/main.html"; + + @ConfigEntry.Gui.Tooltip + public boolean disableOwnershipThief = false; + + @ConfigEntry.Gui.Tooltip + public int maxResolutionX = 1920; + + @ConfigEntry.Gui.Tooltip + public int maxResolutionY = 1080; + + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = Short.MAX_VALUE) + public int miniservPort = 25566; + + @ConfigEntry.Gui.Tooltip + public long miniservQuota = 1024; //It's stored as a string anyway + + @ConfigEntry.Gui.Tooltip + public int maxScreenSizeX = 16; + + @ConfigEntry.Gui.Tooltip + public int maxScreenSizeY = 16; + } + + public static class Client { + @ConfigEntry.Gui.Tooltip + public double loadDistance = 30.0; + + @ConfigEntry.Gui.Tooltip + public double unloadDistance = 32.0; + + @ConfigEntry.Gui.CollapsibleObject() + public AutoVolumeControl autoVolumeControl = new AutoVolumeControl(); + + public static class AutoVolumeControl { + @ConfigEntry.Gui.Tooltip + public boolean enableAutoVolume = true; + + @ConfigEntry.Gui.Tooltip + public double ytVolume = 100.0; + + @ConfigEntry.Gui.Tooltip + public double dist100 = 10.0; + + @ConfigEntry.Gui.Tooltip + public double dist0 = 30.0; + } + } + + @Override + public void validatePostLoad() throws ValidationException { + ConfigData.super.validatePostLoad(); + + main.miniservPort = Mth.clamp(main.miniservPort, 0, Short.MAX_VALUE); + client.autoVolumeControl.ytVolume = Mth.clamp(client.autoVolumeControl.ytVolume, 0.0, 100.0); + client.autoVolumeControl.dist0 = Mth.clamp(client.autoVolumeControl.dist0, 0.0, Double.MAX_VALUE); + client.autoVolumeControl.ytVolume = Mth.clamp(client.autoVolumeControl.dist100, 0.0, Double.MAX_VALUE); + + if(client.unloadDistance < client.loadDistance + 2.0) { + client.unloadDistance = client.loadDistance + 2.0; + } + + if(client.autoVolumeControl.dist0 < client.autoVolumeControl.dist100 + 0.1) { + client.autoVolumeControl.dist0 = client.autoVolumeControl.dist100 + 0.1; + } + } + + // //Comments & shit +// blacklist.setComment("An array of domain names you don't want to load."); +// padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO); +// hardRecipe.setComment("If true, breaking the minePad is required to craft upgrades."); +// homePage.setComment("The URL that will be loaded each time you create a screen"); +// disableOT.setComment("If true, the ownership thief item will be disabled"); +// loadDistance.setComment("All screens outside this range will be unloaded"); +// unloadDistance.setComment("All unloaded screens inside this range will be loaded"); +// maxResX.setComment("Maximum horizontal screen resolution, in pixels"); +// maxResY.setComment("Maximum vertical screen resolution, in pixels"); +// miniservPort.setComment("The port used by miniserv. 0 to disable."); +// miniservPort.setMaxValue(Short.MAX_VALUE); +// miniservQuota.setComment("The amount of data that can be uploaded to miniserv, in KiB (so 1024 = 1 MiO)"); +// maxScreenX.setComment("Maximum screen width, in blocks. Resolution will be clamped by maxResolutionX."); +// maxScreenY.setComment("Maximum screen height, in blocks. Resolution will be clamped by maxResolutionY."); +// enableAutoVol.setComment("If true, the volume of YouTube videos will change depending on how far you are"); +// ytVolume.setComment("Volume for YouTube videos. This will have no effect if enableSoundDistance is set to false"); +// ytVolume.setMinValue(0.0); +// ytVolume.setMaxValue(100.0); +// dist100.setComment("Distance after which the sound starts dropping (in blocks)"); +// dist100.setMinValue(0.0); +// dist0.setComment("Distance after which you can't hear anything (in blocks)"); +// dist0.setMinValue(0.0); +} diff --git a/src/main/java/net/montoyo/wd/data/KeyboardData.java b/src/main/java/net/montoyo/wd/data/KeyboardData.java index 4b66f30..f4cbd79 100644 --- a/src/main/java/net/montoyo/wd/data/KeyboardData.java +++ b/src/main/java/net/montoyo/wd/data/KeyboardData.java @@ -35,7 +35,7 @@ public class KeyboardData extends GuiData { } public KeyboardData(TileEntityScreen tes, BlockSide side, BlockPos kbPos) { - pos = new Vector3i(tes.getPos()); + pos = new Vector3i(tes.getBlockPos()); this.side = side; kbX = kbPos.getX(); kbY = kbPos.getY(); diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index 1a5c40a..364c52b 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -17,6 +17,7 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.montoyo.mcef.api.IBrowser; import net.montoyo.wd.WebDisplays; @@ -39,7 +40,7 @@ import javax.annotation.Nullable; import java.util.*; import java.util.function.Consumer; -public class TileEntityScreen extends TileEntity { +public class TileEntityScreen extends BlockEntity { public static class Screen { diff --git a/src/main/java/net/montoyo/wd/miniserv/PacketWriter.java b/src/main/java/net/montoyo/wd/miniserv/PacketWriter.java index 1bf4c9a..e8e0796 100644 --- a/src/main/java/net/montoyo/wd/miniserv/PacketWriter.java +++ b/src/main/java/net/montoyo/wd/miniserv/PacketWriter.java @@ -34,7 +34,7 @@ public final class PacketWriter { private boolean writeByteArray(ByteBuffer dst, byte[] src) { int remaining = src.length - pos; - int written = (dst.remaining() >= remaining) ? remaining : dst.remaining(); + int written = Math.min(dst.remaining(), remaining); dst.put(src, pos, written); pos += written;