diff --git a/gradle.properties b/gradle.properties index 9e048bb..debddbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -81,4 +81,4 @@ usesShadowedDependencies = false # Uncomment this to disable spotless checks # This should only be uncommented to keep it easier to sync with upstream/other forks. # That is, if there is no other active fork/upstream, NEVER change this. -disableSpotless = true +disableSpotless = diff --git a/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java b/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java index 220c68e..390af4c 100644 --- a/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java +++ b/src/main/java/com/gtnewhorizons/modularui/ClientProxy.java @@ -1,6 +1,5 @@ package com.gtnewhorizons.modularui; - import codechicken.lib.math.MathHelper; import com.gtnewhorizons.modularui.common.internal.JsonLoader; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; @@ -25,7 +24,8 @@ public void preInit(FMLPreInitializationEvent event) { public void postInit() { super.postInit(); - ((SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(this::onReload); + ((SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()) + .registerReloadListener(this::onReload); } public void onReload(IResourceManager manager) { @@ -37,7 +37,7 @@ public void onReload(IResourceManager manager) { public void mouseScreenInput(GuiScreenEvent event) { if (event.gui instanceof ModularGui) { int w = Mouse.getEventDWheel(); - int wheel = (int)MathHelper.clip(w, -1, 1); + int wheel = (int) MathHelper.clip(w, -1, 1); if (wheel != 0) { ((ModularGui) event.gui).mouseScroll(wheel); } diff --git a/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java b/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java index 72a6084..fbad77b 100644 --- a/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java +++ b/src/main/java/com/gtnewhorizons/modularui/CommonProxy.java @@ -20,9 +20,9 @@ public class CommonProxy { public void preInit(FMLPreInitializationEvent event) { testBlock = new TestBlock(Material.rock) - .setBlockName("testBlock") - .setCreativeTab(CreativeTabs.tabBlock) - .setBlockTextureName("stone"); + .setBlockName("testBlock") + .setCreativeTab(CreativeTabs.tabBlock) + .setBlockTextureName("stone"); GameRegistry.registerBlock(testBlock, "testBlock"); GameRegistry.registerTileEntity(TestTile.class, "TestTileEntity"); @@ -32,20 +32,19 @@ public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); } - public void postInit() { - } - -// @SubscribeEvent -// public static void registerBlocks(RegistryEvent.Register event) { -// IForgeRegistry registry = event.getRegistry(); -// registry.register(testBlock); -// } -// -// @SubscribeEvent -// public static void registerItems(RegistryEvent.Register event) { -// IForgeRegistry registry = event.getRegistry(); -// registry.register(testItemBlock); -// } + public void postInit() {} + + // @SubscribeEvent + // public static void registerBlocks(RegistryEvent.Register event) { + // IForgeRegistry registry = event.getRegistry(); + // registry.register(testBlock); + // } + // + // @SubscribeEvent + // public static void registerItems(RegistryEvent.Register event) { + // IForgeRegistry registry = event.getRegistry(); + // registry.register(testItemBlock); + // } @SubscribeEvent public void onConfigChange(ConfigChangedEvent.OnConfigChangedEvent event) { diff --git a/src/main/java/com/gtnewhorizons/modularui/ModularUI.java b/src/main/java/com/gtnewhorizons/modularui/ModularUI.java index a696f26..3f9315f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/ModularUI.java +++ b/src/main/java/com/gtnewhorizons/modularui/ModularUI.java @@ -1,13 +1,13 @@ package com.gtnewhorizons.modularui; -import com.gtnewhorizons.modularui.common.internal.JsonLoader; -import com.gtnewhorizons.modularui.common.internal.network.NetworkHandler; -import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; -import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; import com.gtnewhorizons.modularui.api.UIInfos; import com.gtnewhorizons.modularui.api.screen.ModularUIContext; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.internal.JsonLoader; +import com.gtnewhorizons.modularui.common.internal.network.NetworkHandler; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; import com.gtnewhorizons.modularui.common.widget.WidgetJsonRegistry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; @@ -17,20 +17,18 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.util.function.Function; import net.minecraft.entity.player.EntityPlayer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.function.Function; - @Mod( - modid = ModularUI.MODID, - version = Tags.VERSION, - name = Tags.MODNAME, - acceptedMinecraftVersions = "[1.7.10]", - dependencies = ModularUI.DEPENDENCIES, - guiFactory = ModularUI.GUI_FACTORY -) + modid = ModularUI.MODID, + version = Tags.VERSION, + name = Tags.MODNAME, + acceptedMinecraftVersions = "[1.7.10]", + dependencies = ModularUI.DEPENDENCIES, + guiFactory = ModularUI.GUI_FACTORY) public class ModularUI { public static final String MODID = "modularui"; @@ -42,7 +40,10 @@ public class ModularUI { @Mod.Instance(ModularUI.MODID) public static ModularUI INSTANCE; - @SidedProxy(modId = MODID, clientSide = Tags.GROUPNAME + ".ClientProxy", serverSide = Tags.GROUPNAME + ".CommonProxy") + @SidedProxy( + modId = MODID, + clientSide = Tags.GROUPNAME + ".ClientProxy", + serverSide = Tags.GROUPNAME + ".CommonProxy") public static CommonProxy proxy; @Mod.EventHandler @@ -65,14 +66,16 @@ public void onPostInit(FMLPostInitializationEvent event) { proxy.postInit(); } - public static ModularUIContainer createContainer(EntityPlayer player, Function windowCreator) { + public static ModularUIContainer createContainer( + EntityPlayer player, Function windowCreator) { UIBuildContext buildContext = new UIBuildContext(player); ModularWindow window = windowCreator.apply(buildContext); return new ModularUIContainer(new ModularUIContext(buildContext), window); } @SideOnly(Side.CLIENT) - public static ModularGui createGuiScreen(EntityPlayer player, Function windowCreator) { + public static ModularGui createGuiScreen( + EntityPlayer player, Function windowCreator) { return new ModularGui(createContainer(player, windowCreator)); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java b/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java index 3d96de6..adb5c23 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/GlStateManager.java @@ -2,17 +2,16 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import javax.annotation.Nullable; import net.minecraft.client.renderer.OpenGlHelper; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; import org.lwjgl.util.vector.Quaternion; -import javax.annotation.Nullable; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; - /** * Copied from forge 1.12.2-14.23.5.2847 net.minecraft.client.renderer.GlStateManager */ @@ -44,156 +43,129 @@ public class GlStateManager { /** * Do not use (see MinecraftForge issue #1637) */ - public static void pushAttrib() - { + public static void pushAttrib() { GL11.glPushAttrib(8256); } /** * Do not use (see MinecraftForge issue #1637) */ - public static void popAttrib() - { + public static void popAttrib() { GL11.glPopAttrib(); } - public static void disableAlpha() - { + public static void disableAlpha() { alphaState.alphaTest.setDisabled(); } - public static void enableAlpha() - { + public static void enableAlpha() { alphaState.alphaTest.setEnabled(); } - public static void alphaFunc(int func, float ref) - { - if (func != alphaState.func || ref != alphaState.ref) - { + public static void alphaFunc(int func, float ref) { + if (func != alphaState.func || ref != alphaState.ref) { alphaState.func = func; alphaState.ref = ref; GL11.glAlphaFunc(func, ref); } } - public static void enableLighting() - { + public static void enableLighting() { lightingState.setEnabled(); } - public static void disableLighting() - { + public static void disableLighting() { lightingState.setDisabled(); } - public static void enableLight(int light) - { + public static void enableLight(int light) { lightState[light].setEnabled(); } - public static void disableLight(int light) - { + public static void disableLight(int light) { lightState[light].setDisabled(); } - public static void enableColorMaterial() - { + public static void enableColorMaterial() { colorMaterialState.colorMaterial.setEnabled(); } - public static void disableColorMaterial() - { + public static void disableColorMaterial() { colorMaterialState.colorMaterial.setDisabled(); } - public static void colorMaterial(int face, int mode) - { - if (face != colorMaterialState.face || mode != colorMaterialState.mode) - { + public static void colorMaterial(int face, int mode) { + if (face != colorMaterialState.face || mode != colorMaterialState.mode) { colorMaterialState.face = face; colorMaterialState.mode = mode; GL11.glColorMaterial(face, mode); } } - public static void glLight(int light, int pname, FloatBuffer params) - { + public static void glLight(int light, int pname, FloatBuffer params) { GL11.glLight(light, pname, params); } - public static void glLightModel(int pname, FloatBuffer params) - { + public static void glLightModel(int pname, FloatBuffer params) { GL11.glLightModel(pname, params); } - public static void glNormal3f(float nx, float ny, float nz) - { + public static void glNormal3f(float nx, float ny, float nz) { GL11.glNormal3f(nx, ny, nz); } - public static void disableDepth() - { + public static void disableDepth() { depthState.depthTest.setDisabled(); } - public static void enableDepth() - { + public static void enableDepth() { depthState.depthTest.setEnabled(); } - public static void depthFunc(int depthFunc) - { - if (depthFunc != depthState.depthFunc) - { + public static void depthFunc(int depthFunc) { + if (depthFunc != depthState.depthFunc) { depthState.depthFunc = depthFunc; GL11.glDepthFunc(depthFunc); } } - public static void depthMask(boolean flagIn) - { - if (flagIn != depthState.maskEnabled) - { + public static void depthMask(boolean flagIn) { + if (flagIn != depthState.maskEnabled) { depthState.maskEnabled = flagIn; GL11.glDepthMask(flagIn); } } - public static void disableBlend() - { + public static void disableBlend() { blendState.blend.setDisabled(); } - public static void enableBlend() - { + public static void enableBlend() { blendState.blend.setEnabled(); } - public static void blendFunc(SourceFactor srcFactor, DestFactor dstFactor) - { + public static void blendFunc(SourceFactor srcFactor, DestFactor dstFactor) { blendFunc(srcFactor.factor, dstFactor.factor); } - public static void blendFunc(int srcFactor, int dstFactor) - { - if (srcFactor != blendState.srcFactor || dstFactor != blendState.dstFactor) - { + public static void blendFunc(int srcFactor, int dstFactor) { + if (srcFactor != blendState.srcFactor || dstFactor != blendState.dstFactor) { blendState.srcFactor = srcFactor; blendState.dstFactor = dstFactor; GL11.glBlendFunc(srcFactor, dstFactor); } } - public static void tryBlendFuncSeparate(SourceFactor srcFactor, DestFactor dstFactor, SourceFactor srcFactorAlpha, DestFactor dstFactorAlpha) - { + public static void tryBlendFuncSeparate( + SourceFactor srcFactor, DestFactor dstFactor, SourceFactor srcFactorAlpha, DestFactor dstFactorAlpha) { tryBlendFuncSeparate(srcFactor.factor, dstFactor.factor, srcFactorAlpha.factor, dstFactorAlpha.factor); } - public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) - { - if (srcFactor != blendState.srcFactor || dstFactor != blendState.dstFactor || srcFactorAlpha != blendState.srcFactorAlpha || dstFactorAlpha != blendState.dstFactorAlpha) - { + public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFactorAlpha, int dstFactorAlpha) { + if (srcFactor != blendState.srcFactor + || dstFactor != blendState.dstFactor + || srcFactorAlpha != blendState.srcFactorAlpha + || dstFactorAlpha != blendState.dstFactorAlpha) { blendState.srcFactor = srcFactor; blendState.dstFactor = dstFactor; blendState.srcFactorAlpha = srcFactorAlpha; @@ -202,17 +174,15 @@ public static void tryBlendFuncSeparate(int srcFactor, int dstFactor, int srcFac } } - public static void glBlendEquation(int blendEquation) - { + public static void glBlendEquation(int blendEquation) { GL14.glBlendEquation(blendEquation); } - public static void enableOutlineMode(int color) - { - BUF_FLOAT_4.put(0, (float)(color >> 16 & 255) / 255.0F); - BUF_FLOAT_4.put(1, (float)(color >> 8 & 255) / 255.0F); - BUF_FLOAT_4.put(2, (float)(color >> 0 & 255) / 255.0F); - BUF_FLOAT_4.put(3, (float)(color >> 24 & 255) / 255.0F); + public static void enableOutlineMode(int color) { + BUF_FLOAT_4.put(0, (float) (color >> 16 & 255) / 255.0F); + BUF_FLOAT_4.put(1, (float) (color >> 8 & 255) / 255.0F); + BUF_FLOAT_4.put(2, (float) (color >> 0 & 255) / 255.0F); + BUF_FLOAT_4.put(3, (float) (color >> 24 & 255) / 255.0F); glTexEnv(8960, 8705, BUF_FLOAT_4); glTexEnvi(8960, 8704, 34160); glTexEnvi(8960, 34161, 7681); @@ -223,8 +193,7 @@ public static void enableOutlineMode(int color) glTexEnvi(8960, 34200, 770); } - public static void disableOutlineMode() - { + public static void disableOutlineMode() { glTexEnvi(8960, 8704, 8448); glTexEnvi(8960, 34161, 8448); glTexEnvi(8960, 34162, 8448); @@ -234,170 +203,135 @@ public static void disableOutlineMode() glTexEnvi(8960, 34200, 770); } - public static void enableFog() - { + public static void enableFog() { fogState.fog.setEnabled(); } - public static void disableFog() - { + public static void disableFog() { fogState.fog.setDisabled(); } - public static void setFog(FogMode fogMode) - { + public static void setFog(FogMode fogMode) { setFog(fogMode.capabilityId); } - private static void setFog(int param) - { - if (param != fogState.mode) - { + private static void setFog(int param) { + if (param != fogState.mode) { fogState.mode = param; GL11.glFogi(GL11.GL_FOG_MODE, param); } } - public static void setFogDensity(float param) - { - if (param != fogState.density) - { + public static void setFogDensity(float param) { + if (param != fogState.density) { fogState.density = param; GL11.glFogf(GL11.GL_FOG_DENSITY, param); } } - public static void setFogStart(float param) - { - if (param != fogState.start) - { + public static void setFogStart(float param) { + if (param != fogState.start) { fogState.start = param; GL11.glFogf(GL11.GL_FOG_START, param); } } - public static void setFogEnd(float param) - { - if (param != fogState.end) - { + public static void setFogEnd(float param) { + if (param != fogState.end) { fogState.end = param; GL11.glFogf(GL11.GL_FOG_END, param); } } - public static void glFog(int pname, FloatBuffer param) - { + public static void glFog(int pname, FloatBuffer param) { GL11.glFog(pname, param); } - public static void glFogi(int pname, int param) - { + public static void glFogi(int pname, int param) { GL11.glFogi(pname, param); } - public static void enableCull() - { + public static void enableCull() { cullState.cullFace.setEnabled(); } - public static void disableCull() - { + public static void disableCull() { cullState.cullFace.setDisabled(); } - public static void cullFace(CullFace cullFace) - { + public static void cullFace(CullFace cullFace) { cullFace(cullFace.mode); } - private static void cullFace(int mode) - { - if (mode != cullState.mode) - { + private static void cullFace(int mode) { + if (mode != cullState.mode) { cullState.mode = mode; GL11.glCullFace(mode); } } - public static void glPolygonMode(int face, int mode) - { + public static void glPolygonMode(int face, int mode) { GL11.glPolygonMode(face, mode); } - public static void enablePolygonOffset() - { + public static void enablePolygonOffset() { polygonOffsetState.polygonOffsetFill.setEnabled(); } - public static void disablePolygonOffset() - { + public static void disablePolygonOffset() { polygonOffsetState.polygonOffsetFill.setDisabled(); } - public static void doPolygonOffset(float factor, float units) - { - if (factor != polygonOffsetState.factor || units != polygonOffsetState.units) - { + public static void doPolygonOffset(float factor, float units) { + if (factor != polygonOffsetState.factor || units != polygonOffsetState.units) { polygonOffsetState.factor = factor; polygonOffsetState.units = units; GL11.glPolygonOffset(factor, units); } } - public static void enableColorLogic() - { + public static void enableColorLogic() { colorLogicState.colorLogicOp.setEnabled(); } - public static void disableColorLogic() - { + public static void disableColorLogic() { colorLogicState.colorLogicOp.setDisabled(); } - public static void colorLogicOp(LogicOp logicOperation) - { + public static void colorLogicOp(LogicOp logicOperation) { colorLogicOp(logicOperation.opcode); } - public static void colorLogicOp(int opcode) - { - if (opcode != colorLogicState.opcode) - { + public static void colorLogicOp(int opcode) { + if (opcode != colorLogicState.opcode) { colorLogicState.opcode = opcode; GL11.glLogicOp(opcode); } } - public static void enableTexGenCoord(TexGen texGen) - { + public static void enableTexGenCoord(TexGen texGen) { texGenCoord(texGen).textureGen.setEnabled(); } - public static void disableTexGenCoord(TexGen texGen) - { + public static void disableTexGenCoord(TexGen texGen) { texGenCoord(texGen).textureGen.setDisabled(); } - public static void texGen(TexGen texGen, int param) - { + public static void texGen(TexGen texGen, int param) { TexGenCoord glstatemanager$texgencoord = texGenCoord(texGen); - if (param != glstatemanager$texgencoord.param) - { + if (param != glstatemanager$texgencoord.param) { glstatemanager$texgencoord.param = param; GL11.glTexGeni(glstatemanager$texgencoord.coord, GL11.GL_TEXTURE_GEN_MODE, param); } } - public static void texGen(TexGen texGen, int pname, FloatBuffer params) - { + public static void texGen(TexGen texGen, int pname, FloatBuffer params) { GL11.glTexGen(texGenCoord(texGen).coord, pname, params); } - private static TexGenCoord texGenCoord(TexGen texGen) - { - switch (texGen) - { + private static TexGenCoord texGenCoord(TexGen texGen) { + switch (texGen) { case S: return texGenState.s; case T: @@ -411,140 +345,133 @@ private static TexGenCoord texGenCoord(TexGen texGen) } } - public static void setActiveTexture(int texture) - { - if (activeTextureUnit != texture - OpenGlHelper.defaultTexUnit) - { + public static void setActiveTexture(int texture) { + if (activeTextureUnit != texture - OpenGlHelper.defaultTexUnit) { activeTextureUnit = texture - OpenGlHelper.defaultTexUnit; OpenGlHelper.setActiveTexture(texture); } } - public static void enableTexture2D() - { + public static void enableTexture2D() { textureState[activeTextureUnit].texture2DState.setEnabled(); } - public static void disableTexture2D() - { + public static void disableTexture2D() { textureState[activeTextureUnit].texture2DState.setDisabled(); } - public static void glTexEnv(int target, int parameterName, FloatBuffer parameters) - { + public static void glTexEnv(int target, int parameterName, FloatBuffer parameters) { GL11.glTexEnv(target, parameterName, parameters); } - public static void glTexEnvi(int target, int parameterName, int parameter) - { + public static void glTexEnvi(int target, int parameterName, int parameter) { GL11.glTexEnvi(target, parameterName, parameter); } - public static void glTexEnvf(int target, int parameterName, float parameter) - { + public static void glTexEnvf(int target, int parameterName, float parameter) { GL11.glTexEnvf(target, parameterName, parameter); } - public static void glTexParameterf(int target, int parameterName, float parameter) - { + public static void glTexParameterf(int target, int parameterName, float parameter) { GL11.glTexParameterf(target, parameterName, parameter); } - public static void glTexParameteri(int target, int parameterName, int parameter) - { + public static void glTexParameteri(int target, int parameterName, int parameter) { GL11.glTexParameteri(target, parameterName, parameter); } - public static int glGetTexLevelParameteri(int target, int level, int parameterName) - { + public static int glGetTexLevelParameteri(int target, int level, int parameterName) { return GL11.glGetTexLevelParameteri(target, level, parameterName); } - public static int generateTexture() - { + public static int generateTexture() { return GL11.glGenTextures(); } - public static void deleteTexture(int texture) - { + public static void deleteTexture(int texture) { GL11.glDeleteTextures(texture); - for (TextureState glstatemanager$texturestate : textureState) - { - if (glstatemanager$texturestate.textureName == texture) - { + for (TextureState glstatemanager$texturestate : textureState) { + if (glstatemanager$texturestate.textureName == texture) { glstatemanager$texturestate.textureName = -1; } } } - public static void bindTexture(int texture) - { - if (texture != textureState[activeTextureUnit].textureName) - { + public static void bindTexture(int texture) { + if (texture != textureState[activeTextureUnit].textureName) { textureState[activeTextureUnit].textureName = texture; GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); } } - public static void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, @Nullable IntBuffer pixels) - { + public static void glTexImage2D( + int target, + int level, + int internalFormat, + int width, + int height, + int border, + int format, + int type, + @Nullable IntBuffer pixels) { GL11.glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels); } - public static void glTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, IntBuffer pixels) - { + public static void glTexSubImage2D( + int target, + int level, + int xOffset, + int yOffset, + int width, + int height, + int format, + int type, + IntBuffer pixels) { GL11.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, pixels); } - public static void glCopyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height) - { + public static void glCopyTexSubImage2D( + int target, int level, int xOffset, int yOffset, int x, int y, int width, int height) { GL11.glCopyTexSubImage2D(target, level, xOffset, yOffset, x, y, width, height); } - public static void glGetTexImage(int target, int level, int format, int type, IntBuffer pixels) - { + public static void glGetTexImage(int target, int level, int format, int type, IntBuffer pixels) { GL11.glGetTexImage(target, level, format, type, pixels); } - public static void enableNormalize() - { + public static void enableNormalize() { normalizeState.setEnabled(); } - public static void disableNormalize() - { + public static void disableNormalize() { normalizeState.setDisabled(); } - public static void shadeModel(int mode) - { - if (mode != activeShadeModel) - { + public static void shadeModel(int mode) { + if (mode != activeShadeModel) { activeShadeModel = mode; GL11.glShadeModel(mode); } } - public static void enableRescaleNormal() - { + public static void enableRescaleNormal() { rescaleNormalState.setEnabled(); } - public static void disableRescaleNormal() - { + public static void disableRescaleNormal() { rescaleNormalState.setDisabled(); } - public static void viewport(int x, int y, int width, int height) - { + public static void viewport(int x, int y, int width, int height) { GL11.glViewport(x, y, width, height); } - public static void colorMask(boolean red, boolean green, boolean blue, boolean alpha) - { - if (red != colorMaskState.red || green != colorMaskState.green || blue != colorMaskState.blue || alpha != colorMaskState.alpha) - { + public static void colorMask(boolean red, boolean green, boolean blue, boolean alpha) { + if (red != colorMaskState.red + || green != colorMaskState.green + || blue != colorMaskState.blue + || alpha != colorMaskState.alpha) { colorMaskState.red = red; colorMaskState.green = green; colorMaskState.blue = blue; @@ -553,19 +480,18 @@ public static void colorMask(boolean red, boolean green, boolean blue, boolean a } } - public static void clearDepth(double depth) - { - if (depth != clearState.depth) - { + public static void clearDepth(double depth) { + if (depth != clearState.depth) { clearState.depth = depth; GL11.glClearDepth(depth); } } - public static void clearColor(float red, float green, float blue, float alpha) - { - if (red != clearState.color.red || green != clearState.color.green || blue != clearState.color.blue || alpha != clearState.color.alpha) - { + public static void clearColor(float red, float green, float blue, float alpha) { + if (red != clearState.color.red + || green != clearState.color.green + || blue != clearState.color.blue + || alpha != clearState.color.alpha) { clearState.color.red = red; clearState.color.green = green; clearState.color.blue = blue; @@ -574,78 +500,63 @@ public static void clearColor(float red, float green, float blue, float alpha) } } - public static void clear(int mask) - { + public static void clear(int mask) { GL11.glClear(mask); } - public static void matrixMode(int mode) - { + public static void matrixMode(int mode) { GL11.glMatrixMode(mode); } - public static void loadIdentity() - { + public static void loadIdentity() { GL11.glLoadIdentity(); } - public static void pushMatrix() - { + public static void pushMatrix() { GL11.glPushMatrix(); } - public static void popMatrix() - { + public static void popMatrix() { GL11.glPopMatrix(); } - public static void getFloat(int pname, FloatBuffer params) - { + public static void getFloat(int pname, FloatBuffer params) { GL11.glGetFloat(pname, params); } - public static void ortho(double left, double right, double bottom, double top, double zNear, double zFar) - { + public static void ortho(double left, double right, double bottom, double top, double zNear, double zFar) { GL11.glOrtho(left, right, bottom, top, zNear, zFar); } - public static void rotate(float angle, float x, float y, float z) - { + public static void rotate(float angle, float x, float y, float z) { GL11.glRotatef(angle, x, y, z); } - public static void scale(float x, float y, float z) - { + public static void scale(float x, float y, float z) { GL11.glScalef(x, y, z); } - public static void scale(double x, double y, double z) - { + public static void scale(double x, double y, double z) { GL11.glScaled(x, y, z); } - public static void translate(float x, float y, float z) - { + public static void translate(float x, float y, float z) { GL11.glTranslatef(x, y, z); } - public static void translate(double x, double y, double z) - { + public static void translate(double x, double y, double z) { GL11.glTranslated(x, y, z); } - public static void multMatrix(FloatBuffer matrix) - { + public static void multMatrix(FloatBuffer matrix) { GL11.glMultMatrix(matrix); } - public static void rotate(Quaternion quaternionIn) - { + public static void rotate(Quaternion quaternionIn) { multMatrix(quatToGlMatrix(BUF_FLOAT_16, quaternionIn)); } - public static FloatBuffer quatToGlMatrix(FloatBuffer buffer, Quaternion quaternionIn) - { + public static FloatBuffer quatToGlMatrix(FloatBuffer buffer, Quaternion quaternionIn) { buffer.clear(); float f = quaternionIn.x * quaternionIn.x; float f1 = quaternionIn.x * quaternionIn.y; @@ -676,10 +587,11 @@ public static FloatBuffer quatToGlMatrix(FloatBuffer buffer, Quaternion quaterni return buffer; } - public static void color(float colorRed, float colorGreen, float colorBlue, float colorAlpha) - { - if (colorRed != colorState.red || colorGreen != colorState.green || colorBlue != colorState.blue || colorAlpha != colorState.alpha) - { + public static void color(float colorRed, float colorGreen, float colorBlue, float colorAlpha) { + if (colorRed != colorState.red + || colorGreen != colorState.green + || colorBlue != colorState.blue + || colorAlpha != colorState.alpha) { colorState.red = colorRed; colorState.green = colorGreen; colorState.blue = colorBlue; @@ -688,153 +600,123 @@ public static void color(float colorRed, float colorGreen, float colorBlue, floa } } - public static void color(float colorRed, float colorGreen, float colorBlue) - { + public static void color(float colorRed, float colorGreen, float colorBlue) { color(colorRed, colorGreen, colorBlue, 1.0F); } - public static void glTexCoord2f(float sCoord, float tCoord) - { + public static void glTexCoord2f(float sCoord, float tCoord) { GL11.glTexCoord2f(sCoord, tCoord); } - public static void glVertex3f(float x, float y, float z) - { + public static void glVertex3f(float x, float y, float z) { GL11.glVertex3f(x, y, z); } - public static void resetColor() - { + public static void resetColor() { colorState.red = -1.0F; colorState.green = -1.0F; colorState.blue = -1.0F; colorState.alpha = -1.0F; } - public static void glNormalPointer(int type, int stride, ByteBuffer buffer) - { + public static void glNormalPointer(int type, int stride, ByteBuffer buffer) { GL11.glNormalPointer(type, stride, buffer); } - public static void glTexCoordPointer(int size, int type, int stride, int buffer_offset) - { - GL11.glTexCoordPointer(size, type, stride, (long)buffer_offset); + public static void glTexCoordPointer(int size, int type, int stride, int buffer_offset) { + GL11.glTexCoordPointer(size, type, stride, (long) buffer_offset); } - public static void glTexCoordPointer(int size, int type, int stride, ByteBuffer buffer) - { + public static void glTexCoordPointer(int size, int type, int stride, ByteBuffer buffer) { GL11.glTexCoordPointer(size, type, stride, buffer); } - public static void glVertexPointer(int size, int type, int stride, int buffer_offset) - { - GL11.glVertexPointer(size, type, stride, (long)buffer_offset); + public static void glVertexPointer(int size, int type, int stride, int buffer_offset) { + GL11.glVertexPointer(size, type, stride, (long) buffer_offset); } - public static void glVertexPointer(int size, int type, int stride, ByteBuffer buffer) - { + public static void glVertexPointer(int size, int type, int stride, ByteBuffer buffer) { GL11.glVertexPointer(size, type, stride, buffer); } - public static void glColorPointer(int size, int type, int stride, int buffer_offset) - { - GL11.glColorPointer(size, type, stride, (long)buffer_offset); + public static void glColorPointer(int size, int type, int stride, int buffer_offset) { + GL11.glColorPointer(size, type, stride, (long) buffer_offset); } - public static void glColorPointer(int size, int type, int stride, ByteBuffer buffer) - { + public static void glColorPointer(int size, int type, int stride, ByteBuffer buffer) { GL11.glColorPointer(size, type, stride, buffer); } - public static void glDisableClientState(int cap) - { + public static void glDisableClientState(int cap) { GL11.glDisableClientState(cap); } - public static void glEnableClientState(int cap) - { + public static void glEnableClientState(int cap) { GL11.glEnableClientState(cap); } - public static void glBegin(int mode) - { + public static void glBegin(int mode) { GL11.glBegin(mode); } - public static void glEnd() - { + public static void glEnd() { GL11.glEnd(); } - public static void glDrawArrays(int mode, int first, int count) - { + public static void glDrawArrays(int mode, int first, int count) { GL11.glDrawArrays(mode, first, count); } - public static void glLineWidth(float width) - { + public static void glLineWidth(float width) { GL11.glLineWidth(width); } - public static void callList(int list) - { + public static void callList(int list) { GL11.glCallList(list); } - public static void glDeleteLists(int list, int range) - { + public static void glDeleteLists(int list, int range) { GL11.glDeleteLists(list, range); } - public static void glNewList(int list, int mode) - { + public static void glNewList(int list, int mode) { GL11.glNewList(list, mode); } - public static void glEndList() - { + public static void glEndList() { GL11.glEndList(); } - public static int glGenLists(int range) - { + public static int glGenLists(int range) { return GL11.glGenLists(range); } - public static void glPixelStorei(int parameterName, int param) - { + public static void glPixelStorei(int parameterName, int param) { GL11.glPixelStorei(parameterName, param); } - public static void glReadPixels(int x, int y, int width, int height, int format, int type, IntBuffer pixels) - { + public static void glReadPixels(int x, int y, int width, int height, int format, int type, IntBuffer pixels) { GL11.glReadPixels(x, y, width, height, format, type, pixels); } - public static int glGetError() - { + public static int glGetError() { return GL11.glGetError(); } - public static String glGetString(int name) - { + public static String glGetString(int name) { return GL11.glGetString(name); } - public static void glGetInteger(int parameterName, IntBuffer parameters) - { + public static void glGetInteger(int parameterName, IntBuffer parameters) { GL11.glGetInteger(parameterName, parameters); } - public static int glGetInteger(int parameterName) - { + public static int glGetInteger(int parameterName) { return GL11.glGetInteger(parameterName); } - static - { - for (int i = 0; i < 8; ++i) - { + static { + for (int i = 0; i < 8; ++i) { lightState[i] = new BooleanState(16384 + i); } @@ -851,8 +733,7 @@ public static int glGetInteger(int parameterName) normalizeState = new BooleanState(2977); textureState = new TextureState[8]; - for (int j = 0; j < 8; ++j) - { + for (int j = 0; j < 8; ++j) { textureState[j] = new TextureState(); } @@ -863,14 +744,12 @@ public static int glGetInteger(int parameterName) } @SideOnly(Side.CLIENT) - static class AlphaState - { + static class AlphaState { public BooleanState alphaTest; public int func; public float ref; - private AlphaState() - { + private AlphaState() { this.alphaTest = new BooleanState(3008); this.func = 519; this.ref = -1.0F; @@ -878,16 +757,14 @@ private AlphaState() } @SideOnly(Side.CLIENT) - static class BlendState - { + static class BlendState { public BooleanState blend; public int srcFactor; public int dstFactor; public int srcFactorAlpha; public int dstFactorAlpha; - private BlendState() - { + private BlendState() { this.blend = new BooleanState(3042); this.srcFactor = 1; this.dstFactor = 0; @@ -897,38 +774,29 @@ private BlendState() } @SideOnly(Side.CLIENT) - static class BooleanState - { + static class BooleanState { private final int capability; private boolean currentState; - public BooleanState(int capabilityIn) - { + public BooleanState(int capabilityIn) { this.capability = capabilityIn; } - public void setDisabled() - { + public void setDisabled() { this.setState(false); } - public void setEnabled() - { + public void setEnabled() { this.setState(true); } - public void setState(boolean state) - { - if (state != this.currentState) - { + public void setState(boolean state) { + if (state != this.currentState) { this.currentState = state; - if (state) - { + if (state) { GL11.glEnable(this.capability); - } - else - { + } else { GL11.glDisable(this.capability); } } @@ -936,33 +804,28 @@ public void setState(boolean state) } @SideOnly(Side.CLIENT) - static class ClearState - { + static class ClearState { public double depth; public Color color; - private ClearState() - { + private ClearState() { this.depth = 1.0D; this.color = new Color(0.0F, 0.0F, 0.0F, 0.0F); } } @SideOnly(Side.CLIENT) - static class Color - { + static class Color { public float red; public float green; public float blue; public float alpha; - public Color() - { + public Color() { this(1.0F, 1.0F, 1.0F, 1.0F); } - public Color(float redIn, float greenIn, float blueIn, float alphaIn) - { + public Color(float redIn, float greenIn, float blueIn, float alphaIn) { this.red = 1.0F; this.green = 1.0F; this.blue = 1.0F; @@ -975,28 +838,24 @@ public Color(float redIn, float greenIn, float blueIn, float alphaIn) } @SideOnly(Side.CLIENT) - static class ColorLogicState - { + static class ColorLogicState { public BooleanState colorLogicOp; public int opcode; - private ColorLogicState() - { + private ColorLogicState() { this.colorLogicOp = new BooleanState(3058); this.opcode = 5379; } } @SideOnly(Side.CLIENT) - static class ColorMask - { + static class ColorMask { public boolean red; public boolean green; public boolean blue; public boolean alpha; - private ColorMask() - { + private ColorMask() { this.red = true; this.green = true; this.blue = true; @@ -1005,14 +864,12 @@ private ColorMask() } @SideOnly(Side.CLIENT) - static class ColorMaterialState - { + static class ColorMaterialState { public BooleanState colorMaterial; public int face; public int mode; - private ColorMaterialState() - { + private ColorMaterialState() { this.colorMaterial = new BooleanState(2903); this.face = 1032; this.mode = 5634; @@ -1020,42 +877,36 @@ private ColorMaterialState() } @SideOnly(Side.CLIENT) - public static enum CullFace - { + public static enum CullFace { FRONT(1028), BACK(1029), FRONT_AND_BACK(1032); public final int mode; - private CullFace(int modeIn) - { + private CullFace(int modeIn) { this.mode = modeIn; } } @SideOnly(Side.CLIENT) - static class CullState - { + static class CullState { public BooleanState cullFace; public int mode; - private CullState() - { + private CullState() { this.cullFace = new BooleanState(2884); this.mode = 1029; } } @SideOnly(Side.CLIENT) - static class DepthState - { + static class DepthState { public BooleanState depthTest; public boolean maskEnabled; public int depthFunc; - private DepthState() - { + private DepthState() { this.depthTest = new BooleanState(2929); this.maskEnabled = true; this.depthFunc = 513; @@ -1063,8 +914,7 @@ private DepthState() } @SideOnly(Side.CLIENT) - public static enum DestFactor - { + public static enum DestFactor { CONSTANT_ALPHA(32771), CONSTANT_COLOR(32769), DST_ALPHA(772), @@ -1082,15 +932,13 @@ public static enum DestFactor public final int factor; - private DestFactor(int factorIn) - { + private DestFactor(int factorIn) { this.factor = factorIn; } } @SideOnly(Side.CLIENT) - public static enum FogMode - { + public static enum FogMode { LINEAR(9729), EXP(2048), EXP2(2049); @@ -1098,23 +946,20 @@ public static enum FogMode /** The capability ID of this {@link FogMode} */ public final int capabilityId; - private FogMode(int capabilityIn) - { + private FogMode(int capabilityIn) { this.capabilityId = capabilityIn; } } @SideOnly(Side.CLIENT) - static class FogState - { + static class FogState { public BooleanState fog; public int mode; public float density; public float start; public float end; - private FogState() - { + private FogState() { this.fog = new BooleanState(2912); this.mode = 2048; this.density = 1.0F; @@ -1123,8 +968,7 @@ private FogState() } @SideOnly(Side.CLIENT) - public static enum LogicOp - { + public static enum LogicOp { AND(5377), AND_INVERTED(5380), AND_REVERSE(5378), @@ -1144,30 +988,26 @@ public static enum LogicOp public final int opcode; - private LogicOp(int opcodeIn) - { + private LogicOp(int opcodeIn) { this.opcode = opcodeIn; } } @SideOnly(Side.CLIENT) - static class PolygonOffsetState - { + static class PolygonOffsetState { public BooleanState polygonOffsetFill; public BooleanState polygonOffsetLine; public float factor; public float units; - private PolygonOffsetState() - { + private PolygonOffsetState() { this.polygonOffsetFill = new BooleanState(32823); this.polygonOffsetLine = new BooleanState(10754); } } @SideOnly(Side.CLIENT) - public static enum SourceFactor - { + public static enum SourceFactor { CONSTANT_ALPHA(32771), CONSTANT_COLOR(32769), DST_ALPHA(772), @@ -1186,36 +1026,31 @@ public static enum SourceFactor public final int factor; - private SourceFactor(int factorIn) - { + private SourceFactor(int factorIn) { this.factor = factorIn; } } @SideOnly(Side.CLIENT) - static class StencilFunc - { + static class StencilFunc { public int func; public int mask; - private StencilFunc() - { + private StencilFunc() { this.func = 519; this.mask = -1; } } @SideOnly(Side.CLIENT) - static class StencilState - { + static class StencilState { public StencilFunc func; public int mask; public int fail; public int zfail; public int zpass; - private StencilState() - { + private StencilState() { this.func = new StencilFunc(); this.mask = -1; this.fail = 7680; @@ -1225,8 +1060,7 @@ private StencilState() } @SideOnly(Side.CLIENT) - public static enum TexGen - { + public static enum TexGen { S, T, R, @@ -1234,29 +1068,25 @@ public static enum TexGen } @SideOnly(Side.CLIENT) - static class TexGenCoord - { + static class TexGenCoord { public BooleanState textureGen; public int coord; public int param = -1; - public TexGenCoord(int coordIn, int capabilityIn) - { + public TexGenCoord(int coordIn, int capabilityIn) { this.coord = coordIn; this.textureGen = new BooleanState(capabilityIn); } } @SideOnly(Side.CLIENT) - static class TexGenState - { + static class TexGenState { public TexGenCoord s; public TexGenCoord t; public TexGenCoord r; public TexGenCoord q; - private TexGenState() - { + private TexGenState() { this.s = new TexGenCoord(8192, 3168); this.t = new TexGenCoord(8193, 3169); this.r = new TexGenCoord(8194, 3170); @@ -1265,13 +1095,11 @@ private TexGenState() } @SideOnly(Side.CLIENT) - static class TextureState - { + static class TextureState { public BooleanState texture2DState; public int textureName; - private TextureState() - { + private TextureState() { this.texture2DState = new BooleanState(3553); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java b/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java index 5c0c978..0c29aa3 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/KeyBindAPI.java @@ -1,8 +1,7 @@ package com.gtnewhorizons.modularui.api; -import net.minecraft.client.settings.KeyBinding; - import java.util.*; +import net.minecraft.client.settings.KeyBinding; public class KeyBindAPI { @@ -56,5 +55,4 @@ public static boolean areCompatible(KeyBinding keyBinding1, KeyBinding keyBindin public static Collection getCompatibles(KeyBinding keyBinding) { return compatibiliyMap.getOrDefault(keyBinding, Collections.emptySet()); } - } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java b/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java index 9402e23..dbcd4cc 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/ModularUITextures.java @@ -7,10 +7,14 @@ public class ModularUITextures { public static final UITexture ICON_INFO = UITexture.fullImage(ModularUI.MODID, "gui/widgets/information"); - public static final UITexture VANILLA_BACKGROUND = AdaptableUITexture.of(ModularUI.MODID, "gui/background/vanilla_background", 195, 136, 4); - public static final AdaptableUITexture BASE_BUTTON = AdaptableUITexture.of(ModularUI.MODID, "gui/widgets/base_button", 18, 18, 1); - public static final AdaptableUITexture ITEM_SLOT = AdaptableUITexture.of(ModularUI.MODID, "gui/slot/item", 18, 18, 1); - public static final AdaptableUITexture FLUID_SLOT = AdaptableUITexture.of(ModularUI.MODID, "gui/slot/fluid", 18, 18, 1); + public static final UITexture VANILLA_BACKGROUND = + AdaptableUITexture.of(ModularUI.MODID, "gui/background/vanilla_background", 195, 136, 4); + public static final AdaptableUITexture BASE_BUTTON = + AdaptableUITexture.of(ModularUI.MODID, "gui/widgets/base_button", 18, 18, 1); + public static final AdaptableUITexture ITEM_SLOT = + AdaptableUITexture.of(ModularUI.MODID, "gui/slot/item", 18, 18, 1); + public static final AdaptableUITexture FLUID_SLOT = + AdaptableUITexture.of(ModularUI.MODID, "gui/slot/fluid", 18, 18, 1); public static final UITexture ARROW_LEFT = UITexture.fullImage(ModularUI.MODID, "gui/icons/arrow_left"); public static final UITexture ARROW_RIGHT = UITexture.fullImage(ModularUI.MODID, "gui/icons/arrow_right"); diff --git a/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java b/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java index 97423cc..6bb321f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/NumberFormat.java @@ -1,26 +1,25 @@ package com.gtnewhorizons.modularui.api; -import org.jetbrains.annotations.NotNull; - import java.text.DecimalFormat; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; +import org.jetbrains.annotations.NotNull; public class NumberFormat { private static final NavigableMap suffixesByPower = new TreeMap<>(); private static final java.text.NumberFormat[] NUMBER_FORMAT = { - new DecimalFormat("0."), - new DecimalFormat("0.#"), - new DecimalFormat("0.##"), - new DecimalFormat("0.###"), - new DecimalFormat("0.####"), - new DecimalFormat("0.#####"), - new DecimalFormat("0.######"), - new DecimalFormat("0.#######"), - new DecimalFormat("0.########"), - new DecimalFormat("0.#########"), + new DecimalFormat("0."), + new DecimalFormat("0.#"), + new DecimalFormat("0.##"), + new DecimalFormat("0.###"), + new DecimalFormat("0.####"), + new DecimalFormat("0.#####"), + new DecimalFormat("0.######"), + new DecimalFormat("0.#######"), + new DecimalFormat("0.########"), + new DecimalFormat("0.#########"), }; static { @@ -40,7 +39,7 @@ public class NumberFormat { @NotNull public static String format(double value, int precision) { - //Double.MIN_VALUE == -Double.MIN_VALUE so we need an adjustment here + // Double.MIN_VALUE == -Double.MIN_VALUE so we need an adjustment here if (value == Double.MIN_VALUE) return format(Double.MIN_VALUE + 1, precision); if (value == 0) return "0"; if (value < 0) return '-' + format(-value, precision); @@ -55,9 +54,11 @@ public static String format(double value, int precision) { suffix = e.getValue(); } - double truncated = value / (divideBy / 10); //the number part of the output times 10 + double truncated = value / (divideBy / 10); // the number part of the output times 10 boolean hasDecimal = truncated < 100 && (truncated / 10D) != (truncated / 10); - return hasDecimal ? NUMBER_FORMAT[precision].format(truncated / 10D) + suffix : NUMBER_FORMAT[precision].format(truncated / 10) + suffix; + return hasDecimal + ? NUMBER_FORMAT[precision].format(truncated / 10D) + suffix + : NUMBER_FORMAT[precision].format(truncated / 10) + suffix; } @NotNull diff --git a/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java b/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java index ec7229d..9115b18 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/UIInfos.java @@ -1,29 +1,26 @@ package com.gtnewhorizons.modularui.api; import com.gtnewhorizons.modularui.ModularUI; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; +import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.builder.UIBuilder; import com.gtnewhorizons.modularui.common.builder.UIInfo; import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; - -import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; -import com.gtnewhorizons.modularui.api.screen.ModularUIContext; -import com.gtnewhorizons.modularui.api.screen.ModularWindow; -import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.util.function.Function; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; -import java.util.function.Function; - public class UIInfos { - public static void init() { - } + public static void init() {} public static final UIInfo TILE_MODULAR_UI = UIBuilder.of() .gui(((player, world, x, y, z) -> { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/Widget.java b/src/main/java/com/gtnewhorizons/modularui/api/Widget.java index 6ea5f6d..5d63618 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/Widget.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/Widget.java @@ -5,11 +5,8 @@ public class Widget { - public void drawForeGround(int mouseX, int mouseY, FontRenderer fontRenderer){ + public void drawForeGround(int mouseX, int mouseY, FontRenderer fontRenderer) {} - } - - public void drawBackGround(int mouseX, int mouseY, TextureManager textureManager, int WindowStartX, int windwStartY){ - - } + public void drawBackGround( + int mouseX, int mouseY, TextureManager textureManager, int WindowStartX, int windwStartY) {} } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java b/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java index 674fbf2..eff2d1f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/animation/Eases.java @@ -11,7 +11,6 @@ public enum Eases implements IEase { }), EaseQuadOut(input -> -input * (input - 2)); - IEase ease; Eases(IEase ease) { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java b/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java index 4751729..58e726d 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/animation/Interpolator.java @@ -18,7 +18,8 @@ public Interpolator(float from, float to, int duration, IEase ease, Consumer interpolate, Consumer callback) { + public Interpolator( + float from, float to, int duration, IEase ease, Consumer interpolate, Consumer callback) { this.from = from; this.to = to; this.duration = duration; diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java index e8aa4ca..186f3a7 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/AdaptableUITexture.java @@ -6,7 +6,16 @@ public class AdaptableUITexture extends UITexture { private final int imageWidth, imageHeight, borderWidthU, borderWidthV; - public AdaptableUITexture(ResourceLocation location, float u0, float v0, float u1, float v1, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) { + public AdaptableUITexture( + ResourceLocation location, + float u0, + float v0, + float u1, + float v1, + int imageWidth, + int imageHeight, + int borderWidthU, + int borderWidthV) { super(location, u0, v0, u1, v1); this.imageWidth = imageWidth; this.imageHeight = imageHeight; @@ -14,29 +23,44 @@ public AdaptableUITexture(ResourceLocation location, float u0, float v0, float u this.borderWidthV = borderWidthV; } - public AdaptableUITexture(ResourceLocation location, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) { + public AdaptableUITexture( + ResourceLocation location, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) { this(location, 0, 0, 1, 1, imageWidth, imageHeight, borderWidthU, borderWidthV); } - public static AdaptableUITexture of(ResourceLocation location, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) { + public static AdaptableUITexture of( + ResourceLocation location, int imageWidth, int imageHeight, int borderWidthU, int borderWidthV) { return new AdaptableUITexture(location, imageWidth, imageHeight, borderWidthU, borderWidthV); } - public static AdaptableUITexture of(ResourceLocation location, int imageWidth, int imageHeight, int borderWidthPixel) { + public static AdaptableUITexture of( + ResourceLocation location, int imageWidth, int imageHeight, int borderWidthPixel) { return new AdaptableUITexture(location, imageWidth, imageHeight, borderWidthPixel, borderWidthPixel); } public static AdaptableUITexture of(String location, int imageWidth, int imageHeight, int borderWidthPixel) { - return new AdaptableUITexture(new ResourceLocation(location), imageWidth, imageHeight, borderWidthPixel, borderWidthPixel); + return new AdaptableUITexture( + new ResourceLocation(location), imageWidth, imageHeight, borderWidthPixel, borderWidthPixel); } - public static AdaptableUITexture of(String mod, String location, int imageWidth, int imageHeight, int borderWidthPixel) { - return new AdaptableUITexture(new ResourceLocation(mod, location), imageWidth, imageHeight, borderWidthPixel, borderWidthPixel); + public static AdaptableUITexture of( + String mod, String location, int imageWidth, int imageHeight, int borderWidthPixel) { + return new AdaptableUITexture( + new ResourceLocation(mod, location), imageWidth, imageHeight, borderWidthPixel, borderWidthPixel); } @Override public AdaptableUITexture getSubArea(float uStart, float vStart, float uEnd, float vEnd) { - return new AdaptableUITexture(location, calcU(uStart), calcV(vStart), calcU(uEnd), calcV(vEnd), imageWidth, imageHeight, borderWidthU, borderWidthV); + return new AdaptableUITexture( + location, + calcU(uStart), + calcV(vStart), + calcU(uEnd), + calcV(vEnd), + imageWidth, + imageHeight, + borderWidthU, + borderWidthV); } @Override @@ -55,14 +79,77 @@ public void draw(float x, float y, float width, float height) { // draw corners draw(location, x, y, borderWidthU, borderWidthV, u0, v0, borderU, borderV); // x0 y0 draw(location, x + width - borderWidthU, y, borderWidthU, borderWidthV, u1 - borderU, v0, u1, borderV); // x1 y0 - draw(location, x, y + height - borderWidthV, borderWidthU, borderWidthV, u0, v1 - borderV, borderU, v1); // x0 y1 - draw(location, x + width - borderWidthU, y + height - borderWidthV, borderWidthU, borderWidthV, u1 - borderU, v1 - borderV, u1, v1); // x1 y1 + draw( + location, + x, + y + height - borderWidthV, + borderWidthU, + borderWidthV, + u0, + v1 - borderV, + borderU, + v1); // x0 y1 + draw( + location, + x + width - borderWidthU, + y + height - borderWidthV, + borderWidthU, + borderWidthV, + u1 - borderU, + v1 - borderV, + u1, + v1); // x1 y1 // draw edges - draw(location, x + borderWidthU, y, width - borderWidthU * 2, borderWidthV, borderU, v0, u1 - borderU, borderV); // top - draw(location, x + borderWidthU, y + height - borderWidthV, width - borderWidthU * 2, borderWidthV, borderU, v1 - borderV, u1 - borderU, v1); // bottom - draw(location, x, y + borderWidthV, borderWidthU, height - borderWidthV * 2, u0, borderV, borderU, v1 - borderV); // left - draw(location, x + width - borderWidthU, y + borderWidthV, borderWidthU, height - borderWidthV * 2, u1 - borderU, borderV, u1, v1 - borderV); // left + draw( + location, + x + borderWidthU, + y, + width - borderWidthU * 2, + borderWidthV, + borderU, + v0, + u1 - borderU, + borderV); // top + draw( + location, + x + borderWidthU, + y + height - borderWidthV, + width - borderWidthU * 2, + borderWidthV, + borderU, + v1 - borderV, + u1 - borderU, + v1); // bottom + draw( + location, + x, + y + borderWidthV, + borderWidthU, + height - borderWidthV * 2, + u0, + borderV, + borderU, + v1 - borderV); // left + draw( + location, + x + width - borderWidthU, + y + borderWidthV, + borderWidthU, + height - borderWidthV * 2, + u1 - borderU, + borderV, + u1, + v1 - borderV); // left // draw body - draw(location, x + borderWidthU, y + borderWidthV, width - borderWidthU * 2, height - borderWidthV * 2, borderU, borderV, u1 - borderU, v1 - borderV); + draw( + location, + x + borderWidthU, + y + borderWidthV, + width - borderWidthU * 2, + height - borderWidthV * 2, + borderU, + borderV, + u1 - borderU, + v1 - borderV); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java index 50758e2..0418830 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/GuiHelper.java @@ -7,6 +7,9 @@ import com.gtnewhorizons.modularui.api.math.Size; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.util.List; +import java.util.Stack; +import java.util.stream.Collectors; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; @@ -21,14 +24,10 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.util.List; -import java.util.Stack; -import java.util.stream.Collectors; - @SideOnly(Side.CLIENT) public class GuiHelper { - //==== Screen helpers ==== + // ==== Screen helpers ==== public static boolean hasScreen() { return Minecraft.getMinecraft().currentScreen != null; @@ -62,10 +61,16 @@ public static Pos2d getCurrentMousePos() { return Pos2d.ZERO; } + // ==== Tooltip helpers ==== - //==== Tooltip helpers ==== - - public static void drawHoveringText(List textLines, Pos2d mousePos, Size screenSize, int maxWidth, float scale, boolean forceShadow, Alignment alignment) { + public static void drawHoveringText( + List textLines, + Pos2d mousePos, + Size screenSize, + int maxWidth, + float scale, + boolean forceShadow, + Alignment alignment) { if (textLines.isEmpty()) { return; } @@ -77,21 +82,29 @@ public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, drawHoveringTextFormatted(lines, mousePos, screenSize, maxWidth, 1f, false, Alignment.TopLeft); } - public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, Size screenSize, int maxWidth, float scale, boolean forceShadow, Alignment alignment) { + public static void drawHoveringTextFormatted( + List lines, + Pos2d mousePos, + Size screenSize, + int maxWidth, + float scale, + boolean forceShadow, + Alignment alignment) { if (lines.isEmpty()) { return; } if (maxWidth < 0) { maxWidth = Integer.MAX_VALUE; } -// RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(ItemStack.EMPTY, lines, mousePos.x, mousePos.y, screenSize.width, screenSize.height, maxWidth, TextRenderer.getFontRenderer()); -// if (MinecraftForge.EVENT_BUS.post(event)) { -// return; -// } -// lines = event.getLines(); -// mousePos = new Pos2d(event.x(), event.getY()); -// screenSize = new Size(event.getScreenWidth(), event.getScreenHeight()); -// maxWidth = event.getMaxWidth(); + // RenderTooltipEvent.Pre event = new RenderTooltipEvent.Pre(ItemStack.EMPTY, lines, mousePos.x, + // mousePos.y, screenSize.width, screenSize.height, maxWidth, TextRenderer.getFontRenderer()); + // if (MinecraftForge.EVENT_BUS.post(event)) { + // return; + // } + // lines = event.getLines(); + // mousePos = new Pos2d(event.x(), event.getY()); + // screenSize = new Size(event.getScreenWidth(), event.getScreenHeight()); + // maxWidth = event.getMaxWidth(); int maxTextWidth = maxWidth; @@ -139,22 +152,87 @@ public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, int backgroundColor = 0xF0100010; int borderColorStart = 0x505000FF; int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; -// RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(ItemStack.EMPTY, lines, tooltipX, tooltipY, TextRenderer.getFontRenderer(), backgroundColor, borderColorStart, borderColorEnd); -// MinecraftForge.EVENT_BUS.post(colorEvent); -// backgroundColor = colorEvent.getBackground(); -// borderColorStart = colorEvent.getBorderStart(); -// borderColorEnd = colorEvent.getBorderEnd(); - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); - drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); - drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); - drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); - -// MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(ItemStack.EMPTY, lines, tooltipX, tooltipY, TextRenderer.getFontRenderer(), tooltipTextWidth, tooltipHeight)); + // RenderTooltipEvent.Color colorEvent = new RenderTooltipEvent.Color(ItemStack.EMPTY, lines, tooltipX, + // tooltipY, TextRenderer.getFontRenderer(), backgroundColor, borderColorStart, borderColorEnd); + // MinecraftForge.EVENT_BUS.post(colorEvent); + // backgroundColor = colorEvent.getBackground(); + // borderColorStart = colorEvent.getBorderStart(); + // borderColorEnd = colorEvent.getBorderEnd(); + drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 4, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3, + backgroundColor, + backgroundColor); + drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY + tooltipHeight + 3, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 4, + backgroundColor, + backgroundColor); + drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor); + drawGradientRect( + zLevel, + tooltipX - 4, + tooltipY - 3, + tooltipX - 3, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor); + drawGradientRect( + zLevel, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 4, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor); + drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3 + 1, + tooltipX - 3 + 1, + tooltipY + tooltipHeight + 3 - 1, + borderColorStart, + borderColorEnd); + drawGradientRect( + zLevel, + tooltipX + tooltipTextWidth + 2, + tooltipY - 3 + 1, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3 - 1, + borderColorStart, + borderColorEnd); + drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3 + 1, + borderColorStart, + borderColorStart); + drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY + tooltipHeight + 2, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3, + borderColorEnd, + borderColorEnd); + + // MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostBackground(ItemStack.EMPTY, lines, tooltipX, + // tooltipY, TextRenderer.getFontRenderer(), tooltipTextWidth, tooltipHeight)); renderer.setSimulate(false); renderer.setPos(tooltipX, tooltipY); @@ -162,7 +240,8 @@ public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, renderer.setColor(color); renderer.drawMeasuredLines(measuredLines); -// MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(ItemStack.EMPTY, lines, tooltipX, tooltipY, TextRenderer.getFontRenderer(), tooltipTextWidth, tooltipHeight)); + // MinecraftForge.EVENT_BUS.post(new RenderTooltipEvent.PostText(ItemStack.EMPTY, lines, tooltipX, + // tooltipY, TextRenderer.getFontRenderer(), tooltipTextWidth, tooltipHeight)); GlStateManager.enableLighting(); GlStateManager.enableDepth(); @@ -170,9 +249,10 @@ public static void drawHoveringTextFormatted(List lines, Pos2d mousePos, GlStateManager.enableRescaleNormal(); } - //==== Draw helpers ==== + // ==== Draw helpers ==== - public static void drawGradientRect(float zLevel, float left, float top, float right, float bottom, int startColor, int endColor) { + public static void drawGradientRect( + float zLevel, float left, float top, float right, float bottom, int startColor, int endColor) { float startAlpha = (float) (startColor >> 24 & 255) / 255.0F; float startRed = (float) (startColor >> 16 & 255) / 255.0F; float startGreen = (float) (startColor >> 8 & 255) / 255.0F; @@ -185,7 +265,11 @@ public static void drawGradientRect(float zLevel, float left, float top, float r GlStateManager.disableTexture2D(); GlStateManager.enableBlend(); GlStateManager.disableAlpha(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.tryBlendFuncSeparate( + GlStateManager.SourceFactor.SRC_ALPHA, + GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, + GlStateManager.SourceFactor.ONE, + GlStateManager.DestFactor.ZERO); GlStateManager.shadeModel(GL11.GL_SMOOTH); Tessellator tessellator = Tessellator.instance; @@ -216,12 +300,18 @@ public static void drawFluidTexture(FluidStack content, float x0, float y0, floa GlStateManager.enableBlend(); Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); - float u0 = fluidStill.getMinU(), u1 = fluidStill.getMaxU(), v0 = fluidStill.getMinV(), v1 = fluidStill.getMaxV(); + float u0 = fluidStill.getMinU(), + u1 = fluidStill.getMaxU(), + v0 = fluidStill.getMinV(), + v1 = fluidStill.getMaxV(); float x1 = x0 + width, y1 = y0 + height; - float r = Color.getRedF(fluidColor), g = Color.getGreenF(fluidColor), b = Color.getBlueF(fluidColor), a = Color.getAlphaF(fluidColor); + float r = Color.getRedF(fluidColor), + g = Color.getGreenF(fluidColor), + b = Color.getBlueF(fluidColor), + a = Color.getAlphaF(fluidColor); Tessellator tessellator = Tessellator.instance; -// tessellator.startDrawing(7, DefaultVertexFormats.POSITION_TEX_COLOR); + // tessellator.startDrawing(7, DefaultVertexFormats.POSITION_TEX_COLOR); tessellator.startDrawingQuads(); tessellator.setColorRGBA_F(r, g, b, a); tessellator.setTextureUV(u0, v1); @@ -236,8 +326,7 @@ public static void drawFluidTexture(FluidStack content, float x0, float y0, floa GlStateManager.disableBlend(); } - - //==== Scissor helpers ==== + // ==== Scissor helpers ==== private static final Stack scissorFrameStack = new Stack<>(); @@ -254,7 +343,7 @@ private static int[] peekFirstScissorOrFullScreen() { int[] currentTopFrame = scissorFrameStack.isEmpty() ? null : scissorFrameStack.peek(); if (currentTopFrame == null) { Minecraft minecraft = Minecraft.getMinecraft(); - return new int[]{0, 0, minecraft.displayWidth, minecraft.displayHeight}; + return new int[] {0, 0, minecraft.displayWidth, minecraft.displayHeight}; } return currentTopFrame; } @@ -278,11 +367,11 @@ public static void pushScissorFrame(int x, int y, int width, int height) { newWidth = Math.min(maxWidth, newWidth); newHeight = Math.min(maxHeight, newHeight); applyScissor(newX, newY, newWidth, newHeight); - //finally, push applied scissor on top of scissor stack + // finally, push applied scissor on top of scissor stack if (scissorFrameStack.isEmpty()) { GL11.glEnable(GL11.GL_SCISSOR_TEST); } - scissorFrameStack.push(new int[]{newX, newY, newWidth, newHeight}); + scissorFrameStack.push(new int[] {newX, newY, newWidth, newHeight}); pushedFrame = true; } } @@ -290,7 +379,7 @@ public static void pushScissorFrame(int x, int y, int width, int height) { if (scissorFrameStack.isEmpty()) { GL11.glEnable(GL11.GL_SCISSOR_TEST); } - scissorFrameStack.push(new int[]{parentX, parentY, parentWidth, parentHeight}); + scissorFrameStack.push(new int[] {parentX, parentY, parentWidth, parentHeight}); } } @@ -307,9 +396,9 @@ public static void popScissorFrame() { } } - //applies scissor with gui-space coordinates and sizes + // applies scissor with gui-space coordinates and sizes private static void applyScissor(int x, int y, int w, int h) { - //translate upper-left to bottom-left + // translate upper-left to bottom-left ScaledResolution r = ((GuiIngameForge) Minecraft.getMinecraft().ingameGUI).getResolution(); int s = r == null ? 1 : r.getScaleFactor(); int translatedY = r == null ? 0 : (r.getScaledHeight() - y - h); diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java index a238415..6d721a1 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/IDrawable.java @@ -9,7 +9,6 @@ import com.gtnewhorizons.modularui.common.widget.DrawableWidget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - import java.util.HashMap; import java.util.Map; import java.util.function.Function; @@ -20,8 +19,7 @@ public interface IDrawable { /** * Empty drawable */ - IDrawable EMPTY = (x, y, width, height, partialTicks) -> { - }; + IDrawable EMPTY = (x, y, width, height, partialTicks) -> {}; /** * Called ever frame @@ -40,12 +38,12 @@ default void draw(Pos2d pos, Size size, float partialTicks) { draw(pos.x, pos.y, size.width, size.height, partialTicks); } - default void tick() { - } + default void tick() {} @SideOnly(Side.CLIENT) default void applyThemeColor(int color) { - GlStateManager.color(Color.getRedF(color), Color.getGreenF(color), Color.getBlueF(color), Color.getAlphaF(color)); + GlStateManager.color( + Color.getRedF(color), Color.getGreenF(color), Color.getBlueF(color), Color.getAlphaF(color)); } @SideOnly(Side.CLIENT) @@ -100,7 +98,8 @@ default IDrawable withFixedSize(float fixedWidth, float fixedHeight) { static IDrawable ofJson(JsonObject json) { IDrawable drawable = EMPTY; if (json.has("type")) { - Function function = JSON_DRAWABLE_MAP.get(json.get("type").getAsString()); + Function function = + JSON_DRAWABLE_MAP.get(json.get("type").getAsString()); if (function != null) { drawable = function.apply(json); } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java index 61a523b..aab0b8c 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/ItemDrawable.java @@ -23,8 +23,7 @@ public ItemDrawable(@NotNull ItemStack item) { } @Override - public void applyThemeColor(int color) { - } + public void applyThemeColor(int color) {} @Override public void draw(float x, float y, float width, float height, float partialTicks) { @@ -33,7 +32,9 @@ public void draw(float x, float y, float width, float height, float partialTicks RenderHelper.enableGUIStandardItemLighting(); GlStateManager.enableDepth(); GlStateManager.scale(width / 16, height / 16, 1); - itemRenderer.renderItemAndEffectIntoGUI(item.getItem().getFontRenderer(item), Minecraft.getMinecraft().getTextureManager(), item, (int) x, (int) y); + itemRenderer.renderItemAndEffectIntoGUI( + item.getItem().getFontRenderer(item), Minecraft.getMinecraft().getTextureManager(), item, (int) x, (int) + y); GlStateManager.disableDepth(); RenderHelper.enableStandardItemLighting(); GlStateManager.disableLighting(); diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java index 0a0b8ca..ad3e86e 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/Text.java @@ -7,14 +7,13 @@ import com.gtnewhorizons.modularui.common.internal.JsonHelper; import com.gtnewhorizons.modularui.common.internal.Theme; import cpw.mods.fml.common.FMLCommonHandler; +import java.util.Objects; +import java.util.function.Supplier; +import javax.annotation.Nullable; import net.minecraft.client.resources.I18n; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; -import javax.annotation.Nullable; -import java.util.Objects; -import java.util.function.Supplier; - public class Text implements IDrawable { public static final Text EMPTY = new Text(""); @@ -22,8 +21,10 @@ public class Text implements IDrawable { private static final TextRenderer renderer = new TextRenderer(); private final String text; private String formatting = ""; + @Nullable private Supplier localisationData; + private int color; private boolean shadow = false; diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/TextRenderer.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/TextRenderer.java index 826c4ab..c0edb04 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/TextRenderer.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/TextRenderer.java @@ -7,13 +7,12 @@ import com.gtnewhorizons.modularui.common.internal.Theme; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import org.apache.commons.lang3.tuple.Pair; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import org.apache.commons.lang3.tuple.Pair; public class TextRenderer { @@ -95,7 +94,9 @@ public List> measureLines(List lines) { } public List wrapLine(String line) { - return maxWidth > 0 ? getFontRenderer().listFormattedStringToWidth(line, (int) (maxWidth / scale)) : Collections.singletonList(line); + return maxWidth > 0 + ? getFontRenderer().listFormattedStringToWidth(line, (int) (maxWidth / scale)) + : Collections.singletonList(line); } public boolean wouldFit(List text) { @@ -154,7 +155,7 @@ protected float draw(String text, float x, float y) { GlStateManager.disableBlend(); GlStateManager.pushMatrix(); GlStateManager.scale(scale, scale, 0f); - int width = getFontRenderer().drawString(text, (int)(x / scale), (int)(y / scale), color, shadow); + int width = getFontRenderer().drawString(text, (int) (x / scale), (int) (y / scale), color, shadow); GlStateManager.popMatrix(); GlStateManager.enableBlend(); return width * scale; diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/UITexture.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/UITexture.java index 2c85be8..5fcdea3 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/UITexture.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/UITexture.java @@ -2,18 +2,16 @@ import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.math.GuiArea; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.common.internal.JsonHelper; +import java.util.HashMap; +import java.util.Map; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import java.util.HashMap; -import java.util.Map; - public class UITexture implements IDrawable { public static final Map JSON_TEXTURES = new HashMap<>(); @@ -58,15 +56,22 @@ public static UITexture fullImage(String mod, String location) { return fullImage(new ResourceLocation(mod, location)); } - public static UITexture partly(ResourceLocation location, int imageWidth, int imageHeight, int u0, int v0, int u1, int v1) { - return new UITexture(location, u0 / (float) imageWidth, v0 / (float) imageHeight, u1 / (float) imageWidth, v1 / (float) imageHeight); + public static UITexture partly( + ResourceLocation location, int imageWidth, int imageHeight, int u0, int v0, int u1, int v1) { + return new UITexture( + location, + u0 / (float) imageWidth, + v0 / (float) imageHeight, + u1 / (float) imageWidth, + v1 / (float) imageHeight); } public static UITexture partly(String location, int imageWidth, int imageHeight, int u0, int v0, int u1, int v1) { return partly(new ResourceLocation(location), imageWidth, imageHeight, u0, v0, u1, v1); } - public static UITexture partly(String domain, String location, int imageWidth, int imageHeight, int u0, int v0, int u1, int v1) { + public static UITexture partly( + String domain, String location, int imageWidth, int imageHeight, int u0, int v0, int u1, int v1) { return partly(new ResourceLocation(domain, location), imageWidth, imageHeight, u0, v0, u1, v1); } @@ -90,7 +95,14 @@ public UITexture getSubArea(float uStart, float vStart, float uEnd, float vEnd) public UITexture exposeToJson() { if (JSON_TEXTURES.containsKey(location)) { UITexture texture = JSON_TEXTURES.get(location); - ModularUI.logger.error("{} '{}' is already exposed to json with uv {}, {}, {}, {}!", texture.getClass().getSimpleName(), location, texture.u0, texture.v0, texture.u1, texture.v1); + ModularUI.logger.error( + "{} '{}' is already exposed to json with uv {}, {}, {}, {}!", + texture.getClass().getSimpleName(), + location, + texture.u0, + texture.v0, + texture.u1, + texture.v1); } else { JSON_TEXTURES.put(location, this); } @@ -118,11 +130,21 @@ public void draw(float x, float y, float width, float height) { draw(location, x, y, width, height, u0, v0, u1, v1); } - public void drawSubArea(float x, float y, float width, float height, float uStart, float vStart, float uEnd, float vEnd) { + public void drawSubArea( + float x, float y, float width, float height, float uStart, float vStart, float uEnd, float vEnd) { draw(location, x, y, width, height, calcU(uStart), calcV(vStart), calcU(uEnd), calcV(vEnd)); } - public static void draw(ResourceLocation location, float x0, float y0, float width, float height, float u0, float v0, float u1, float v1) { + public static void draw( + ResourceLocation location, + float x0, + float y0, + float width, + float height, + float u0, + float v0, + float u1, + float v1) { float x1 = x0 + width, y1 = y0 + height; Minecraft.getMinecraft().renderEngine.bindTexture(location); Tessellator tessellator = Tessellator.instance; @@ -154,7 +176,8 @@ public static UITexture ofJson(JsonObject json) { Size imageSize = JsonHelper.getElement(json, Size.ZERO, Size::ofJson, "imageSize"); int borderWidth = JsonHelper.getInt(json, -1, "borderWidth"); if (imageSize.width > 0 && imageSize.height > 0 && borderWidth >= 0) { - return AdaptableUITexture.of(rl, imageSize.width, imageSize.height, borderWidth).getSubArea(u0, v0, u1, v1); + return AdaptableUITexture.of(rl, imageSize.width, imageSize.height, borderWidth) + .getSubArea(u0, v0, u1, v1); } return new UITexture(rl, u0, v0, u1, v1); } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Circle.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Circle.java index d9a6f93..0a9cf71 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Circle.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Circle.java @@ -53,12 +53,20 @@ public void draw(float x0, float y0, float width, float height, float partialTic GlStateManager.disableTexture2D(); GlStateManager.enableBlend(); GlStateManager.enableAlpha(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.tryBlendFuncSeparate( + GlStateManager.SourceFactor.SRC_ALPHA, + GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, + GlStateManager.SourceFactor.ONE, + GlStateManager.DestFactor.ZERO); GlStateManager.shadeModel(7425); Tessellator tessellator = Tessellator.instance; float x_2 = x0 + width / 2, y_2 = y0 + height / 2; tessellator.startDrawing(GL11.GL_TRIANGLE_FAN); - tessellator.setColorRGBA(Color.getRed(colorInner), Color.getGreen(colorInner), Color.getBlue(colorInner), Color.getAlpha(colorInner)); + tessellator.setColorRGBA( + Color.getRed(colorInner), + Color.getGreen(colorInner), + Color.getBlue(colorInner), + Color.getAlpha(colorInner)); tessellator.addVertex(x_2, y_2, 0.0f); float incr = (float) (PI2 / segments); for (int i = 0; i <= segments; i++) { @@ -66,7 +74,11 @@ public void draw(float x0, float y0, float width, float height, float partialTic float x = (float) (Math.sin(angle) * (width / 2) + x_2); float y = (float) (Math.cos(angle) * (height / 2) + y_2); tessellator.startDrawing(GL11.GL_TRIANGLE_FAN); - tessellator.setColorRGBA(Color.getRed(colorOuter), Color.getGreen(colorOuter), Color.getBlue(colorOuter), Color.getAlpha(colorOuter)); + tessellator.setColorRGBA( + Color.getRed(colorOuter), + Color.getGreen(colorOuter), + Color.getBlue(colorOuter), + Color.getAlpha(colorOuter)); tessellator.addVertex(x, y, 0.0f); } tessellator.draw(); diff --git a/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Rectangle.java b/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Rectangle.java index ad492e8..dcdbae6 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Rectangle.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/drawable/shapes/Rectangle.java @@ -63,62 +63,93 @@ public void draw(float x0, float y0, float width, float height, float partialTic GlStateManager.disableTexture2D(); GlStateManager.enableBlend(); GlStateManager.enableAlpha(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.tryBlendFuncSeparate( + GlStateManager.SourceFactor.SRC_ALPHA, + GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, + GlStateManager.SourceFactor.ONE, + GlStateManager.DestFactor.ZERO); GlStateManager.shadeModel(7425); Tessellator tessellator = Tessellator.instance; float x1 = x0 + width, y1 = y0 + height; if (this.cornerRadius == 0) { tessellator.startDrawingQuads(); - tessellator.setColorRGBA_F(Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); + tessellator.setColorRGBA_F( + Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); tessellator.addVertex(x0, y0, 0.0f); - tessellator.setColorRGBA_F(Color.getRed(colorBL), Color.getGreen(colorBL), Color.getBlue(colorBL), Color.getAlpha(colorBL)); + tessellator.setColorRGBA_F( + Color.getRed(colorBL), Color.getGreen(colorBL), Color.getBlue(colorBL), Color.getAlpha(colorBL)); tessellator.addVertex(x0, y1, 0.0f); - tessellator.setColorRGBA_F(Color.getRed(colorBR), Color.getGreen(colorBR), Color.getBlue(colorBR), Color.getAlpha(colorBR)); + tessellator.setColorRGBA_F( + Color.getRed(colorBR), Color.getGreen(colorBR), Color.getBlue(colorBR), Color.getAlpha(colorBR)); tessellator.addVertex(x1, y1, 0.0f); - tessellator.setColorRGBA_F(Color.getRed(colorTR), Color.getGreen(colorTR), Color.getBlue(colorTR), Color.getAlpha(colorTR)); + tessellator.setColorRGBA_F( + Color.getRed(colorTR), Color.getGreen(colorTR), Color.getBlue(colorTR), Color.getAlpha(colorTR)); tessellator.addVertex(x1, y0, 0.0f); } else { tessellator.startDrawing(GL11.GL_TRIANGLE_FAN); int color = Color.average(colorBL, colorBR, colorTR, colorTL); - tessellator.setColorRGBA_F(Color.getRed(color), Color.getGreen(color), Color.getBlue(color), Color.getAlpha(color)); + tessellator.setColorRGBA_F( + Color.getRed(color), Color.getGreen(color), Color.getBlue(color), Color.getAlpha(color)); tessellator.addVertex(x0 + width / 2, y0 + height / 2, 0.0f); - tessellator.setColorRGBA_F(Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); + tessellator.setColorRGBA_F( + Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); tessellator.addVertex(x0, y0 + cornerRadius, 0.0f); - tessellator.setColorRGBA_F(Color.getRed(colorBL), Color.getGreen(colorBL), Color.getBlue(colorBL), Color.getAlpha(colorBL)); + tessellator.setColorRGBA_F( + Color.getRed(colorBL), Color.getGreen(colorBL), Color.getBlue(colorBL), Color.getAlpha(colorBL)); tessellator.addVertex(x0, y1 - cornerRadius, 0.0f); int n = cornerSegments; for (int i = 1; i <= n; i++) { float x = (float) (x0 + cornerRadius - Math.cos(PI_2 / n * i) * cornerRadius); float y = (float) (y1 - cornerRadius + Math.sin(PI_2 / n * i) * cornerRadius); - tessellator.setColorRGBA_F(Color.getRed(colorBL), Color.getGreen(colorBL), Color.getBlue(colorBL), Color.getAlpha(colorBL)); + tessellator.setColorRGBA_F( + Color.getRed(colorBL), + Color.getGreen(colorBL), + Color.getBlue(colorBL), + Color.getAlpha(colorBL)); tessellator.addVertex(x, y, 0.0f); } - tessellator.setColorRGBA_F(Color.getRed(colorBR), Color.getGreen(colorBR), Color.getBlue(colorBR), Color.getAlpha(colorBR)); + tessellator.setColorRGBA_F( + Color.getRed(colorBR), Color.getGreen(colorBR), Color.getBlue(colorBR), Color.getAlpha(colorBR)); tessellator.addVertex(x1 - cornerRadius, y1, 0.0f); for (int i = 1; i <= n; i++) { float x = (float) (x1 - cornerRadius + Math.sin(PI_2 / n * i) * cornerRadius); float y = (float) (y1 - cornerRadius + Math.cos(PI_2 / n * i) * cornerRadius); - tessellator.setColorRGBA_F(Color.getRed(colorBR), Color.getGreen(colorBR), Color.getBlue(colorBR), Color.getAlpha(colorBR)); + tessellator.setColorRGBA_F( + Color.getRed(colorBR), + Color.getGreen(colorBR), + Color.getBlue(colorBR), + Color.getAlpha(colorBR)); tessellator.addVertex(x, y, 0.0f); } - tessellator.setColorRGBA_F(Color.getRed(colorTR), Color.getGreen(colorTR), Color.getBlue(colorTR), Color.getAlpha(colorTR)); + tessellator.setColorRGBA_F( + Color.getRed(colorTR), Color.getGreen(colorTR), Color.getBlue(colorTR), Color.getAlpha(colorTR)); tessellator.addVertex(x1, y0 + cornerRadius, 0.0f); for (int i = 1; i <= n; i++) { float x = (float) (x1 - cornerRadius + Math.cos(PI_2 / n * i) * cornerRadius); float y = (float) (y0 + cornerRadius - Math.sin(PI_2 / n * i) * cornerRadius); - tessellator.setColorRGBA_F(Color.getRed(colorTR), Color.getGreen(colorTR), Color.getBlue(colorTR), Color.getAlpha(colorTR)); + tessellator.setColorRGBA_F( + Color.getRed(colorTR), + Color.getGreen(colorTR), + Color.getBlue(colorTR), + Color.getAlpha(colorTR)); tessellator.addVertex(x, y, 0.0f); } - tessellator.setColorRGBA_F(Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); + tessellator.setColorRGBA_F( + Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); tessellator.addVertex(x0 + cornerRadius, y0, 0.0f); for (int i = 1; i <= n; i++) { float x = (float) (x0 + cornerRadius - Math.sin(PI_2 / n * i) * cornerRadius); float y = (float) (y0 + cornerRadius - Math.cos(PI_2 / n * i) * cornerRadius); - tessellator.setColorRGBA_F(Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); + tessellator.setColorRGBA_F( + Color.getRed(colorTL), + Color.getGreen(colorTL), + Color.getBlue(colorTL), + Color.getAlpha(colorTL)); tessellator.addVertex(x, y, 0.0f); } - tessellator.setColorRGBA_F(Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); + tessellator.setColorRGBA_F( + Color.getRed(colorTL), Color.getGreen(colorTL), Color.getBlue(colorTL), Color.getAlpha(colorTL)); tessellator.addVertex(x0, y0 + cornerRadius, 0.0f); } tessellator.draw(); diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/CraftingHelper.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/CraftingHelper.java index 4a07723..3a0f3d6 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/CraftingHelper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/CraftingHelper.java @@ -1,11 +1,7 @@ package com.gtnewhorizons.modularui.api.forge; - import com.gtnewhorizons.modularui.ModularUI; import cpw.mods.fml.common.ModContainer; -import net.minecraft.item.crafting.CraftingManager; -import org.apache.commons.io.IOUtils; - import java.io.File; import java.io.IOException; import java.net.URI; @@ -17,28 +13,32 @@ import java.util.Iterator; import java.util.function.BiFunction; import java.util.function.Function; +import net.minecraft.item.crafting.CraftingManager; +import org.apache.commons.io.IOUtils; public class CraftingHelper { private static final boolean DEBUG_LOAD_MINECRAFT = false; - public static boolean findFiles(ModContainer mod, String base, Function preprocessor, BiFunction processor, - boolean defaultUnfoundRoot, boolean visitAllFiles) { + public static boolean findFiles( + ModContainer mod, + String base, + Function preprocessor, + BiFunction processor, + boolean defaultUnfoundRoot, + boolean visitAllFiles) { File source = mod.getSource(); - if ("minecraft".equals(mod.getModId())) - { - if (!DEBUG_LOAD_MINECRAFT) - return true; + if ("minecraft".equals(mod.getModId())) { + if (!DEBUG_LOAD_MINECRAFT) return true; - try - { - URI tmp = CraftingManager.class.getResource("/assets/.mcassetsroot").toURI(); + try { + URI tmp = CraftingManager.class + .getResource("/assets/.mcassetsroot") + .toURI(); source = new File(tmp.resolve("..").getPath()); - } - catch (URISyntaxException e) - { + } catch (URISyntaxException e) { ModularUI.logger.error("Error finding Minecraft jar: ", e); return false; } @@ -47,68 +47,48 @@ public static boolean findFiles(ModContainer mod, String base, Function itr = null; - try - { + try { itr = Files.walk(root).iterator(); - } - catch (IOException e) - { + } catch (IOException e) { ModularUI.logger.error("Error iterating filesystem for: {}", mod.getModId(), e); return false; } - while (itr != null && itr.hasNext()) - { + while (itr != null && itr.hasNext()) { Boolean cont = processor.apply(root, itr.next()); - if (visitAllFiles) - { + if (visitAllFiles) { success &= cont != null && cont; - } - else if (cont == null || !cont) - { + } else if (cont == null || !cont) { return false; } } } - } - finally - { + } finally { IOUtils.closeQuietly(fs); } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandler.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandler.java index a105c86..da72ae1 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandler.java @@ -4,7 +4,6 @@ // (powered by FernFlower decompiler) // -import javax.annotation.Nonnull; import net.minecraft.item.ItemStack; public interface IItemHandler { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandlerModifiable.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandlerModifiable.java index e31a835..99aa3eb 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandlerModifiable.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/IItemHandlerModifiable.java @@ -9,4 +9,3 @@ public interface IItemHandlerModifiable extends IItemHandler { void setStackInSlot(int var1, ItemStack var2); } - diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/InvWrapper.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/InvWrapper.java index 09bad32..0b4c2ad 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/InvWrapper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/InvWrapper.java @@ -6,69 +6,53 @@ public class InvWrapper implements IItemHandlerModifiable { private final IInventory inv; - public InvWrapper(IInventory inv) - { + public InvWrapper(IInventory inv) { this.inv = inv; } @Override - public boolean equals(Object o) - { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; InvWrapper that = (InvWrapper) o; return getInv().equals(that.getInv()); - } @Override - public int hashCode() - { + public int hashCode() { return getInv().hashCode(); } @Override - public int getSlots() - { + public int getSlots() { return getInv().getSizeInventory(); } @Override - public ItemStack getStackInSlot(int slot) - { + public ItemStack getStackInSlot(int slot) { return getInv().getStackInSlot(slot); } @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) - { - if (stack == null) - return null; + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (stack == null) return null; ItemStack stackInSlot = getInv().getStackInSlot(slot); int m; - if (stackInSlot != null) - { - if (stackInSlot.stackSize >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot))) - return stack; + if (stackInSlot != null) { + if (stackInSlot.stackSize >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot))) return stack; - if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot)) - return stack; + if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot)) return stack; - if (!getInv().isItemValidForSlot(slot, stack)) - return stack; + if (!getInv().isItemValidForSlot(slot, stack)) return stack; m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.stackSize; - if (stack.stackSize <= m) - { - if (!simulate) - { + if (stack.stackSize <= m) { + if (!simulate) { ItemStack copy = stack.copy(); copy.stackSize += stackInSlot.stackSize; getInv().setInventorySlotContents(slot, copy); @@ -76,87 +60,62 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) } return null; - } - else - { + } else { // copy the stack to not modify the original one stack = stack.copy(); - if (!simulate) - { + if (!simulate) { ItemStack copy = stack.splitStack(m); copy.stackSize += stackInSlot.stackSize; getInv().setInventorySlotContents(slot, copy); getInv().markDirty(); return stack; - } - else - { + } else { stack.stackSize -= m; return stack; } } - } - else - { - if (!getInv().isItemValidForSlot(slot, stack)) - return stack; + } else { + if (!getInv().isItemValidForSlot(slot, stack)) return stack; m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)); - if (m < stack.stackSize) - { + if (m < stack.stackSize) { // copy the stack to not modify the original one stack = stack.copy(); - if (!simulate) - { + if (!simulate) { getInv().setInventorySlotContents(slot, stack.splitStack(m)); getInv().markDirty(); return stack; - } - else - { + } else { stack.stackSize -= m; return stack; } - } - else - { - if (!simulate) - { + } else { + if (!simulate) { getInv().setInventorySlotContents(slot, stack); getInv().markDirty(); } return null; } } - } @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) - { - if (amount == 0) - return null; + public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (amount == 0) return null; ItemStack stackInSlot = getInv().getStackInSlot(slot); - if (stackInSlot == null) - return null; + if (stackInSlot == null) return null; - if (simulate) - { - if (stackInSlot.stackSize < amount) - { + if (simulate) { + if (stackInSlot.stackSize < amount) { return stackInSlot.copy(); - } - else - { + } else { ItemStack copy = stackInSlot.copy(); copy.stackSize = amount; return copy; } - } - else - { + } else { int m = Math.min(stackInSlot.stackSize, amount); ItemStack decrStackSize = getInv().decrStackSize(slot, m); @@ -166,25 +125,21 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) } @Override - public void setStackInSlot(int slot, ItemStack stack) - { + public void setStackInSlot(int slot, ItemStack stack) { getInv().setInventorySlotContents(slot, stack); } @Override - public int getSlotLimit(int slot) - { + public int getSlotLimit(int slot) { return getInv().getInventoryStackLimit(); } @Override - public boolean isItemValid(int slot, ItemStack stack) - { + public boolean isItemValid(int slot, ItemStack stack) { return getInv().isItemValidForSlot(slot, stack); } - public IInventory getInv() - { + public IInventory getInv() { return inv; } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemHandlerHelper.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemHandlerHelper.java index 47574f7..48d32ed 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemHandlerHelper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemHandlerHelper.java @@ -5,22 +5,19 @@ // import javax.annotation.Nullable; - import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -//import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class ItemHandlerHelper { - public ItemHandlerHelper() { - } + public ItemHandlerHelper() {} public static ItemStack insertItem(IItemHandler dest, ItemStack stack, boolean simulate) { if (dest != null && stack != null) { - for(int i = 0; i < dest.getSlots(); ++i) { + for (int i = 0; i < dest.getSlots(); ++i) { stack = dest.insertItem(i, stack, simulate); if (stack == null) { return null; @@ -75,7 +72,7 @@ public static ItemStack insertItemStacked(IItemHandler inventory, ItemStack stac int sizeInventory = inventory.getSlots(); int i; - for(i = 0; i < sizeInventory; ++i) { + for (i = 0; i < sizeInventory; ++i) { ItemStack slot = inventory.getStackInSlot(i); if (canItemStacksStackRelaxed(slot, stack)) { stack = inventory.insertItem(i, stack, simulate); @@ -86,7 +83,7 @@ public static ItemStack insertItemStacked(IItemHandler inventory, ItemStack stac } if (stack != null) { - for(i = 0; i < sizeInventory; ++i) { + for (i = 0; i < sizeInventory; ++i) { if (inventory.getStackInSlot(i) == null) { stack = inventory.insertItem(i, stack, simulate); if (stack == null) { @@ -121,7 +118,11 @@ public static void giveItemToPlayer(EntityPlayer player, ItemStack stack, int pr } if (remainder == null || remainder.stackSize != stack.stackSize) { - world.playSoundAtEntity(player, "random.pop", 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); + world.playSoundAtEntity( + player, + "random.pop", + 0.2F, + ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); } if (remainder != null && !world.isRemote) { @@ -131,7 +132,6 @@ public static void giveItemToPlayer(EntityPlayer player, ItemStack stack, int pr entityitem.motionZ = 0.0D; world.spawnEntityInWorld(entityitem); } - } } @@ -142,17 +142,17 @@ public static int calcRedstoneFromInventory(@Nullable IItemHandler inv) { int itemsFound = 0; float proportion = 0.0F; - for(int j = 0; j < inv.getSlots(); ++j) { + for (int j = 0; j < inv.getSlots(); ++j) { ItemStack itemstack = inv.getStackInSlot(j); if (itemstack != null) { - proportion += (float)itemstack.stackSize / (float)Math.min(inv.getSlotLimit(j), itemstack.getMaxStackSize()); + proportion += (float) itemstack.stackSize + / (float) Math.min(inv.getSlotLimit(j), itemstack.getMaxStackSize()); ++itemsFound; } } - proportion /= (float)inv.getSlots(); + proportion /= (float) inv.getSlots(); return MathHelper.floor_float(proportion * 14.0F) + (itemsFound > 0 ? 1 : 0); } } } - diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemStackHandler.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemStackHandler.java index 1c0d992..c0f5e06 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemStackHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/ItemStackHandler.java @@ -4,13 +4,12 @@ // (powered by FernFlower decompiler) // +import java.util.Arrays; +import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import java.util.Arrays; -import java.util.List; - public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, INBTSerializable { protected List stacks; @@ -28,8 +27,7 @@ public ItemStackHandler(List stacks) { this.stacks = stacks; } - public void setSize(int size) - { + public void setSize(int size) { ItemStack[] stacks = new ItemStack[size]; Arrays.fill(stacks, null); this.stacks = Arrays.asList(stacks); @@ -50,7 +48,7 @@ public int getSlots() { @Override public ItemStack getStackInSlot(int slot) { this.validateSlotIndex(slot); - return (ItemStack)this.stacks.get(slot); + return (ItemStack) this.stacks.get(slot); } @Override @@ -59,7 +57,7 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { return null; } else { this.validateSlotIndex(slot); - ItemStack existing = (ItemStack)this.stacks.get(slot); + ItemStack existing = (ItemStack) this.stacks.get(slot); int limit = this.getStackLimit(slot, stack); if (existing != null) { if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) { @@ -94,7 +92,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) { return null; } else { this.validateSlotIndex(slot); - ItemStack existing = (ItemStack)this.stacks.get(slot); + ItemStack existing = (ItemStack) this.stacks.get(slot); if (existing == null) { return null; } else { @@ -108,7 +106,8 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) { return existing; } else { if (!simulate) { - this.stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.stackSize - toExtract)); + this.stacks.set( + slot, ItemHandlerHelper.copyStackWithSize(existing, existing.stackSize - toExtract)); this.onContentsChanged(slot); } @@ -136,11 +135,11 @@ public boolean isItemValid(int slot, ItemStack stack) { public NBTTagCompound serializeNBT() { NBTTagList nbtTagList = new NBTTagList(); - for(int i = 0; i < this.stacks.size(); ++i) { - if ((ItemStack)this.stacks.get(i) != null) { + for (int i = 0; i < this.stacks.size(); ++i) { + if ((ItemStack) this.stacks.get(i) != null) { NBTTagCompound itemTag = new NBTTagCompound(); itemTag.setInteger("Slot", i); - ((ItemStack)this.stacks.get(i)).writeToNBT(itemTag); + ((ItemStack) this.stacks.get(i)).writeToNBT(itemTag); nbtTagList.appendTag(itemTag); } } @@ -156,11 +155,11 @@ public void deserializeNBT(NBTTagCompound nbt) { this.setSize(nbt.hasKey("Size", 3) ? nbt.getInteger("Size") : this.stacks.size()); NBTTagList tagList = nbt.getTagList("Items", 10); - for(int i = 0; i < tagList.tagCount(); ++i) { + for (int i = 0; i < tagList.tagCount(); ++i) { NBTTagCompound itemTags = tagList.getCompoundTagAt(i); int slot = itemTags.getInteger("Slot"); if (slot >= 0 && slot < this.stacks.size()) { -// this.stacks.set(slot, new ItemStack(itemTags)); + // this.stacks.set(slot, new ItemStack(itemTags)); } } @@ -173,9 +172,7 @@ protected void validateSlotIndex(int slot) { } } - protected void onLoad() { - } + protected void onLoad() {} - protected void onContentsChanged(int slot) { - } + protected void onContentsChanged(int slot) {} } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/PlayerMainInvWrapper.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/PlayerMainInvWrapper.java index 055339d..03ea9e4 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/PlayerMainInvWrapper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/PlayerMainInvWrapper.java @@ -11,27 +11,21 @@ public class PlayerMainInvWrapper extends RangedWrapper { private final InventoryPlayer inventoryPlayer; - public PlayerMainInvWrapper(InventoryPlayer inv) - { + public PlayerMainInvWrapper(InventoryPlayer inv) { super(new InvWrapper(inv), 0, inv.mainInventory.length); inventoryPlayer = inv; } @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) - { + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { ItemStack rest = super.insertItem(slot, stack, simulate); - if (rest.stackSize != stack.stackSize) - { + if (rest.stackSize != stack.stackSize) { // the stack in the slot changed, animate it ItemStack inSlot = getStackInSlot(slot); - if(inSlot != null) - { - if (getInventoryPlayer().player.worldObj.isRemote) - { + if (inSlot != null) { + if (getInventoryPlayer().player.worldObj.isRemote) { inSlot.animationsToGo = 5; - } - else if(getInventoryPlayer().player instanceof EntityPlayerMP) { + } else if (getInventoryPlayer().player instanceof EntityPlayerMP) { getInventoryPlayer().player.openContainer.detectAndSendChanges(); } } @@ -39,8 +33,7 @@ else if(getInventoryPlayer().player instanceof EntityPlayerMP) { return rest; } - public InventoryPlayer getInventoryPlayer() - { + public InventoryPlayer getInventoryPlayer() { return inventoryPlayer; } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/RangedWrapper.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/RangedWrapper.java index c49cc7f..5c6ce4e 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/RangedWrapper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/RangedWrapper.java @@ -13,8 +13,7 @@ public class RangedWrapper implements IItemHandlerModifiable { private final int minSlot; private final int maxSlot; - public RangedWrapper(IItemHandlerModifiable compose, int minSlot, int maxSlotExclusive) - { + public RangedWrapper(IItemHandlerModifiable compose, int minSlot, int maxSlotExclusive) { Preconditions.checkArgument(maxSlotExclusive > minSlot, "Max slot must be greater than min slot"); this.compose = compose; this.minSlot = minSlot; @@ -22,16 +21,13 @@ public RangedWrapper(IItemHandlerModifiable compose, int minSlot, int maxSlotExc } @Override - public int getSlots() - { + public int getSlots() { return maxSlot - minSlot; } @Override - public ItemStack getStackInSlot(int slot) - { - if (checkSlot(slot)) - { + public ItemStack getStackInSlot(int slot) { + if (checkSlot(slot)) { return compose.getStackInSlot(slot + minSlot); } @@ -39,10 +35,8 @@ public ItemStack getStackInSlot(int slot) } @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) - { - if (checkSlot(slot)) - { + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (checkSlot(slot)) { return compose.insertItem(slot + minSlot, stack, simulate); } @@ -50,10 +44,8 @@ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) } @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) - { - if (checkSlot(slot)) - { + public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (checkSlot(slot)) { return compose.extractItem(slot + minSlot, amount, simulate); } @@ -61,19 +53,15 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) } @Override - public void setStackInSlot(int slot, ItemStack stack) - { - if (checkSlot(slot)) - { + public void setStackInSlot(int slot, ItemStack stack) { + if (checkSlot(slot)) { compose.setStackInSlot(slot + minSlot, stack); } } @Override - public int getSlotLimit(int slot) - { - if (checkSlot(slot)) - { + public int getSlotLimit(int slot) { + if (checkSlot(slot)) { return compose.getSlotLimit(slot + minSlot); } @@ -81,18 +69,15 @@ public int getSlotLimit(int slot) } @Override - public boolean isItemValid(int slot, ItemStack stack) - { - if (checkSlot(slot)) - { + public boolean isItemValid(int slot, ItemStack stack) { + if (checkSlot(slot)) { return compose.isItemValid(slot + minSlot, stack); } return false; } - private boolean checkSlot(int localSlot) - { + private boolean checkSlot(int localSlot) { return localSlot + minSlot < maxSlot; } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/forge/SlotItemHandler.java b/src/main/java/com/gtnewhorizons/modularui/api/forge/SlotItemHandler.java index ba447dc..1e62063 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/forge/SlotItemHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/forge/SlotItemHandler.java @@ -23,11 +23,11 @@ public SlotItemHandler(IItemHandler itemHandler, int index, int xPosition, int y } public boolean isItemValid(ItemStack stack) { - if (stack!=null && this.itemHandler.isItemValid(this.index, stack)) { + if (stack != null && this.itemHandler.isItemValid(this.index, stack)) { IItemHandler handler = this.getItemHandler(); ItemStack remainder; if (handler instanceof IItemHandlerModifiable) { - IItemHandlerModifiable handlerModifiable = (IItemHandlerModifiable)handler; + IItemHandlerModifiable handlerModifiable = (IItemHandlerModifiable) handler; ItemStack currentStack = handlerModifiable.getStackInSlot(this.index); handlerModifiable.setStackInSlot(this.index, null); remainder = handlerModifiable.insertItem(this.index, stack, true); @@ -47,12 +47,11 @@ public ItemStack getStack() { } public void putStack(ItemStack stack) { - ((IItemHandlerModifiable)this.getItemHandler()).setStackInSlot(this.index, stack); + ((IItemHandlerModifiable) this.getItemHandler()).setStackInSlot(this.index, stack); this.onSlotChanged(); } - public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_) { - } + public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_) {} public int getSlotStackLimit() { return this.itemHandler.getSlotLimit(this.index); @@ -65,7 +64,7 @@ public int getItemStackLimit(ItemStack stack) { IItemHandler handler = this.getItemHandler(); ItemStack currentStack = handler.getStackInSlot(this.index); if (handler instanceof IItemHandlerModifiable) { - IItemHandlerModifiable handlerModifiable = (IItemHandlerModifiable)handler; + IItemHandlerModifiable handlerModifiable = (IItemHandlerModifiable) handler; handlerModifiable.setStackInSlot(this.index, null); ItemStack remainder = handlerModifiable.insertItem(this.index, maxAdd, true); handlerModifiable.setStackInSlot(this.index, currentStack); @@ -92,7 +91,6 @@ public IItemHandler getItemHandler() { } public boolean isSameInventory(Slot other) { - return other instanceof SlotItemHandler && ((SlotItemHandler)other).getItemHandler() == this.itemHandler; + return other instanceof SlotItemHandler && ((SlotItemHandler) other).getItemHandler() == this.itemHandler; } } - diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/Alignment.java b/src/main/java/com/gtnewhorizons/modularui/api/math/Alignment.java index 8147586..dbad203 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/Alignment.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/Alignment.java @@ -4,25 +4,25 @@ public class Alignment { public final int x, y; - public static final Alignment TopLeft = new Alignment(-1, -1); - public static final Alignment TopCenter = new Alignment(0, -1); - public static final Alignment TopRight = new Alignment(1, -1); - public static final Alignment CenterLeft = new Alignment(-1, 0); - public static final Alignment Center = new Alignment(0, 0); - public static final Alignment CenterRight = new Alignment(1, 0); - public static final Alignment BottomLeft = new Alignment(-1, 1); - public static final Alignment BottomCenter = new Alignment(0, 1); - public static final Alignment BottomRight = new Alignment(1, 1); + public static final Alignment TopLeft = new Alignment(-1, -1); + public static final Alignment TopCenter = new Alignment(0, -1); + public static final Alignment TopRight = new Alignment(1, -1); + public static final Alignment CenterLeft = new Alignment(-1, 0); + public static final Alignment Center = new Alignment(0, 0); + public static final Alignment CenterRight = new Alignment(1, 0); + public static final Alignment BottomLeft = new Alignment(-1, 1); + public static final Alignment BottomCenter = new Alignment(0, 1); + public static final Alignment BottomRight = new Alignment(1, 1); public static final Alignment[] ALL = { - TopLeft, TopCenter, TopRight, - CenterLeft, Center, CenterRight, - BottomLeft, BottomCenter, BottomRight + TopLeft, TopCenter, TopRight, + CenterLeft, Center, CenterRight, + BottomLeft, BottomCenter, BottomRight }; public static final Alignment[] CORNERS = { - TopLeft, TopRight, - BottomLeft, BottomRight + TopLeft, TopRight, + BottomLeft, BottomRight }; public Alignment(int x, int y) { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/Color.java b/src/main/java/com/gtnewhorizons/modularui/api/math/Color.java index 1ff6c95..f3d22a7 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/Color.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/Color.java @@ -3,17 +3,15 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.GlStateManager; import com.gtnewhorizons.modularui.common.internal.JsonHelper; -import org.jetbrains.annotations.NotNull; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.util.MathHelper; - -import javax.annotation.Nullable; import java.util.Arrays; import java.util.Iterator; +import javax.annotation.Nullable; +import net.minecraft.util.MathHelper; +import org.jetbrains.annotations.NotNull; public class Color implements Iterable { @@ -200,7 +198,7 @@ public static float getAlphaF(int argb) { * @return rgba as an array [red, green, blue, alpha] */ public static int[] getValues(int argb) { - return new int[]{getRed(argb), getGreen(argb), getBlue(argb), getAlpha(argb)}; + return new int[] {getRed(argb), getGreen(argb), getBlue(argb), getAlpha(argb)}; } public static int rgbaToArgb(int rgba) { @@ -285,136 +283,198 @@ public static Integer ofJson(JsonElement jsonElement) { return null; } - public static final Color WHITE = new Color(0xFFFFFF, new int[]{}, - 0xF7F7F7, - 0xEFEFEF, - 0xE7E7E7, - 0xDFDFDF, - 0xD7D7D7, - 0xCFCFCF, - 0xC7C7C7, - 0xBFBFBF); - - public static final Color BLACK = new Color(0x000000, new int[]{ - 0x080808, - 0x101010, - 0x181818, - 0x202020, - 0x282828, - 0x303030, - 0x383838, - 0x404040 - }); - - // from here on color values are taken from https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/colors.dart - - public static final Color RED = new Color(0xF44336, - new int[]{0xEF5350, 0xE57373, 0xEF9A9A, 0xFFCDD2, 0xFFEBEE}, - 0xE53935, 0xD32F2F, 0xC62828, 0xB71C1C); - - public static final Color RED_ACCENT = new Color(0xFF5252, new int[]{0xFF8A80}, 0xFF1744, 0xD50000); - - public static final Color PINK = new Color(0xE91E63, - new int[]{0xEC407A, 0xF06292, 0xF48FB1, 0xF8BBD0, 0xFCE4EC}, - 0xD81B60, 0xC2185B, 0xAD1457, 0x880E4F); - - public static final Color PINK_ACCENT = new Color(0xFF4081, new int[]{0xFF80AB}, 0xF50057, 0xC51162); - - public static final Color PURPLE = new Color(0x9C27B0, - new int[]{0xAB47BC, 0xBA68C8, 0xCE93D8, 0xE1BEE7, 0xF3E5F5}, - 0x8E24AA, 0x7B1FA2, 0x6A1B9A, 0x4A148C); - - public static final Color PURPLE_ACCENT = new Color(0xE040FB, new int[]{0xEA80FC}, 0xD500F9, 0xAA00FF); - - public static final Color DEEP_PURPLE = new Color(0x673AB7, - new int[]{0x7E57C2, 0x9575CD, 0xB39DDB, 0xD1C4E9, 0xEDE7F6}, - 0x5E35B1, 0x512DA8, 0x4527A0, 0x311B92); - - public static final Color DEEP_PURPLE_ACCENT = new Color(0x7C4DFF, new int[]{0xB388FF}, 0x651FFF, 0x651FFF); - - public static final Color INDIGO = new Color(0x3F51B5, - new int[]{0x5C6BC0, 0x7986CB, 0x9FA8DA, 0xC5CAE9, 0xE8EAF6}, - 0x3949AB, 0x303F9F, 0x283593, 0x1A237E); - - public static final Color INDIGO_ACCENT = new Color(0x536DFE, new int[]{0x8C9EFF}, 0x3D5AFE, 0x304FFE); - - public static final Color BLUE = new Color(0x2196F3, - new int[]{0x42A5F5, 0x64B5F6, 0x90CAF9, 0xBBDEFB, 0xE3F2FD}, - 0x1E88E5, 0x1976D2, 0x1565C0, 0x0D47A1); - - public static final Color BLUE_ACCENT = new Color(0x448AFF, new int[]{0x82B1FF}, 0x2979FF, 0x2962FF); - - public static final Color LIGHT_BLUE = new Color(0x03A9F4, - new int[]{0x29B6F6, 0x4FC3F7, 0x81D4FA, 0xB3E5FC, 0xE1F5FE}, - 0x039BE5, 0x0288D1, 0x0277BD, 0x01579B); - - public static final Color LIGHT_BLUE_ACCENT = new Color(0x40C4FF, new int[]{0x80D8FF}, 0x00B0FF, 0x0091EA); - - public static final Color CYAN = new Color(0x00BCD4, - new int[]{0x26C6DA, 0x4DD0E1, 0x80DEEA, 0xB2EBF2, 0xE0F7FA}, - 0x00ACC1, 0x0097A7, 0x00838F, 0x006064); - - public static final Color CYAN_ACCENT = new Color(0x18FFFF, new int[]{0x84FFFF}, 0x00E5FF, 0x00B8D4); - - public static final Color TEAL = new Color(0x009688, - new int[]{0x26A69A, 0x4DB6AC, 0x80CBC4, 0xB2DFDB, 0xE0F2F1}, - 0x00897B, 0x00796B, 0x00695C, 0x004D40); - - public static final Color TEAL_ACCENT = new Color(0x64FFDA, new int[]{0xA7FFEB}, 0x1DE9B6, 0x00BFA5); - - public static final Color GREEN = new Color(0x4CAF50, - new int[]{0x66BB6A, 0x81C784, 0xA5D6A7, 0xC8E6C9, 0xE8F5E9}, - 0x43A047, 0x388E3C, 0x2E7D32, 0x1B5E20); - - public static final Color GREEN_ACCENT = new Color(0x69F0AE, new int[]{0xB9F6CA}, 0x00E676, 0x00C853); - - public static final Color LIGHT_GREEN = new Color(0x8BC34A, - new int[]{0x9CCC65, 0xAED581, 0xC5E1A5, 0xDCEDC8, 0xF1F8E9}, - 0x7CB342, 0x689F38, 0x558B2F, 0x33691E); - - public static final Color LIGHT_GREEN_ACCENT = new Color(0xB2FF59, new int[]{0xCCFF90}, 0x76FF03, 0x64DD17); - - public static final Color LIME = new Color(0xCDDC39, - new int[]{0xD4E157, 0xDCE775, 0xE6EE9C, 0xF0F4C3, 0xF9FBE7}, - 0xC0CA33, 0xAFB42B, 0x9E9D24, 0x827717); - - public static final Color LIME_ACCENT = new Color(0xEEFF41, new int[]{0xF4FF81}, 0xC6FF00, 0xAEEA00); - - public static final Color YELLOW = new Color(0xFFEB3B, - new int[]{0xFFEE58, 0xFFF176, 0xFFF59D, 0xFFF9C4, 0xFFFDE7}, - 0xFDD835, 0xFBC02D, 0xF9A825, 0xF57F17); - - public static final Color YELLOW_ACCENT = new Color(0xFFFF00, new int[]{0xFFFF8D}, 0xFFEA00, 0xFFD600); - - public static final Color AMBER = new Color(0xFFC107, - new int[]{0xFFCA28, 0xFFD54F, 0xFFE082, 0xFFECB3, 0xFFF8E1}, - 0xFFB300, 0xFFA000, 0xFF8F00, 0xFF6F00); - - public static final Color AMBER_ACCENT = new Color(0xFFD740, new int[]{0xFFE57F}, 0xFFC400, 0xFFAB00); - - public static final Color ORANGE = new Color(0xFF9800, - new int[]{0xFFA726, 0xFFB74D, 0xFFCC80, 0xFFE0B2, 0xFFFFF3E0}, - 0xFB8C00, 0xF57C00, 0xEF6C00, 0xE65100); - - public static final Color ORANGE_ACCENT = new Color(0xFFAB40, new int[]{0xFFD180}, 0xFF9100, 0xFF6D00); - - public static final Color DEEP_ORANGE = new Color(0xFF5722, - new int[]{0xFF7043, 0xFF8A65, 0xFFAB91, 0xFFCCBC, 0xFBE9E7}, - 0xF4511E, 0xE64A19, 0xD84315, 0xBF360C); - - public static final Color DEEP_ORANGE_ACCENT = new Color(0xFF6E40, new int[]{0xFF9E80}, 0xFF3D00, 0xDD2C00); - - public static final Color BROWN = new Color(0x795548, - new int[]{0x8D6E63, 0xA1887F, 0xBCAAA4, 0xD7CCC8, 0xEFEBE9}, - 0x6D4C41, 0x5D4037, 0x4E342E, 0x3E2723); - - public static final Color GREY = new Color(0x9E9E9E, - new int[]{0xBDBDBD, 0xE0E0E0, 0xEEEEEE, 0xF5F5F5, 0xFAFAFA}, - 0x757575, 0x616161, 0x424242, 0x212121); - - public static final Color BLUE_GREY = new Color(0x607D8B, - new int[]{0x78909C, 0x90A4AE, 0xB0BEC5, 0xCFD8DC, 0xECEFF1}, - 0x546E7A, 0x455A64, 0x37474F, 0x263238); + public static final Color WHITE = new Color( + 0xFFFFFF, new int[] {}, 0xF7F7F7, 0xEFEFEF, 0xE7E7E7, 0xDFDFDF, 0xD7D7D7, 0xCFCFCF, 0xC7C7C7, 0xBFBFBF); + + public static final Color BLACK = new Color( + 0x000000, new int[] {0x080808, 0x101010, 0x181818, 0x202020, 0x282828, 0x303030, 0x383838, 0x404040}); + + // from here on color values are taken from + // https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/colors.dart + + public static final Color RED = new Color( + 0xF44336, + new int[] {0xEF5350, 0xE57373, 0xEF9A9A, 0xFFCDD2, 0xFFEBEE}, + 0xE53935, + 0xD32F2F, + 0xC62828, + 0xB71C1C); + + public static final Color RED_ACCENT = new Color(0xFF5252, new int[] {0xFF8A80}, 0xFF1744, 0xD50000); + + public static final Color PINK = new Color( + 0xE91E63, + new int[] {0xEC407A, 0xF06292, 0xF48FB1, 0xF8BBD0, 0xFCE4EC}, + 0xD81B60, + 0xC2185B, + 0xAD1457, + 0x880E4F); + + public static final Color PINK_ACCENT = new Color(0xFF4081, new int[] {0xFF80AB}, 0xF50057, 0xC51162); + + public static final Color PURPLE = new Color( + 0x9C27B0, + new int[] {0xAB47BC, 0xBA68C8, 0xCE93D8, 0xE1BEE7, 0xF3E5F5}, + 0x8E24AA, + 0x7B1FA2, + 0x6A1B9A, + 0x4A148C); + + public static final Color PURPLE_ACCENT = new Color(0xE040FB, new int[] {0xEA80FC}, 0xD500F9, 0xAA00FF); + + public static final Color DEEP_PURPLE = new Color( + 0x673AB7, + new int[] {0x7E57C2, 0x9575CD, 0xB39DDB, 0xD1C4E9, 0xEDE7F6}, + 0x5E35B1, + 0x512DA8, + 0x4527A0, + 0x311B92); + + public static final Color DEEP_PURPLE_ACCENT = new Color(0x7C4DFF, new int[] {0xB388FF}, 0x651FFF, 0x651FFF); + + public static final Color INDIGO = new Color( + 0x3F51B5, + new int[] {0x5C6BC0, 0x7986CB, 0x9FA8DA, 0xC5CAE9, 0xE8EAF6}, + 0x3949AB, + 0x303F9F, + 0x283593, + 0x1A237E); + + public static final Color INDIGO_ACCENT = new Color(0x536DFE, new int[] {0x8C9EFF}, 0x3D5AFE, 0x304FFE); + + public static final Color BLUE = new Color( + 0x2196F3, + new int[] {0x42A5F5, 0x64B5F6, 0x90CAF9, 0xBBDEFB, 0xE3F2FD}, + 0x1E88E5, + 0x1976D2, + 0x1565C0, + 0x0D47A1); + + public static final Color BLUE_ACCENT = new Color(0x448AFF, new int[] {0x82B1FF}, 0x2979FF, 0x2962FF); + + public static final Color LIGHT_BLUE = new Color( + 0x03A9F4, + new int[] {0x29B6F6, 0x4FC3F7, 0x81D4FA, 0xB3E5FC, 0xE1F5FE}, + 0x039BE5, + 0x0288D1, + 0x0277BD, + 0x01579B); + + public static final Color LIGHT_BLUE_ACCENT = new Color(0x40C4FF, new int[] {0x80D8FF}, 0x00B0FF, 0x0091EA); + + public static final Color CYAN = new Color( + 0x00BCD4, + new int[] {0x26C6DA, 0x4DD0E1, 0x80DEEA, 0xB2EBF2, 0xE0F7FA}, + 0x00ACC1, + 0x0097A7, + 0x00838F, + 0x006064); + + public static final Color CYAN_ACCENT = new Color(0x18FFFF, new int[] {0x84FFFF}, 0x00E5FF, 0x00B8D4); + + public static final Color TEAL = new Color( + 0x009688, + new int[] {0x26A69A, 0x4DB6AC, 0x80CBC4, 0xB2DFDB, 0xE0F2F1}, + 0x00897B, + 0x00796B, + 0x00695C, + 0x004D40); + + public static final Color TEAL_ACCENT = new Color(0x64FFDA, new int[] {0xA7FFEB}, 0x1DE9B6, 0x00BFA5); + + public static final Color GREEN = new Color( + 0x4CAF50, + new int[] {0x66BB6A, 0x81C784, 0xA5D6A7, 0xC8E6C9, 0xE8F5E9}, + 0x43A047, + 0x388E3C, + 0x2E7D32, + 0x1B5E20); + + public static final Color GREEN_ACCENT = new Color(0x69F0AE, new int[] {0xB9F6CA}, 0x00E676, 0x00C853); + + public static final Color LIGHT_GREEN = new Color( + 0x8BC34A, + new int[] {0x9CCC65, 0xAED581, 0xC5E1A5, 0xDCEDC8, 0xF1F8E9}, + 0x7CB342, + 0x689F38, + 0x558B2F, + 0x33691E); + + public static final Color LIGHT_GREEN_ACCENT = new Color(0xB2FF59, new int[] {0xCCFF90}, 0x76FF03, 0x64DD17); + + public static final Color LIME = new Color( + 0xCDDC39, + new int[] {0xD4E157, 0xDCE775, 0xE6EE9C, 0xF0F4C3, 0xF9FBE7}, + 0xC0CA33, + 0xAFB42B, + 0x9E9D24, + 0x827717); + + public static final Color LIME_ACCENT = new Color(0xEEFF41, new int[] {0xF4FF81}, 0xC6FF00, 0xAEEA00); + + public static final Color YELLOW = new Color( + 0xFFEB3B, + new int[] {0xFFEE58, 0xFFF176, 0xFFF59D, 0xFFF9C4, 0xFFFDE7}, + 0xFDD835, + 0xFBC02D, + 0xF9A825, + 0xF57F17); + + public static final Color YELLOW_ACCENT = new Color(0xFFFF00, new int[] {0xFFFF8D}, 0xFFEA00, 0xFFD600); + + public static final Color AMBER = new Color( + 0xFFC107, + new int[] {0xFFCA28, 0xFFD54F, 0xFFE082, 0xFFECB3, 0xFFF8E1}, + 0xFFB300, + 0xFFA000, + 0xFF8F00, + 0xFF6F00); + + public static final Color AMBER_ACCENT = new Color(0xFFD740, new int[] {0xFFE57F}, 0xFFC400, 0xFFAB00); + + public static final Color ORANGE = new Color( + 0xFF9800, + new int[] {0xFFA726, 0xFFB74D, 0xFFCC80, 0xFFE0B2, 0xFFFFF3E0}, + 0xFB8C00, + 0xF57C00, + 0xEF6C00, + 0xE65100); + + public static final Color ORANGE_ACCENT = new Color(0xFFAB40, new int[] {0xFFD180}, 0xFF9100, 0xFF6D00); + + public static final Color DEEP_ORANGE = new Color( + 0xFF5722, + new int[] {0xFF7043, 0xFF8A65, 0xFFAB91, 0xFFCCBC, 0xFBE9E7}, + 0xF4511E, + 0xE64A19, + 0xD84315, + 0xBF360C); + + public static final Color DEEP_ORANGE_ACCENT = new Color(0xFF6E40, new int[] {0xFF9E80}, 0xFF3D00, 0xDD2C00); + + public static final Color BROWN = new Color( + 0x795548, + new int[] {0x8D6E63, 0xA1887F, 0xBCAAA4, 0xD7CCC8, 0xEFEBE9}, + 0x6D4C41, + 0x5D4037, + 0x4E342E, + 0x3E2723); + + public static final Color GREY = new Color( + 0x9E9E9E, + new int[] {0xBDBDBD, 0xE0E0E0, 0xEEEEEE, 0xF5F5F5, 0xFAFAFA}, + 0x757575, + 0x616161, + 0x424242, + 0x212121); + + public static final Color BLUE_GREY = new Color( + 0x607D8B, + new int[] {0x78909C, 0x90A4AE, 0xB0BEC5, 0xCFD8DC, 0xECEFF1}, + 0x546E7A, + 0x455A64, + 0x37474F, + 0x263238); public final int normal; private final int[] shadeBright; diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/CrossAxisAlignment.java b/src/main/java/com/gtnewhorizons/modularui/api/math/CrossAxisAlignment.java index 043aaf4..1893056 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/CrossAxisAlignment.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/CrossAxisAlignment.java @@ -1,5 +1,7 @@ package com.gtnewhorizons.modularui.api.math; public enum CrossAxisAlignment { - START, CENTER, END; + START, + CENTER, + END; } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/MainAxisAlignment.java b/src/main/java/com/gtnewhorizons/modularui/api/math/MainAxisAlignment.java index 499bb4c..fe21bb5 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/MainAxisAlignment.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/MainAxisAlignment.java @@ -1,5 +1,8 @@ package com.gtnewhorizons.modularui.api.math; public enum MainAxisAlignment { - START, CENTER, END, SPACE_BETWEEN; + START, + CENTER, + END, + SPACE_BETWEEN; } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/MathExpression.java b/src/main/java/com/gtnewhorizons/modularui/api/math/MathExpression.java index a83d77f..80c800f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/MathExpression.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/MathExpression.java @@ -1,7 +1,6 @@ package com.gtnewhorizons.modularui.api.math; import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; - import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; @@ -215,8 +214,12 @@ public static double parse(String num) { } public enum Operator { - - PLUS("+"), MINUS("-"), MULTIPLY("*"), DIVIDE("/"), MOD("%"), POWER("^"); + PLUS("+"), + MINUS("-"), + MULTIPLY("*"), + DIVIDE("/"), + MOD("%"), + POWER("^"); public final String sign; Operator(String sign) { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/Pos2d.java b/src/main/java/com/gtnewhorizons/modularui/api/math/Pos2d.java index 3f73e24..818e5e2 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/Pos2d.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/Pos2d.java @@ -3,9 +3,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.common.internal.JsonHelper; - import java.awt.*; import java.util.Objects; @@ -71,10 +69,7 @@ public static boolean isInside(int posX, int posY, Pos2d areaPos, Size size) { } public static boolean isInside(int posX, int posY, int areaX, int areaY, int width, int height) { - return posX >= areaX && - posX < areaX + width && - posY >= areaY && - posY < areaY + height; + return posX >= areaX && posX < areaX + width && posY >= areaY && posY < areaY + height; } public boolean isInside(Pos2d pos, Size size) { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/math/Size.java b/src/main/java/com/gtnewhorizons/modularui/api/math/Size.java index ddb0ea0..a2f9887 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/math/Size.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/math/Size.java @@ -3,9 +3,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.common.internal.JsonHelper; - import java.awt.*; import java.util.Objects; diff --git a/src/main/java/com/gtnewhorizons/modularui/api/nei/IGhostIngredientHandler.java b/src/main/java/com/gtnewhorizons/modularui/api/nei/IGhostIngredientHandler.java index b50b67a..a9a5c4f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/nei/IGhostIngredientHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/nei/IGhostIngredientHandler.java @@ -1,11 +1,10 @@ package com.gtnewhorizons.modularui.api.nei; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.item.ItemStack; - import java.awt.*; import java.util.List; import java.util.function.Consumer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.item.ItemStack; /** * Lets mods accept ghost ingredients from NEI. diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/Cursor.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/Cursor.java index da9b436..1e62861 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/Cursor.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/Cursor.java @@ -4,27 +4,30 @@ import com.gtnewhorizons.modularui.api.widget.IDraggable; import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Widget; -import net.minecraft.client.Minecraft; -import net.minecraft.item.ItemStack; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; public class Cursor { private final ModularUIContext uiContext; + @Nullable private IDraggable cursorDraggable; + @Nullable private Widget hovered; + @Nullable private Widget focused; + private final List hoveredWidgets = new ArrayList<>(); private int lastButton = -1; private long lastClickTime = 0; @@ -121,13 +124,14 @@ public void setItemStack(ItemStack stack, boolean sync) { if (stack != null) { uiContext.getPlayer().inventory.setItemStack(stack); if (sync && !uiContext.isClient()) { - uiContext.sendServerPacket(ModularUIContext.DataCodes.SYNC_CURSOR_STACK, null, uiContext.getMainWindow(), buffer -> { - try { - buffer.writeItemStackToBuffer(stack); - } catch (IOException e) { - e.printStackTrace(); - } - }); + uiContext.sendServerPacket( + ModularUIContext.DataCodes.SYNC_CURSOR_STACK, null, uiContext.getMainWindow(), buffer -> { + try { + buffer.writeItemStackToBuffer(stack); + } catch (IOException e) { + e.printStackTrace(); + } + }); } } } @@ -159,9 +163,9 @@ public void draw(float partialTicks) { @ApiStatus.Internal public void onScreenUpdate() { if (this.hovered != null) { -// if (hovered instanceof IVanillaSlot) { -// uiContext.getScreen().getAccessor().setHoveredSlot(((IVanillaSlot) hovered).getMcSlot()); -// } + // if (hovered instanceof IVanillaSlot) { + // uiContext.getScreen().getAccessor().setHoveredSlot(((IVanillaSlot) hovered).getMcSlot()); + // } this.timeHovered++; } if (this.cursorDraggable != null && getItemStack() != null) { @@ -211,7 +215,8 @@ public boolean onHoveredClick(int button, Object hovered) { if (hovered instanceof IDraggable) { draggable = (IDraggable) hovered; } else if (hovered instanceof ModularWindow && ((ModularWindow) hovered).isDraggable()) { - draggable = new DraggableWindowWrapper((ModularWindow) hovered, getPos().subtract(((ModularWindow) hovered).getPos())); + draggable = new DraggableWindowWrapper( + (ModularWindow) hovered, getPos().subtract(((ModularWindow) hovered).getPos())); } else { return false; } @@ -241,7 +246,11 @@ public IDraggable findDraggable() { if (!window.isEnabled()) continue; AtomicReference hovered = new AtomicReference<>(); IWidgetParent.forEachByLayer(window, true, widget -> { - if (widget instanceof IDraggable && (hovered.get() == null || widget.getLayer() > hovered.get().getLayer()) && isAbove(widget) && widget.canHover()) { + if (widget instanceof IDraggable + && (hovered.get() == null + || widget.getLayer() > hovered.get().getLayer()) + && isAbove(widget) + && widget.canHover()) { hovered.set(widget); } return false; @@ -276,7 +285,10 @@ public Widget findHoveredWidget(boolean forDebug) { public Widget findHoveredWidget(ModularWindow window, boolean forDebug) { AtomicReference hovered = new AtomicReference<>(); IWidgetParent.forEachByLayer(window, widget -> { - if ((hovered.get() == null || widget.getLayer() > hovered.get().getLayer()) && widget.isEnabled() && isAbove(widget) && (forDebug || widget.canHover())) { + if ((hovered.get() == null || widget.getLayer() > hovered.get().getLayer()) + && widget.isEnabled() + && isAbove(widget) + && (forDebug || widget.canHover())) { hovered.set(widget); } return false; @@ -321,7 +333,8 @@ private Widget findHoveredWidgets() { } } } - if (child instanceof IWidgetParent && (!((IWidgetParent) child).childrenMustBeInBounds() || above)) { + if (child instanceof IWidgetParent + && (!((IWidgetParent) child).childrenMustBeInBounds() || above)) { stack.addLast((IWidgetParent) child); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/DraggableWindowWrapper.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/DraggableWindowWrapper.java index 027c1d2..44a0bfd 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/DraggableWindowWrapper.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/DraggableWindowWrapper.java @@ -4,8 +4,8 @@ import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.widget.IDraggable; import com.gtnewhorizons.modularui.api.widget.Widget; -import org.jetbrains.annotations.Nullable; import java.awt.*; +import org.jetbrains.annotations.Nullable; public class DraggableWindowWrapper implements IDraggable { @@ -44,8 +44,7 @@ public void onDragEnd(boolean successful) { } @Override - public void onDrag(int mouseButton, long timeSinceLastClick) { - } + public void onDrag(int mouseButton, long timeSinceLastClick) {} @Override public boolean canDropHere(@Nullable Widget widget, boolean isInBounds) { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/IContainerCreator.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/IContainerCreator.java index 0444cd7..d546ac4 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/IContainerCreator.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/IContainerCreator.java @@ -8,5 +8,4 @@ public interface IContainerCreator { Container create(EntityPlayer player, World world, int x, int y, int z); - } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/IGuiCreator.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/IGuiCreator.java index a45473d..26a1e32 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/IGuiCreator.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/IGuiCreator.java @@ -10,5 +10,4 @@ public interface IGuiCreator { @SideOnly(Side.CLIENT) Object create(EntityPlayer player, World world, int x, int y, int z); - } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/IWindowCreator.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/IWindowCreator.java index b81b238..904548a 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/IWindowCreator.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/IWindowCreator.java @@ -5,5 +5,4 @@ public interface IWindowCreator { ModularWindow create(EntityPlayer player); - } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularUIContext.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularUIContext.java index 7ed57c1..1ea7680 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularUIContext.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularUIContext.java @@ -4,7 +4,10 @@ import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableMap; import com.gtnewhorizons.modularui.ModularUI; - +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; +import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.network.CWidgetUpdate; import com.gtnewhorizons.modularui.common.internal.network.NetworkHandler; import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; @@ -12,23 +15,18 @@ import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; -import com.gtnewhorizons.modularui.api.math.Pos2d; -import com.gtnewhorizons.modularui.api.math.Size; -import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; -import com.gtnewhorizons.modularui.api.widget.Widget; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.Unpooled; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.PacketBuffer; - import java.awt.*; import java.io.IOException; -import java.util.List; import java.util.*; +import java.util.List; import java.util.function.Consumer; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; public class ModularUIContext { @@ -37,8 +35,10 @@ public class ModularUIContext { private final BiMap syncedWindows = HashBiMap.create(4); private final Map lastWindowPos = new HashMap<>(); private ModularWindow mainWindow; + @SideOnly(Side.CLIENT) private ModularGui screen; + private final EntityPlayer player; private final com.gtnewhorizons.modularui.api.screen.Cursor cursor; private final List jeiExclusionZone = new ArrayList<>(); @@ -48,7 +48,9 @@ public class ModularUIContext { private final List closeListeners; private final boolean showJei; - private Size screenSize = NetworkUtils.isDedicatedClient() ? new Size(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight) : Size.ZERO; + private Size screenSize = NetworkUtils.isDedicatedClient() + ? new Size(Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight) + : Size.ZERO; private ModularUIContainer container; @@ -319,9 +321,9 @@ public void syncSlotContent(BaseSlot slot) { getContainer().sendSlotChange(slot.getStack(), slot.slotNumber); } -// public void syncHeldItem() { -// getContainer().sendHeldItemUpdate(); -// } + // public void syncHeldItem() { + // getContainer().sendHeldItemUpdate(); + // } public void readClientPacket(PacketBuffer buf, int widgetId) throws IOException { int id = buf.readVarIntFromBuffer(); @@ -363,7 +365,11 @@ public void readServerPacket(PacketBuffer buf, int widgetId) throws IOException } @SideOnly(Side.CLIENT) - public void sendClientPacket(int discriminator, ISyncedWidget syncedWidget, ModularWindow window, Consumer bufferConsumer) { + public void sendClientPacket( + int discriminator, + ISyncedWidget syncedWidget, + ModularWindow window, + Consumer bufferConsumer) { if (isClient() && !isClientOnly()) { if (!syncedWindows.containsValue(window)) { ModularUI.logger.error("Window is not synced!"); @@ -379,7 +385,11 @@ public void sendClientPacket(int discriminator, ISyncedWidget syncedWidget, Modu } } - public void sendServerPacket(int discriminator, ISyncedWidget syncedWidget, ModularWindow window, Consumer bufferConsumer) { + public void sendServerPacket( + int discriminator, + ISyncedWidget syncedWidget, + ModularWindow window, + Consumer bufferConsumer) { if (!isClient()) { if (!syncedWindows.containsValue(window)) { ModularUI.logger.error("Window is not synced!"); diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularWindow.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularWindow.java index d09722b..cc0833a 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularWindow.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/ModularWindow.java @@ -1,36 +1,35 @@ package com.gtnewhorizons.modularui.api.screen; -import com.gtnewhorizons.modularui.config.Config; -import com.gtnewhorizons.modularui.api.ModularUITextures; -import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; -import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; -import com.gtnewhorizons.modularui.api.widget.IWidgetParent; -import com.gtnewhorizons.modularui.api.widget.Interactable; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.internal.Theme; -import com.gtnewhorizons.modularui.api.math.Color; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableBiMap; import com.gtnewhorizons.modularui.api.GlStateManager; +import com.gtnewhorizons.modularui.api.ModularUITextures; import com.gtnewhorizons.modularui.api.animation.Eases; import com.gtnewhorizons.modularui.api.animation.Interpolator; import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.math.Alignment; +import com.gtnewhorizons.modularui.api.math.Color; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; +import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; +import com.gtnewhorizons.modularui.api.widget.IWidgetParent; +import com.gtnewhorizons.modularui.api.widget.Interactable; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.internal.Theme; import com.gtnewhorizons.modularui.common.widget.TextWidget; +import com.gtnewhorizons.modularui.config.Config; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.entity.player.EntityPlayer; - import java.awt.Rectangle; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; +import net.minecraft.entity.player.EntityPlayer; /** * A window in a modular gui. Only the "main" window can exist on both, server and client. @@ -77,7 +76,6 @@ public static Builder builderFullScreen() { private float scale = 1f; private float rotation = 0; private float translateX = 0, translateY = 0; - private Interpolator openAnimation, closeAnimation; public ModularWindow(Size size, List children, IDrawable... background) { @@ -125,11 +123,11 @@ public void onResize(Size screenSize) { } public static boolean anyAnimation() { - return Config.openCloseDurationMs > 0 && - (Config.openCloseFade || - Config.openCloseTranslateFromBottom || - Config.openCloseScale || - Config.openCloseRotateFast); + return Config.openCloseDurationMs > 0 + && (Config.openCloseFade + || Config.openCloseTranslateFromBottom + || Config.openCloseScale + || Config.openCloseRotateFast); } /** @@ -138,27 +136,33 @@ public static boolean anyAnimation() { public void onOpen() { if (openAnimation == null && anyAnimation()) { final int startY = context.getScaledScreenSize().height - pos.y; - openAnimation = new Interpolator(0, 1, Config.openCloseDurationMs, Eases.EaseQuadOut, value -> { - float val = (float) value; - if (Config.openCloseFade) { - alpha = (int) (val * Color.getAlpha(Theme.INSTANCE.getBackground())); - } - if (Config.openCloseTranslateFromBottom) { - translateY = startY * (1 - val); - } - if (Config.openCloseScale) { - scale = val; - } - if (Config.openCloseRotateFast) { - rotation = val * 360; - } - }, val -> { - alpha = Color.getAlpha(Theme.INSTANCE.getBackground()); - translateX = 0; - translateY = 0; - scale = 1f; - rotation = 360; - }); + openAnimation = new Interpolator( + 0, + 1, + Config.openCloseDurationMs, + Eases.EaseQuadOut, + value -> { + float val = (float) value; + if (Config.openCloseFade) { + alpha = (int) (val * Color.getAlpha(Theme.INSTANCE.getBackground())); + } + if (Config.openCloseTranslateFromBottom) { + translateY = startY * (1 - val); + } + if (Config.openCloseScale) { + scale = val; + } + if (Config.openCloseRotateFast) { + rotation = val * 360; + } + }, + val -> { + alpha = Color.getAlpha(Theme.INSTANCE.getBackground()); + translateX = 0; + translateY = 0; + scale = 1f; + rotation = 360; + }); closeAnimation = openAnimation.getReversed(Config.openCloseDurationMs, Eases.EaseQuadIn); openAnimation.forward(); closeAnimation.setCallback(val -> { @@ -167,7 +171,7 @@ public void onOpen() { closeAnimation = null; }); } - //this.pos = new Pos2d(pos.x, getContext().getScaledScreenSize().height); + // this.pos = new Pos2d(pos.x, getContext().getScaledScreenSize().height); } /** @@ -385,7 +389,8 @@ public List getInteractionListeners() { */ public void addDynamicSyncedWidget(int id, ISyncedWidget syncedWidget, ISyncedWidget parent) { if (id <= 0 || id > 0xFFFF) { - throw new IllegalArgumentException("Dynamic Synced widget id must be greater than 0 and smaller than 65535 (0xFFFF)"); + throw new IllegalArgumentException( + "Dynamic Synced widget id must be greater than 0 and smaller than 65535 (0xFFFF)"); } if (syncedWidget == null || parent == null) { throw new NullPointerException("Can't add dynamic null widget or with null parent!"); @@ -395,7 +400,8 @@ public void addDynamicSyncedWidget(int id, ISyncedWidget syncedWidget, ISyncedWi } int parentId = getSyncedWidgetId(parent); if ((parentId & ~0xFFFF) != 0) { - throw new IllegalStateException("Dynamic synced widgets can't have other dynamic widgets as parent! It's possible with some trickery tho."); + throw new IllegalStateException( + "Dynamic synced widgets can't have other dynamic widgets as parent! It's possible with some trickery tho."); } // generate unique id // first 2 bytes is passed id, last 2 bytes is parent id diff --git a/src/main/java/com/gtnewhorizons/modularui/api/screen/UIBuildContext.java b/src/main/java/com/gtnewhorizons/modularui/api/screen/UIBuildContext.java index 58e5e61..0d83f17 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/screen/UIBuildContext.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/screen/UIBuildContext.java @@ -2,13 +2,11 @@ import com.google.common.collect.ImmutableMap; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.widget.Widget; -import net.minecraft.entity.player.EntityPlayer; - -import javax.annotation.Nullable; import java.util.*; import java.util.function.Consumer; +import javax.annotation.Nullable; +import net.minecraft.entity.player.EntityPlayer; public class UIBuildContext { @@ -56,7 +54,8 @@ public void applyToWidget(String name, Class clazz, Consum if (t != null) { consumer.accept(t); } else { - ModularUI.logger.error("Expected Widget with name {}, of class {}, but was not found!", name, clazz.getName()); + ModularUI.logger.error( + "Expected Widget with name {}, of class {}, but was not found!", name, clazz.getName()); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/IDraggable.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/IDraggable.java index 1d0c2ee..04ab1ab 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/IDraggable.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/IDraggable.java @@ -1,10 +1,9 @@ package com.gtnewhorizons.modularui.api.widget; +import java.awt.*; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.awt.*; - @ApiStatus.Experimental public interface IDraggable { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/ISyncedWidget.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/ISyncedWidget.java index 2a8abb2..1ca429b 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/ISyncedWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/ISyncedWidget.java @@ -3,10 +3,9 @@ import com.gtnewhorizons.modularui.api.screen.ModularWindow; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.network.PacketBuffer; - import java.io.IOException; import java.util.function.Consumer; +import net.minecraft.network.PacketBuffer; /** * Implement this to let them synchronize data between server and client. @@ -24,8 +23,7 @@ public interface ISyncedWidget { * * @param init true if it is called the first time after init */ - default void detectAndSendChanges(boolean init) { - } + default void detectAndSendChanges(boolean init) {} /** * Sends the written data to {@link #readOnServer(int, PacketBuffer)} diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/IVanillaSlot.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/IVanillaSlot.java index f004132..2431e3e 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/IVanillaSlot.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/IVanillaSlot.java @@ -1,7 +1,6 @@ package com.gtnewhorizons.modularui.api.widget; import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; - import java.util.Collections; import java.util.List; diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetBuilder.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetBuilder.java index 3d882a8..0f5636a 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetBuilder.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetBuilder.java @@ -2,7 +2,6 @@ import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; @@ -11,12 +10,11 @@ import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; import com.gtnewhorizons.modularui.common.widget.SlotGroup; import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import org.jetbrains.annotations.ApiStatus; -import java.util.Collection; - public interface IWidgetBuilder> { @ApiStatus.Internal diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetParent.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetParent.java index caa2c96..705402e 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetParent.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/IWidgetParent.java @@ -5,12 +5,11 @@ import com.gtnewhorizons.modularui.api.screen.ModularUIContext; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import org.jetbrains.annotations.Unmodifiable; - import java.util.LinkedList; import java.util.List; import java.util.function.Consumer; import java.util.function.Function; +import org.jetbrains.annotations.Unmodifiable; /** * "Parent" widget that can contain another widgets as children. @@ -31,15 +30,13 @@ public interface IWidgetParent { /** * Called right after the ui is created and right before synced widgets are registered. Last chance to add sub widgets */ - default void initChildren() { - } + default void initChildren() {} /** * Called during rebuild. * {@link Widget#isAutoPositioned()} must be checked for each child!!! */ - default void layoutChildren(int maxWidth, int maxHeight) { - } + default void layoutChildren(int maxWidth, int maxHeight) {} @SideOnly(Side.CLIENT) default void drawChildren(float partialTicks) { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/Interactable.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/Interactable.java index 5fd199b..0e8dc0f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/Interactable.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/Interactable.java @@ -46,8 +46,7 @@ default boolean onClickReleased(int buttonId) { * @param deltaTime milliseconds since last mouse event */ @ApiStatus.OverrideOnly - default void onMouseDragged(int buttonId, long deltaTime) { - } + default void onMouseDragged(int buttonId, long deltaTime) {} /** * Called the mouse wheel moved @@ -88,13 +87,13 @@ static boolean hasShiftDown() { } // todo resurrect this -// /** -// * @return if alt or alt gr is pressed -// */ -// @SideOnly(Side.CLIENT) -// static boolean hasAltDown() { -// return GuiScreen.isAltKeyDown(); -// } + // /** + // * @return if alt or alt gr is pressed + // */ + // @SideOnly(Side.CLIENT) + // static boolean hasAltDown() { + // return GuiScreen.isAltKeyDown(); + // } /** * @param key key id, see {@link Keyboard} @@ -110,7 +109,9 @@ static boolean isKeyPressed(int key) { */ @SideOnly(Side.CLIENT) static void playButtonClickSound() { - Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + Minecraft.getMinecraft() + .getSoundHandler() + .playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); } enum ClickResult { diff --git a/src/main/java/com/gtnewhorizons/modularui/api/widget/Widget.java b/src/main/java/com/gtnewhorizons/modularui/api/widget/Widget.java index 4bf9083..55bd28c 100644 --- a/src/main/java/com/gtnewhorizons/modularui/api/widget/Widget.java +++ b/src/main/java/com/gtnewhorizons/modularui/api/widget/Widget.java @@ -12,16 +12,15 @@ import com.gtnewhorizons.modularui.common.internal.Theme; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.network.PacketBuffer; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import java.awt.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import net.minecraft.network.PacketBuffer; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * This class draws a functional element of ModularUI @@ -38,10 +37,13 @@ public abstract class Widget { protected Pos2d relativePos = Pos2d.ZERO; protected Pos2d pos = Pos2d.ZERO; protected Pos2d fixedPos = null; + @Nullable private SizeProvider sizeProvider; + @Nullable private PosProvider posProvider; + private boolean fillParent = false; private boolean autoSized = true; private boolean autoPositioned = true; @@ -56,17 +58,18 @@ public abstract class Widget { // visuals @Nullable private IDrawable[] background; + private final List additionalTooltip = new ArrayList<>(); private final List mainTooltip = new ArrayList<>(); private int tooltipShowUpDelay = 0; + @Nullable private String debugLabel; @Nullable private Consumer ticker; - public Widget() { - } + public Widget() {} public Widget(Size size) { this(); @@ -111,8 +114,7 @@ public void readJson(JsonObject json, String type) { } } - - //==== Internal methods ==== + // ==== Internal methods ==== /** * You shall not call this @@ -184,7 +186,8 @@ public final void buildBottomToTop() { pos = fixedPos; } else { if (this.posProvider != null) { - this.relativePos = this.posProvider.getPos(getContext().getScaledScreenSize(), getWindow(), this.parent); + this.relativePos = + this.posProvider.getPos(getContext().getScaledScreenSize(), getWindow(), this.parent); } this.pos = this.parent.getAbsolutePos().add(this.relativePos); } @@ -239,8 +242,7 @@ public final void drawInternal(float partialTicks, boolean ignoreEnabled) { } } - - //==== Sizing & Positioning ==== + // ==== Sizing & Positioning ==== /** * Called before this widget ask for the children Size. @@ -248,8 +250,7 @@ public final void drawInternal(float partialTicks, boolean ignoreEnabled) { * @param constraints constraints to modify */ @SideOnly(Side.CLIENT) - protected void modifyConstraints(Dimension constraints) { - } + protected void modifyConstraints(Dimension constraints) {} /** * Called during rebuild @@ -268,16 +269,14 @@ protected void modifyConstraints(Dimension constraints) { */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void onRebuild() { - } + public void onRebuild() {} /** * Called the first time this widget is fully build */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void onFirstRebuild() { - } + public void onFirstRebuild() {} /** * Causes the modular ui to re-layout all children next screen update @@ -288,27 +287,23 @@ public void checkNeedsRebuild() { } } - - //==== Update ==== + // ==== Update ==== /** * Called once per tick */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void onScreenUpdate() { - } + public void onScreenUpdate() {} /** * Called each frame, approximately 60 times per second */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void onFrameUpdate() { - } + public void onFrameUpdate() {} - - //==== Rendering ==== + // ==== Rendering ==== @SideOnly(Side.CLIENT) public void drawBackground(float partialTicks) { @@ -331,8 +326,7 @@ public void drawBackground(float partialTicks) { */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void draw(float partialTicks) { - } + public void draw(float partialTicks) {} /** * Is called after all widgets of the window are drawn. Can be used for special tooltip rendering. @@ -341,8 +335,7 @@ public void draw(float partialTicks) { */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void drawInForeground(float partialTicks) { - } + public void drawInForeground(float partialTicks) {} /** * Called after {@link #notifyTooltipChange()} is called. Result list is cached @@ -351,8 +344,7 @@ public void drawInForeground(float partialTicks) { */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void buildTooltip(List tooltip) { - } + public void buildTooltip(List tooltip) {} /** * @return the color key for the background @@ -364,47 +356,40 @@ public String getBackgroundColorKey() { return Theme.KEY_BACKGROUND; } - - //==== Lifecycle ==== + // ==== Lifecycle ==== /** * Called once when the window opens, before children get initialised. */ @ApiStatus.OverrideOnly - public void onInit() { - } + public void onInit() {} /** * Called once when the window opens, after children get initialised. */ @ApiStatus.OverrideOnly - public void onPostInit() { - } + public void onPostInit() {} /** * Called when another window opens over the current one * or when this window is active and it closes */ @ApiStatus.OverrideOnly - public void onPause() { - } + public void onPause() {} /** * Called when this window becomes active after being paused */ @ApiStatus.OverrideOnly - public void onResume() { - } + public void onResume() {} /** * Called when this window closes */ @ApiStatus.OverrideOnly - public void onDestroy() { - } + public void onDestroy() {} - - //==== focus ==== + // ==== focus ==== /** * Called when this widget is clicked. Also acts as a onReceiveFocus method. @@ -422,8 +407,7 @@ public boolean shouldGetFocus() { */ @ApiStatus.OverrideOnly @SideOnly(Side.CLIENT) - public void onRemoveFocus() { - } + public void onRemoveFocus() {} /** * @return if the modular ui currently has this widget focused @@ -459,8 +443,7 @@ public boolean isRightBelowMouse() { return getContext().getCursor().isRightBelow(this); } - - //==== Debug ==== + // ==== Debug ==== @Override public String toString() { @@ -473,8 +456,7 @@ public String toString() { return getClass().getSimpleName() + "#" + name + "#" + debugLabel; } - - //==== Getter ==== + // ==== Getter ==== public boolean isUnderMouse(Pos2d mousePos) { return mousePos.isInside(pos, size); @@ -587,18 +569,17 @@ public Consumer getTicker() { } public boolean intersects(Widget widget) { - return !(widget.getAbsolutePos().x > getAbsolutePos().x + getSize().width || - widget.getAbsolutePos().x + widget.getSize().width < getAbsolutePos().x || - widget.getAbsolutePos().y > getAbsolutePos().y + getSize().height || - widget.getAbsolutePos().y + widget.getSize().height < getAbsolutePos().y); + return !(widget.getAbsolutePos().x > getAbsolutePos().x + getSize().width + || widget.getAbsolutePos().x + widget.getSize().width < getAbsolutePos().x + || widget.getAbsolutePos().y > getAbsolutePos().y + getSize().height + || widget.getAbsolutePos().y + widget.getSize().height < getAbsolutePos().y); } public Rectangle getRectangle() { return new Rectangle(pos.x, pos.y, size.width, size.height); } - - //==== Setter/Builder ==== + // ==== Setter/Builder ==== /** * If widgets are NOT enabled, they won't be rendered and they can not be interacted with. @@ -769,8 +750,7 @@ public Widget respectAreaInNEI() { return this; } - - //==== Utility ==== + // ==== Utility ==== public interface SizeProvider { Size getSize(Size screenSize, ModularWindow window, IWidgetParent parent); @@ -785,14 +765,14 @@ public static class ClickData { public final boolean doubleClick; public final boolean shift; public final boolean ctrl; -// public final boolean alt; + // public final boolean alt; public ClickData(int mouseButton, boolean doubleClick, boolean shift, boolean ctrl) { this.mouseButton = mouseButton; this.doubleClick = doubleClick; this.shift = shift; this.ctrl = ctrl; -// this.alt = alt; + // this.alt = alt; } public void writeToPacket(PacketBuffer buffer) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/builder/UIBuilder.java b/src/main/java/com/gtnewhorizons/modularui/common/builder/UIBuilder.java index 40f5bf2..0243610 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/builder/UIBuilder.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/builder/UIBuilder.java @@ -18,9 +18,7 @@ public static UIBuilder of() { private IContainerCreator containerCreator = DUMMY_CONTAINER_CREATOR; private IGuiCreator guiCreator = DUMMY_GUI_CREATOR; - private UIBuilder() { - - } + private UIBuilder() {} public UIBuilder container(IContainerCreator containerCreator) { this.containerCreator = containerCreator; @@ -35,5 +33,4 @@ public UIBuilder gui(IGuiCreator guiCreator) { public UIInfo build() { return new UIInfo<>(this.containerCreator, this.guiCreator); } - } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/builder/UIInfo.java b/src/main/java/com/gtnewhorizons/modularui/common/builder/UIInfo.java index 0076ab3..f54d9c2 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/builder/UIInfo.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/builder/UIInfo.java @@ -1,19 +1,17 @@ package com.gtnewhorizons.modularui.common.builder; -import com.gtnewhorizons.modularui.api.UIInfos; -import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import com.gtnewhorizons.modularui.ModularUI; - +import com.gtnewhorizons.modularui.api.UIInfos; import com.gtnewhorizons.modularui.api.screen.IContainerCreator; import com.gtnewhorizons.modularui.api.screen.IGuiCreator; import com.gtnewhorizons.modularui.common.internal.InternalUIMapper; +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import java.util.function.Function; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.Vec3; import net.minecraft.world.World; -import java.util.function.Function; - /** * Responsible for registering actual Container and GuiContainer, and opening them. */ @@ -51,11 +49,10 @@ public void open(EntityPlayer player, World world, int x, int y, int z) { * For client-only GUI, use {@link UIInfos#openClientUI(EntityPlayer, Function)} */ public void open(EntityPlayer player, World world, Vec3 pos) { - open(player, world, (int)pos.xCoord, (int)pos.yCoord, (int)pos.zCoord); + open(player, world, (int) pos.xCoord, (int) pos.yCoord, (int) pos.zCoord); } public void open(EntityPlayer player) { open(player, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ); } - } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/InternalUIMapper.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/InternalUIMapper.java index ceebbfa..05dba07 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/InternalUIMapper.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/InternalUIMapper.java @@ -7,14 +7,13 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; - public class InternalUIMapper implements IGuiHandler { private static InternalUIMapper INSTANCE; @@ -61,5 +60,4 @@ public Object getClientGuiElement(int id, EntityPlayer player, World world, int } return screen; } - } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonHelper.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonHelper.java index c4ad5a2..2b0f469 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonHelper.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonHelper.java @@ -7,7 +7,6 @@ import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.widget.WidgetJsonRegistry; - import java.util.function.Function; public class JsonHelper { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonLoader.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonLoader.java index 3228913..ae47324 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonLoader.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/JsonLoader.java @@ -2,13 +2,9 @@ import com.google.gson.*; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.forge.CraftingHelper; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; -import net.minecraft.util.ResourceLocation; -//import net.minecraftforge.common.crafting.CraftingHelper; - import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -18,6 +14,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.minecraft.util.ResourceLocation; public class JsonLoader { @@ -30,7 +27,10 @@ public static void loadJson() { List mods = Loader.instance().getActiveModList(); mods.forEach((mod) -> { String id = mod.getModId(); - CraftingHelper.findFiles(mod, String.format("assets/%s/guis", id), (path) -> Files.exists(path), + CraftingHelper.findFiles( + mod, + String.format("assets/%s/guis", id), + (path) -> Files.exists(path), (path, file) -> { if (file.toString().endsWith(".json")) { JsonObject json = tryExtractFromFile(file); @@ -43,7 +43,9 @@ public static void loadJson() { } } return true; - }, false, true); + }, + false, + true); }); ModularUI.logger.info("Loaded {} guis from json", GUIS.size()); } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/Theme.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/Theme.java index 0f4e74a..91d308a 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/Theme.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/Theme.java @@ -1,14 +1,10 @@ package com.gtnewhorizons.modularui.common.internal; +import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; import com.gtnewhorizons.modularui.api.math.Color; -import com.google.gson.JsonObject; - -//import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; -//import it.unimi.dsi.fastutil.objects.Object2IntMap; -import org.jetbrains.annotations.Nullable; - import java.util.HashMap; +import org.jetbrains.annotations.Nullable; public class Theme { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/CWidgetUpdate.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/CWidgetUpdate.java index f777272..f67fee7 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/CWidgetUpdate.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/CWidgetUpdate.java @@ -1,15 +1,13 @@ package com.gtnewhorizons.modularui.common.internal.network; import com.gtnewhorizons.modularui.ModularUI; -import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; - import com.gtnewhorizons.modularui.api.screen.ModularUIContext; +import com.gtnewhorizons.modularui.common.internal.wrapper.ModularUIContainer; +import java.io.IOException; import net.minecraft.inventory.Container; import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.PacketBuffer; -import java.io.IOException; - public class CWidgetUpdate implements IPacket { public int widgetId; @@ -20,8 +18,7 @@ public CWidgetUpdate(PacketBuffer packet, int widgetId) { this.widgetId = widgetId; } - public CWidgetUpdate() { - } + public CWidgetUpdate() {} @Override public void decode(PacketBuffer buf) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkHandler.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkHandler.java index 713426a..691471e 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkHandler.java @@ -43,12 +43,12 @@ public static void sendToPlayer(IPacket packet, EntityPlayerMP player) { network.sendTo(packet, player); } - final static IMessageHandler S2CHandler = (message, ctx) -> { + static final IMessageHandler S2CHandler = (message, ctx) -> { NetHandlerPlayClient handler = ctx.getClientHandler(); return message.executeClient(handler); }; - final static IMessageHandler C2SHandler = (message, ctx) -> { + static final IMessageHandler C2SHandler = (message, ctx) -> { NetHandlerPlayServer handler = ctx.getServerHandler(); return message.executeServer(handler); }; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkUtils.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkUtils.java index d2c1cbd..8c5d759 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkUtils.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/NetworkUtils.java @@ -1,10 +1,12 @@ package com.gtnewhorizons.modularui.common.internal.network; import com.gtnewhorizons.modularui.ModularUI; - import cpw.mods.fml.common.FMLCommonHandler; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.function.Consumer; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -12,14 +14,9 @@ import net.minecraftforge.fluids.FluidStack; import org.jetbrains.annotations.Nullable; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.function.Consumer; - public class NetworkUtils { - public static final Consumer EMPTY_PACKET = buffer -> { - }; + public static final Consumer EMPTY_PACKET = buffer -> {}; public static boolean isDedicatedClient() { return FMLCommonHandler.instance().getSide().isClient(); @@ -48,10 +45,9 @@ public static void writeFluidStack(PacketBuffer buffer, @Nullable FluidStack flu } else { buffer.writeBoolean(false); NBTTagCompound fluidStackTag = fluidStack.writeToNBT(new NBTTagCompound()); - try{ + try { buffer.writeNBTTagCompoundToBuffer(fluidStackTag); - } - catch(IOException e){ + } catch (IOException e) { } } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/SWidgetUpdate.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/SWidgetUpdate.java index 1bc8e1c..8ae37e4 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/network/SWidgetUpdate.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/network/SWidgetUpdate.java @@ -3,14 +3,12 @@ import com.gtnewhorizons.modularui.ModularUI; import com.gtnewhorizons.modularui.api.screen.ModularUIContext; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; - +import java.io.IOException; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.PacketBuffer; -import java.io.IOException; - public class SWidgetUpdate implements IPacket { public int widgetId; @@ -21,8 +19,7 @@ public SWidgetUpdate(PacketBuffer packet, int widgetId) { this.widgetId = widgetId; } - public SWidgetUpdate() { - } + public SWidgetUpdate() {} @Override public void decode(PacketBuffer buf) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/BaseSlot.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/BaseSlot.java index 34e167b..65763ad 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/BaseSlot.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/BaseSlot.java @@ -3,13 +3,12 @@ import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; import com.gtnewhorizons.modularui.api.forge.SlotItemHandler; +import java.util.function.Predicate; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import org.jetbrains.annotations.NotNull; -import java.util.function.Predicate; - public class BaseSlot extends SlotItemHandler { protected final boolean phantom; @@ -40,9 +39,9 @@ public BaseSlot(IItemHandlerModifiable inventory, int index) { public BaseSlot(IItemHandlerModifiable inventory, int index, boolean phantom) { super(inventory, index, 0, 0); this.phantom = phantom; -// if (inventory instanceof PlayerMainInvWrapper) { -// setShiftClickPriority(index > 8 ? 40 : 20); -// } + // if (inventory instanceof PlayerMainInvWrapper) { + // setShiftClickPriority(index > 8 ? 40 : 20); + // } if (this.phantom) { this.shiftClickPriority += 10; } @@ -74,7 +73,9 @@ public boolean isItemValid(@NotNull ItemStack stack) { } public boolean isItemValidPhantom(ItemStack stack) { - return this.canInsert && (filter == null || filter.test(stack)) && getItemHandler().isItemValid(getSlotIndex(), stack); + return this.canInsert + && (filter == null || filter.test(stack)) + && getItemHandler().isItemValid(getSlotIndex(), stack); } @Override @@ -143,17 +144,17 @@ public ResourceLocation getBackgroundIconTexture() { return null; } -// @Nullable -// @Override -// public String getSlotTexture() { -// return null; -// } -// -// @Nullable -// @Override -// public TextureAtlasSprite getBackgroundSprite() { -// return null; -// } + // @Nullable + // @Override + // public String getSlotTexture() { + // return null; + // } + // + // @Nullable + // @Override + // public TextureAtlasSprite getBackgroundSprite() { + // return null; + // } public void incrementStackCount(int amount) { ItemStack stack = getStack(); diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/FluidTankHandler.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/FluidTankHandler.java index 401bf44..5e12e91 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/FluidTankHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/FluidTankHandler.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.modularui.common.internal.wrapper; +import javax.annotation.Nullable; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; @@ -7,8 +8,6 @@ import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidTank; -import javax.annotation.Nullable; - public class FluidTankHandler implements IFluidHandler { public static IFluidHandler getTankFluidHandler(IFluidTank tank) { @@ -26,9 +25,7 @@ public FluidTankHandler(IFluidTank tank) { @Override public FluidTankInfo[] getTankInfo(ForgeDirection from) { - return new FluidTankInfo[]{ - fluidTank.getInfo() - }; + return new FluidTankInfo[] {fluidTank.getInfo()}; } @Override diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/GhostIngredientWrapper.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/GhostIngredientWrapper.java index ac7e01e..37a17ea 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/GhostIngredientWrapper.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/GhostIngredientWrapper.java @@ -4,12 +4,12 @@ import com.gtnewhorizons.modularui.api.nei.IGhostIngredientHandler; import com.gtnewhorizons.modularui.api.widget.IGhostIngredientTarget; import com.gtnewhorizons.modularui.api.widget.Widget; +import java.awt.*; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.NotNull; -import java.awt.*; - -public class GhostIngredientWrapper implements IGhostIngredientHandler.Target { +public class GhostIngredientWrapper + implements IGhostIngredientHandler.Target { private final W widget; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularGui.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularGui.java index 1bca11c..b7c6f6c 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularGui.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularGui.java @@ -1,6 +1,7 @@ package com.gtnewhorizons.modularui.common.internal.wrapper; -import com.gtnewhorizons.modularui.config.Config; +import static codechicken.lib.render.FontUtils.fontRenderer; + import com.gtnewhorizons.modularui.api.GlStateManager; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.math.Color; @@ -13,9 +14,14 @@ import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Interactable; import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.config.Config; import com.gtnewhorizons.modularui.mixins.GuiContainerMixin; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; @@ -31,13 +37,6 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Keyboard; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import static codechicken.lib.render.FontUtils.fontRenderer; - @SideOnly(Side.CLIENT) public class ModularGui extends GuiContainer { @@ -46,6 +45,7 @@ public class ModularGui extends GuiContainer { @Nullable private Interactable lastClicked; + private long lastClick = -1; private long lastFocusedClick = -1; private int drawCalls = 0; @@ -72,11 +72,11 @@ public Pos2d getMousePos() { return mousePos; } -// @Override -// public void onResize(@NotNull Minecraft mc, int w, int h) { -// super.onResize(mc, w, h); -// context.resize(new Size(w, h)); -// } + // @Override + // public void onResize(@NotNull Minecraft mc, int w, int h) { + // super.onResize(mc, w, h); + // context.resize(new Size(w, h)); + // } public void setMainWindowArea(Pos2d pos, Size size) { this.guiLeft = pos.x; @@ -128,11 +128,13 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.pushMatrix(); GlStateManager.translate(i, j, 0); -// MinecraftForge.EVENT_BUS.post(new GuiContainerEvent.DrawForeground(this, mouseX, mouseY)); + // MinecraftForge.EVENT_BUS.post(new GuiContainerEvent.DrawForeground(this, mouseX, mouseY)); GlStateManager.popMatrix(); InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory; - ItemStack itemstack = getAccessor().getDraggedStack() == null ? inventoryplayer.getItemStack() : getAccessor().getDraggedStack(); + ItemStack itemstack = getAccessor().getDraggedStack() == null + ? inventoryplayer.getItemStack() + : getAccessor().getDraggedStack(); GlStateManager.translate((float) i, (float) j, 0.0F); if (itemstack != null) { int k2 = getAccessor().getDraggedStack() == null ? 8 : 16; @@ -140,7 +142,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { if (getAccessor().getDraggedStack() != null && getAccessor().getIsRightMouseClick()) { itemstack = itemstack.copy(); - itemstack.stackSize = (int)Math.ceil((float) itemstack.stackSize / 2.0F); + itemstack.stackSize = (int) Math.ceil((float) itemstack.stackSize / 2.0F); } else if (this.isDragSplitting2() && this.getDragSlots().size() > 1) { itemstack = itemstack.copy(); itemstack.stackSize = getAccessor().getDragSplittingRemnant(); @@ -161,8 +163,10 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) { getAccessor().setReturningStack(null); } - int l2 = getAccessor().getReturningStackDestSlot().xDisplayPosition - getAccessor().getTouchUpX(); - int i3 = getAccessor().getReturningStackDestSlot().yDisplayPosition - getAccessor().getTouchUpY(); + int l2 = getAccessor().getReturningStackDestSlot().xDisplayPosition + - getAccessor().getTouchUpX(); + int i3 = getAccessor().getReturningStackDestSlot().yDisplayPosition + - getAccessor().getTouchUpY(); int l1 = getAccessor().getTouchUpX() + (int) ((float) l2 * f); int i2 = getAccessor().getTouchUpY() + (int) ((float) i3 * f); this.drawItemStack(getAccessor().getReturningStack(), l1, i2, null); @@ -190,7 +194,8 @@ private void drawItemStack(ItemStack stack, int x, int y, String altText) { FontRenderer font = stack.getItem().getFontRenderer(stack); if (font == null) font = fontRenderer; itemRender.renderItemAndEffectIntoGUI(font, mc.getTextureManager(), stack, x, y); - itemRender.renderItemOverlayIntoGUI(font, mc.getTextureManager(), stack, x, y - (getDragSlots() != null ? 0 : 8), altText); + itemRender.renderItemOverlayIntoGUI( + font, mc.getTextureManager(), stack, x, y - (getDragSlots() != null ? 0 : 8), altText); this.zLevel = 0.0F; itemRender.zLevel = 0.0F; } @@ -240,12 +245,21 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { Widget hovered = context.getCursor().getHovered(); if (hovered != null && !context.getCursor().isHoldingSomething()) { - if (hovered instanceof IVanillaSlot && ((IVanillaSlot) hovered).getMcSlot().getHasStack()) { - renderToolTip(((IVanillaSlot) hovered).getMcSlot().getStack(), mouseX, mouseY, ((IVanillaSlot) hovered).getExtraTooltip()); + if (hovered instanceof IVanillaSlot + && ((IVanillaSlot) hovered).getMcSlot().getHasStack()) { + renderToolTip( + ((IVanillaSlot) hovered).getMcSlot().getStack(), + mouseX, + mouseY, + ((IVanillaSlot) hovered).getExtraTooltip()); } else if (hovered.getTooltipShowUpDelay() <= context.getCursor().getTimeHovered()) { List tooltip = hovered.getTooltip(); if (!tooltip.isEmpty()) { - renderToolTip(null, context.getMousePos().x, context.getMousePos().y, tooltip.stream().map(line -> line.getFormatted()).collect(Collectors.toList())); + renderToolTip( + null, + context.getMousePos().x, + context.getMousePos().y, + tooltip.stream().map(line -> line.getFormatted()).collect(Collectors.toList())); } } } @@ -276,12 +290,24 @@ public void drawDebugScreen() { IWidgetParent parent = hovered.getParent(); drawBorder(pos.x, pos.y, size.width, size.height, color, 1f); - drawBorder(parent.getAbsolutePos().x, parent.getAbsolutePos().y, parent.getSize().width, parent.getSize().height, Color.withAlpha(color, 0.3f), 1f); + drawBorder( + parent.getAbsolutePos().x, + parent.getAbsolutePos().y, + parent.getSize().width, + parent.getSize().height, + Color.withAlpha(color, 0.3f), + 1f); drawText("Pos: " + hovered.getPos(), 5, lineY, 1, color, false); lineY -= 11; drawText("Size: " + size, 5, lineY, 1, color, false); lineY -= 11; - drawText("Parent: " + (parent instanceof ModularWindow ? "ModularWindow" : parent.toString()), 5, lineY, 1, color, false); + drawText( + "Parent: " + (parent instanceof ModularWindow ? "ModularWindow" : parent.toString()), + 5, + lineY, + 1, + color, + false); lineY -= 11; drawText("Class: " + hovered, 5, lineY, 1, color, false); } @@ -299,7 +325,7 @@ public void drawDebugScreen() { protected void renderToolTip(ItemStack stack, int x, int y, List extraLines) { FontRenderer font = null; List lines = new ArrayList(); - if(stack != null){ + if (stack != null) { font = stack.getItem().getFontRenderer(stack); lines.addAll(stack.getTooltip(context.getPlayer(), this.mc.gameSettings.advancedItemTooltips)); } @@ -309,10 +335,10 @@ protected void renderToolTip(ItemStack stack, int x, int y, List extraLi protected void drawVanillaElements(int mouseX, int mouseY, float partialTicks) { for (Object guiButton : this.buttonList) { - ((GuiButton)guiButton).drawButton(this.mc, mouseX, mouseY); + ((GuiButton) guiButton).drawButton(this.mc, mouseX, mouseY); } for (Object guiLabel : this.labelList) { - ((GuiLabel)guiLabel).func_146159_a(this.mc, mouseX, mouseY); + ((GuiLabel) guiLabel).func_146159_a(this.mc, mouseX, mouseY); } } @@ -331,18 +357,18 @@ private boolean isDoubleClick(long lastClick, long currentClick) { return currentClick - lastClick < 500; } -// @Override -// protected boolean hasClickedOutside(int p_193983_1_, int p_193983_2_, int p_193983_3_, int p_193983_4_) { -// for (ModularWindow window : context.getOpenWindows()) { -// if (Pos2d.isInside(p_193983_1_, p_193983_2_, window.getAbsolutePos(), window.getSize())) { -// return false; -// } -// } -// return super.hasClickedOutside(p_193983_1_, p_193983_2_, p_193983_3_, p_193983_4_); -// } + // @Override + // protected boolean hasClickedOutside(int p_193983_1_, int p_193983_2_, int p_193983_3_, int p_193983_4_) { + // for (ModularWindow window : context.getOpenWindows()) { + // if (Pos2d.isInside(p_193983_1_, p_193983_2_, window.getAbsolutePos(), window.getSize())) { + // return false; + // } + // } + // return super.hasClickedOutside(p_193983_1_, p_193983_2_, p_193983_3_, p_193983_4_); + // } @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton){ + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { long time = Minecraft.getSystemTime(); boolean doubleClick = isDoubleClick(lastClick, time); lastClick = time; @@ -365,7 +391,8 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton){ } if (hovered instanceof Interactable) { Interactable interactable = (Interactable) hovered; - Interactable.ClickResult result = interactable.onClick(mouseButton, doubleClick && lastClicked == interactable); + Interactable.ClickResult result = + interactable.onClick(mouseButton, doubleClick && lastClicked == interactable); switch (result) { case IGNORE: continue; @@ -404,7 +431,8 @@ protected void mouseMovedOrUp(int mouseX, int mouseY, int mouseButton) { for (Interactable interactable : context.getCurrentWindow().getInteractionListeners()) { interactable.onClickReleased(mouseButton); } - if (!context.getCursor().onMouseReleased(mouseButton) && (lastClicked == null || !lastClicked.onClickReleased(mouseButton))) { + if (!context.getCursor().onMouseReleased(mouseButton) + && (lastClicked == null || !lastClicked.onClickReleased(mouseButton))) { super.mouseMovedOrUp(mouseX, mouseY, mouseButton); } } @@ -421,7 +449,7 @@ protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long time } @Override - protected void keyTyped(char typedChar, int keyCode){ + protected void keyTyped(char typedChar, int keyCode) { // debug mode C + CTRL + SHIFT if (keyCode == 46 && isCtrlKeyDown() && isShiftKeyDown()) { Config.debug = !Config.debug; @@ -435,7 +463,9 @@ protected void keyTyped(char typedChar, int keyCode){ return; } for (Object hovered : getCursor().getAllHovered()) { - if (focused != hovered && hovered instanceof Interactable && ((Interactable) hovered).onKeyPressed(typedChar, keyCode)) { + if (focused != hovered + && hovered instanceof Interactable + && ((Interactable) hovered).onKeyPressed(typedChar, keyCode)) { return; } } @@ -456,7 +486,9 @@ public void mouseScroll(int direction) { return; } for (Object hovered : getCursor().getAllHovered()) { - if (focused != hovered && hovered instanceof Interactable && ((Interactable) hovered).onMouseScroll(direction)) { + if (focused != hovered + && hovered instanceof Interactable + && ((Interactable) hovered).onMouseScroll(direction)) { return; } } @@ -513,7 +545,7 @@ public static void drawText(String text, float x, float y, float scale, int colo GlStateManager.pushMatrix(); GlStateManager.scale(scale, scale, 0f); float sf = 1 / scale; - fontRenderer.drawString(text, (int)(x * sf), (int)(y * sf), color, shadow); + fontRenderer.drawString(text, (int) (x * sf), (int) (y * sf), color, shadow); GlStateManager.popMatrix(); GlStateManager.enableBlend(); } @@ -538,10 +570,14 @@ public static void drawRect(float left, float top, float right, float bottom, in Tessellator tessellator = Tessellator.instance; GlStateManager.enableBlend(); GlStateManager.disableTexture2D(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.tryBlendFuncSeparate( + GlStateManager.SourceFactor.SRC_ALPHA, + GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, + GlStateManager.SourceFactor.ONE, + GlStateManager.DestFactor.ZERO); GlStateManager.color(r, g, b, a); tessellator.startDrawingQuads(); -// bufferbuilder.begin(7, DefaultVertexFormats.POSITION); + // bufferbuilder.begin(7, DefaultVertexFormats.POSITION); tessellator.addVertex(left, bottom, 0.0D); tessellator.addVertex(right, bottom, 0.0D); tessellator.addVertex(right, top, 0.0D); diff --git a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularUIContainer.java b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularUIContainer.java index f1f5c2a..ed36790 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularUIContainer.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/internal/wrapper/ModularUIContainer.java @@ -3,14 +3,13 @@ import com.gtnewhorizons.modularui.api.forge.ItemHandlerHelper; import com.gtnewhorizons.modularui.api.screen.ModularUIContext; import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import java.util.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import java.util.*; - public class ModularUIContainer extends Container { private final ModularUIContext context; @@ -43,7 +42,7 @@ public boolean canInteractWith(EntityPlayer playerIn) { private void checkSlotIds() { for (int i = 0; i < inventorySlots.size(); i++) { - ((Slot)(inventorySlots.get(i))).slotNumber = i; + ((Slot) (inventorySlots.get(i))).slotNumber = i; } } @@ -99,22 +98,22 @@ public void detectAndSendChanges() { public void sendSlotChange(ItemStack stack, int index) { for (Object listener : this.crafters) { - ((ICrafting)(listener)).sendSlotContents(this, index, stack); + ((ICrafting) (listener)).sendSlotContents(this, index, stack); } } -// public void sendHeldItemUpdate() { -// for (Object listener : this.crafters) { -// if (listener instanceof EntityPlayerMP) { -// EntityPlayerMP player = (EntityPlayerMP) listener; -// player.connection.sendPacket(new SPacketSetSlot(-1, -1, player.inventory.getItemStack())); -// } -// } -// } + // public void sendHeldItemUpdate() { + // for (Object listener : this.crafters) { + // if (listener instanceof EntityPlayerMP) { + // EntityPlayerMP player = (EntityPlayerMP) listener; + // player.connection.sendPacket(new SPacketSetSlot(-1, -1, player.inventory.getItemStack())); + // } + // } + // } @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - Slot slot = (Slot)(this.inventorySlots.get(index)); + Slot slot = (Slot) (this.inventorySlots.get(index)); if (slot instanceof BaseSlot && !((BaseSlot) slot).isPhantom()) { ItemStack stack = slot.getStack(); if (stack != null) { @@ -131,10 +130,14 @@ public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { protected ItemStack transferItem(BaseSlot fromSlot, ItemStack stack) { for (BaseSlot slot : this.sortedShiftClickSlots) { - if (fromSlot.getShiftClickPriority() != slot.getShiftClickPriority() && slot.canTake && slot.isItemValidPhantom(stack)) { + if (fromSlot.getShiftClickPriority() != slot.getShiftClickPriority() + && slot.canTake + && slot.isItemValidPhantom(stack)) { ItemStack itemstack = slot.getStack(); if (slot.isPhantom()) { - if (itemstack == null || (ItemHandlerHelper.canItemStacksStackRelaxed(stack, itemstack) && itemstack.stackSize < slot.getItemStackLimit(itemstack))) { + if (itemstack == null + || (ItemHandlerHelper.canItemStacksStackRelaxed(stack, itemstack) + && itemstack.stackSize < slot.getItemStackLimit(itemstack))) { slot.putStack(stack.copy()); return stack; } @@ -165,7 +168,10 @@ protected ItemStack transferItem(BaseSlot fromSlot, ItemStack stack) { } BaseSlot slot = (BaseSlot) slot1; ItemStack itemstack = slot.getStack(); - if (fromSlot.getItemHandler() != slot.getItemHandler() && slot.canInsert && itemstack == null && slot.isItemValid(stack)) { + if (fromSlot.getItemHandler() != slot.getItemHandler() + && slot.canInsert + && itemstack == null + && slot.isItemValid(stack)) { if (stack.stackSize > slot1.getSlotStackLimit()) { slot.putStack(stack.splitStack(slot.getSlotStackLimit())); } else { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/keybind/KeyBindHandler.java b/src/main/java/com/gtnewhorizons/modularui/common/keybind/KeyBindHandler.java index d244ed6..5d7c283 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/keybind/KeyBindHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/keybind/KeyBindHandler.java @@ -2,58 +2,58 @@ public class KeyBindHandler { -// @Mod.EventHandler -// public void preInit(FMLPreInitializationEvent event) { -// MinecraftForge.EVENT_BUS.register(this); -// } -// -// private static void checkKeyState(int key, boolean state) { -// if (key != 0) { -// // imitates KeyBinding.setKeyBindState() -// for (KeyBinding keyBinding : getKeyBindingMap().lookupAll(key)) { -// if (KeyBindAPI.doForceCheckKeyBind(keyBinding)) { -// ((KeyBindAccess) keyBinding).setPressed(state); -// } -// } -// // imitates KeyBinding.onTick() -// if (state) { -// KeyBinding keyBinding = getKeyBindingMap().lookupActive(key); -// if (keyBinding != null) { -// if (KeyBindAPI.doForceCheckKeyBind(keyBinding)) { -// incrementPressTime(keyBinding); -// } -// -// Collection compatibles = KeyBindAPI.getCompatibles(keyBinding); -// if (compatibles.isEmpty()) return; -// for (KeyBinding keyBinding1 : compatibles) { -// if (keyBinding1.isActiveAndMatches(key) && KeyBindAPI.doForceCheckKeyBind(keyBinding1)) { -// incrementPressTime(keyBinding1); -// } -// } -// } -// } -// } -// } -// -// @SubscribeEvent(priority = EventPriority.HIGHEST) -// public static void onGuiKeyInput(GuiScreenEvent.ActionPerformedEvent.Pre event) { -// if (!event.gui.mc.inGameHasFocus) { -// int key = Keyboard.getEventKey(); -// boolean state = Keyboard.getEventKeyState(); -// checkKeyState(key, state); -// } -// } -// -// @SubscribeEvent(priority = EventPriority.HIGHEST) -// public static void onMouseInput(GuiScreenEvent.ActionPerformedEvent.Pre event) { -// if (!event.gui.mc.inGameHasFocus) { -// int key = Mouse.getEventButton() - 100; -// boolean state = Mouse.getEventButtonState(); -// checkKeyState(key, state); -// } -// } -// -// public static IntHashMap getKeyBindingMap() { -// return ((KeyBindAccess) Minecraft.getMinecraft().gameSettings.keyBindPickBlock).getHash(); -// } + // @Mod.EventHandler + // public void preInit(FMLPreInitializationEvent event) { + // MinecraftForge.EVENT_BUS.register(this); + // } + // + // private static void checkKeyState(int key, boolean state) { + // if (key != 0) { + // // imitates KeyBinding.setKeyBindState() + // for (KeyBinding keyBinding : getKeyBindingMap().lookupAll(key)) { + // if (KeyBindAPI.doForceCheckKeyBind(keyBinding)) { + // ((KeyBindAccess) keyBinding).setPressed(state); + // } + // } + // // imitates KeyBinding.onTick() + // if (state) { + // KeyBinding keyBinding = getKeyBindingMap().lookupActive(key); + // if (keyBinding != null) { + // if (KeyBindAPI.doForceCheckKeyBind(keyBinding)) { + // incrementPressTime(keyBinding); + // } + // + // Collection compatibles = KeyBindAPI.getCompatibles(keyBinding); + // if (compatibles.isEmpty()) return; + // for (KeyBinding keyBinding1 : compatibles) { + // if (keyBinding1.isActiveAndMatches(key) && KeyBindAPI.doForceCheckKeyBind(keyBinding1)) { + // incrementPressTime(keyBinding1); + // } + // } + // } + // } + // } + // } + // + // @SubscribeEvent(priority = EventPriority.HIGHEST) + // public static void onGuiKeyInput(GuiScreenEvent.ActionPerformedEvent.Pre event) { + // if (!event.gui.mc.inGameHasFocus) { + // int key = Keyboard.getEventKey(); + // boolean state = Keyboard.getEventKeyState(); + // checkKeyState(key, state); + // } + // } + // + // @SubscribeEvent(priority = EventPriority.HIGHEST) + // public static void onMouseInput(GuiScreenEvent.ActionPerformedEvent.Pre event) { + // if (!event.gui.mc.inGameHasFocus) { + // int key = Mouse.getEventButton() - 100; + // boolean state = Mouse.getEventButtonState(); + // checkKeyState(key, state); + // } + // } + // + // public static IntHashMap getKeyBindingMap() { + // return ((KeyBindAccess) Minecraft.getMinecraft().gameSettings.keyBindPickBlock).getHash(); + // } } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/ButtonWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/ButtonWidget.java index eb12d9f..c9d94e3 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/ButtonWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/ButtonWidget.java @@ -6,12 +6,11 @@ import com.gtnewhorizons.modularui.api.widget.Interactable; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.Theme; +import java.util.function.BiConsumer; import net.minecraft.network.PacketBuffer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.function.BiConsumer; - /** * Clickable button widget. */ @@ -20,8 +19,7 @@ public class ButtonWidget extends SyncedWidget implements Interactable { public static ButtonWidget openSyncedWindowButton(int id) { return (ButtonWidget) new ButtonWidget() .setOnClick((clickData, widget) -> { - if (!widget.isClient()) - widget.getContext().openSyncedWindow(id); + if (!widget.isClient()) widget.getContext().openSyncedWindow(id); }) .setBackground(ModularUITextures.VANILLA_BACKGROUND, new Text("Window")); } @@ -72,8 +70,7 @@ public ClickResult onClick(int buttonId, boolean doubleClick) { } @Override - public void readOnClient(int id, PacketBuffer buf) { - } + public void readOnClient(int id, PacketBuffer buf) {} @Override public void readOnServer(int id, PacketBuffer buf) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/ChangeableWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/ChangeableWidget.java index 037b4f0..8e90327 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/ChangeableWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/ChangeableWidget.java @@ -5,23 +5,24 @@ import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; -import net.minecraft.network.PacketBuffer; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; +import net.minecraft.network.PacketBuffer; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; @ApiStatus.Experimental public class ChangeableWidget extends Widget implements ISyncedWidget, IWidgetParent { private final List child = new ArrayList<>(); + @Nullable private Widget queuedChild = null; + private final Supplier widgetSupplier; private boolean initialised = false; private boolean firstTick = true; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/Column.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/Column.java index cce1f66..7bb93c3 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/Column.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/Column.java @@ -1,10 +1,10 @@ package com.gtnewhorizons.modularui.common.widget; -import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; import com.gtnewhorizons.modularui.api.math.CrossAxisAlignment; import com.gtnewhorizons.modularui.api.math.MainAxisAlignment; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; import com.gtnewhorizons.modularui.api.widget.Widget; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/CycleButtonWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/CycleButtonWidget.java index 7e32985..e981bb0 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/CycleButtonWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/CycleButtonWidget.java @@ -1,7 +1,9 @@ package com.gtnewhorizons.modularui.common.widget; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.drawable.UITexture; @@ -10,16 +12,12 @@ import com.gtnewhorizons.modularui.api.widget.Interactable; import com.gtnewhorizons.modularui.common.internal.JsonHelper; import com.gtnewhorizons.modularui.common.internal.Theme; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import net.minecraft.network.PacketBuffer; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import java.util.ArrayList; import java.util.List; import java.util.function.*; +import net.minecraft.network.PacketBuffer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class CycleButtonWidget extends SyncedWidget implements Interactable { @@ -31,8 +29,7 @@ public class CycleButtonWidget extends SyncedWidget implements Interactable { private IDrawable texture = IDrawable.EMPTY; private final List> stateTooltip = new ArrayList<>(); - public CycleButtonWidget() { - } + public CycleButtonWidget() {} @Override public void readJson(JsonObject json, String type) { @@ -172,7 +169,9 @@ public void readOnServer(int id, PacketBuffer buf) { @Override public boolean hasTooltip() { - return super.hasTooltip() || (this.stateTooltip.size() > this.state && !this.stateTooltip.get(this.state).isEmpty()); + return super.hasTooltip() + || (this.stateTooltip.size() > this.state + && !this.stateTooltip.get(this.state).isEmpty()); } @Override diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/DrawableWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/DrawableWidget.java index 3fcd94a..795eaaa 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/DrawableWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/DrawableWidget.java @@ -2,7 +2,6 @@ import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.drawable.UITexture; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/DynamicTextWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/DynamicTextWidget.java index 1817bf6..65c15b2 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/DynamicTextWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/DynamicTextWidget.java @@ -1,7 +1,6 @@ package com.gtnewhorizons.modularui.common.widget; import com.gtnewhorizons.modularui.api.drawable.Text; - import java.util.function.Supplier; public class DynamicTextWidget extends TextWidget { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/ExpandTab.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/ExpandTab.java index 45f4231..fc68615 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/ExpandTab.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/ExpandTab.java @@ -33,25 +33,34 @@ public class ExpandTab extends MultiChildWidget implements Interactable, IWidget private Pos2d normalPos; private int animateDuration = 250; private float animateX, animateY, animateWidth, animateHeight; + @Nullable private IDrawable[] normalTexture; + private float ticktime; @Override public void onInit() { - this.openAnimator = new Interpolator(0, 1, this.animateDuration, Eases.EaseQuadOut, value -> { - float val = (float) value; - this.animateX = (this.expandedPos.x - this.normalPos.x) * val + this.normalPos.x; - this.animateY = (this.expandedPos.y - this.normalPos.y) * val + this.normalPos.y; - this.animateWidth = (this.expandedSize.width - this.normalSize.width) * val + this.normalSize.width; - this.animateHeight = (this.expandedSize.height - this.normalSize.height) * val + this.normalSize.height; - }, val -> { - this.animateX = this.expandedPos.x; - this.animateY = this.expandedPos.y; - this.animateWidth = this.expandedSize.width; - this.animateHeight = this.expandedSize.height; - this.animating = false; - }); + this.openAnimator = new Interpolator( + 0, + 1, + this.animateDuration, + Eases.EaseQuadOut, + value -> { + float val = (float) value; + this.animateX = (this.expandedPos.x - this.normalPos.x) * val + this.normalPos.x; + this.animateY = (this.expandedPos.y - this.normalPos.y) * val + this.normalPos.y; + this.animateWidth = (this.expandedSize.width - this.normalSize.width) * val + this.normalSize.width; + this.animateHeight = + (this.expandedSize.height - this.normalSize.height) * val + this.normalSize.height; + }, + val -> { + this.animateX = this.expandedPos.x; + this.animateY = this.expandedPos.y; + this.animateWidth = this.expandedSize.width; + this.animateHeight = this.expandedSize.height; + this.animating = false; + }); this.closeAnimator = this.openAnimator.getReversed(this.animateDuration, Eases.EaseQuadIn); this.closeAnimator.setCallback(val -> { this.animateX = this.normalPos.x; @@ -98,7 +107,6 @@ public void onRebuild() { } } - @SubscribeEvent public void onRenderTick(TickEvent.RenderTickEvent event) { ticktime = event.renderTickTime; @@ -108,7 +116,7 @@ public void onRenderTick(TickEvent.RenderTickEvent event) { public void onFrameUpdate() { if (this.animating) { if (expanded) { -// this.openAnimator.update(Minecraft.getMinecraft().getTickLength()); + // this.openAnimator.update(Minecraft.getMinecraft().getTickLength()); this.openAnimator.update(ticktime); } else { this.closeAnimator.update(ticktime); @@ -125,7 +133,8 @@ public void drawBackground(float partialTicks) { for (IDrawable drawable : background) { if (drawable != null) { drawable.applyThemeColor(themeColor); - drawable.draw(animateX - getPos().x, animateY - getPos().y, animateWidth, animateHeight, partialTicks); + drawable.draw( + animateX - getPos().x, animateY - getPos().y, animateWidth, animateHeight, partialTicks); } } } @@ -148,9 +157,14 @@ public void drawChildren(float partialTicks) { if (isExpanded() || animating) { Pos2d parentPos = getParent().getAbsolutePos(); if (animating) { - GuiHelper.useScissor((int) (parentPos.x + this.animateX), (int) (parentPos.y + this.animateY), (int) this.animateWidth, (int) this.animateHeight, () -> { - super.drawChildren(partialTicks); - }); + GuiHelper.useScissor( + (int) (parentPos.x + this.animateX), + (int) (parentPos.y + this.animateY), + (int) this.animateWidth, + (int) this.animateHeight, + () -> { + super.drawChildren(partialTicks); + }); } else { super.drawChildren(partialTicks); } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/FluidSlotWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/FluidSlotWidget.java index 7327fd4..71b6071 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/FluidSlotWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/FluidSlotWidget.java @@ -19,26 +19,28 @@ import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import com.gtnewhorizons.modularui.common.internal.wrapper.FluidTankHandler; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +import java.io.IOException; +import java.util.List; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fluids.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; -import java.util.List; - public class FluidSlotWidget extends SyncedWidget implements Interactable, IIngredientProvider, IGhostIngredientTarget { public static final Size SIZE = new Size(18, 18); @Nullable private IDrawable overlayTexture; + private final TextRenderer textRenderer = new TextRenderer(); private final IFluidTank fluidTank; private final IFluidHandler tankHandler; + @Nullable private FluidStack cachedFluid; + private FluidStack lastStoredPhantomFluid; private Pos2d contentOffset = new Pos2d(1, 1); private boolean alwaysShowFull = true; @@ -145,8 +147,7 @@ public void buildTooltip(List tooltip) { * @param tooltipContainer add lines here * @param fluid the nonnull fluid */ - public void addAdditionalFluidInfo(List tooltipContainer, @NotNull FluidStack fluid) { - } + public void addAdditionalFluidInfo(List tooltipContainer, @NotNull FluidStack fluid) {} @Override public @Nullable String getBackgroundColorKey() { @@ -244,7 +245,8 @@ public void detectAndSendChanges(boolean init) { } public static boolean fluidChanged(@Nullable FluidStack current, @Nullable FluidStack cached) { - return current == null ^ cached == null || (current != null && (current.amount != cached.amount || !current.isFluidEqual(cached))); + return current == null ^ cached == null + || (current != null && (current.amount != cached.amount || !current.isFluidEqual(cached))); } @Override @@ -278,113 +280,120 @@ public void readOnServer(int id, PacketBuffer buf) throws IOException { } private void tryClickContainer(int mouseButton, boolean isShiftKeyDown) { -// EntityPlayer player = getContext().getPlayer(); -// ItemStack currentStack = getContext().getCursor().getItemStack(); -// if (!currentStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { -// return; -// } -// int maxAttempts = isShiftKeyDown ? currentStack.stackSize : 1; -// if (mouseButton == 0 && canFillSlot) { -// boolean performedTransfer = false; -// for (int i = 0; i < maxAttempts; i++) { -// FluidActionResult result = FluidUtil.tryEmptyContainer(currentStack, tankHandler, Integer.MAX_VALUE, null, false); -// ItemStack remainingStack = result.getResult(); -// if (!result.isSuccess() || (currentStack.stackSize > 1 && remainingStack != null && !player.inventory.addItemStackToInventory(remainingStack))) { -// player.dropItem(remainingStack.getItem(), remainingStack.stackSize); -// break; //do not continue if we can't add resulting container into inventory -// } -// -// remainingStack = FluidUtil.tryEmptyContainer(currentStack, tankHandler, Integer.MAX_VALUE, null, true).result; -// if (currentStack.stackSize == 1) { -// currentStack = remainingStack; -// } else { -// currentStack.stackSize -= 1; -// } -// performedTransfer = true; -// if (currentStack == null) { -// break; -// } -// } -// FluidStack fluid = fluidTank.getFluid(); -// if (performedTransfer && fluid != null) { -// playSound(fluid, false); -// getContext().getCursor().setItemStack(currentStack, true); -// } -// return; -// } -// FluidStack currentFluid = fluidTank.getFluid(); -// if (mouseButton == 1 && canDrainSlot && currentFluid != null && currentFluid.amount > 0) { -// boolean performedTransfer = false; -// for (int i = 0; i < maxAttempts; i++) { -// FluidActionResult result = FluidUtil.tryFillContainer(currentStack, tankHandler, Integer.MAX_VALUE, null, false); -// ItemStack remainingStack = result.getResult(); -// if (!result.isSuccess() || (currentStack.stackSize > 1 && remainingStack != null && !player.inventory.addItemStackToInventory(remainingStack))) { -// break; //do not continue if we can't add resulting container into inventory -// } -// -// remainingStack = FluidUtil.tryFillContainer(currentStack, tankHandler, Integer.MAX_VALUE, null, true).result; -// if (currentStack.getCount() == 1) { -// currentStack = remainingStack; -// } else { -// currentStack.shrink(1); -// } -// performedTransfer = true; -// if (currentStack.isEmpty()) { -// break; -// } -// } -// if (performedTransfer) { -// playSound(currentFluid, true); -// getContext().getCursor().setItemStack(currentStack, true); -// } -// } + // EntityPlayer player = getContext().getPlayer(); + // ItemStack currentStack = getContext().getCursor().getItemStack(); + // if (!currentStack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { + // return; + // } + // int maxAttempts = isShiftKeyDown ? currentStack.stackSize : 1; + // if (mouseButton == 0 && canFillSlot) { + // boolean performedTransfer = false; + // for (int i = 0; i < maxAttempts; i++) { + // FluidActionResult result = FluidUtil.tryEmptyContainer(currentStack, tankHandler, + // Integer.MAX_VALUE, null, false); + // ItemStack remainingStack = result.getResult(); + // if (!result.isSuccess() || (currentStack.stackSize > 1 && remainingStack != null && + // !player.inventory.addItemStackToInventory(remainingStack))) { + // player.dropItem(remainingStack.getItem(), remainingStack.stackSize); + // break; //do not continue if we can't add resulting container into inventory + // } + // + // remainingStack = FluidUtil.tryEmptyContainer(currentStack, tankHandler, Integer.MAX_VALUE, + // null, true).result; + // if (currentStack.stackSize == 1) { + // currentStack = remainingStack; + // } else { + // currentStack.stackSize -= 1; + // } + // performedTransfer = true; + // if (currentStack == null) { + // break; + // } + // } + // FluidStack fluid = fluidTank.getFluid(); + // if (performedTransfer && fluid != null) { + // playSound(fluid, false); + // getContext().getCursor().setItemStack(currentStack, true); + // } + // return; + // } + // FluidStack currentFluid = fluidTank.getFluid(); + // if (mouseButton == 1 && canDrainSlot && currentFluid != null && currentFluid.amount > 0) { + // boolean performedTransfer = false; + // for (int i = 0; i < maxAttempts; i++) { + // FluidActionResult result = FluidUtil.tryFillContainer(currentStack, tankHandler, + // Integer.MAX_VALUE, null, false); + // ItemStack remainingStack = result.getResult(); + // if (!result.isSuccess() || (currentStack.stackSize > 1 && remainingStack != null && + // !player.inventory.addItemStackToInventory(remainingStack))) { + // break; //do not continue if we can't add resulting container into inventory + // } + // + // remainingStack = FluidUtil.tryFillContainer(currentStack, tankHandler, Integer.MAX_VALUE, + // null, true).result; + // if (currentStack.getCount() == 1) { + // currentStack = remainingStack; + // } else { + // currentStack.shrink(1); + // } + // performedTransfer = true; + // if (currentStack.isEmpty()) { + // break; + // } + // } + // if (performedTransfer) { + // playSound(currentFluid, true); + // getContext().getCursor().setItemStack(currentStack, true); + // } + // } } public void tryClickPhantom(int mouseButton, boolean isShiftKeyDown) { -// EntityPlayer player = getContext().getPlayer(); -// ItemStack currentStack = getContext().getCursor().getItemStack(); -// FluidStack currentFluid = this.fluidTank.getFluid(); -// IFluidHandlerItem fluidHandlerItem = currentStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); -// -// if (mouseButton == 0) { -// if (currentStack == null || fluidHandlerItem == null) { -// if (canDrainSlot) { -// this.fluidTank.drain(isShiftKeyDown ? Integer.MAX_VALUE : 1000, true); -// } -// } else { -// FluidStack cellFluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false); -// if ((this.controlsAmount || currentFluid == null) && cellFluid != null) { -// if (canFillSlot) { -// if (!this.controlsAmount) { -// cellFluid.amount = 1; -// } -// if (this.fluidTank.fill(cellFluid, true) > 0) { -// this.lastStoredPhantomFluid = cellFluid.copy(); -// } -// } -// } else { -// if (canDrainSlot) { -// fluidTank.drain(isShiftKeyDown ? Integer.MAX_VALUE : 1000, true); -// } -// } -// } -// } else if (mouseButton == 1) { -// if (canFillSlot) { -// if (currentFluid != null) { -// if (this.controlsAmount) { -// FluidStack toFill = currentFluid.copy(); -// toFill.amount = 1000; -// this.fluidTank.fill(toFill, true); -// } -// } else if (lastStoredPhantomFluid != null) { -// FluidStack toFill = this.lastStoredPhantomFluid.copy(); -// toFill.amount = this.controlsAmount ? 1000 : 1; -// this.fluidTank.fill(toFill, true); -// } -// } -// } else if (mouseButton == 2 && currentFluid != null && canDrainSlot) { -// this.fluidTank.drain(isShiftKeyDown ? Integer.MAX_VALUE : 1000, true); -// } + // EntityPlayer player = getContext().getPlayer(); + // ItemStack currentStack = getContext().getCursor().getItemStack(); + // FluidStack currentFluid = this.fluidTank.getFluid(); + // IFluidHandlerItem fluidHandlerItem = + // currentStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); + // + // if (mouseButton == 0) { + // if (currentStack == null || fluidHandlerItem == null) { + // if (canDrainSlot) { + // this.fluidTank.drain(isShiftKeyDown ? Integer.MAX_VALUE : 1000, true); + // } + // } else { + // FluidStack cellFluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false); + // if ((this.controlsAmount || currentFluid == null) && cellFluid != null) { + // if (canFillSlot) { + // if (!this.controlsAmount) { + // cellFluid.amount = 1; + // } + // if (this.fluidTank.fill(cellFluid, true) > 0) { + // this.lastStoredPhantomFluid = cellFluid.copy(); + // } + // } + // } else { + // if (canDrainSlot) { + // fluidTank.drain(isShiftKeyDown ? Integer.MAX_VALUE : 1000, true); + // } + // } + // } + // } else if (mouseButton == 1) { + // if (canFillSlot) { + // if (currentFluid != null) { + // if (this.controlsAmount) { + // FluidStack toFill = currentFluid.copy(); + // toFill.amount = 1000; + // this.fluidTank.fill(toFill, true); + // } + // } else if (lastStoredPhantomFluid != null) { + // FluidStack toFill = this.lastStoredPhantomFluid.copy(); + // toFill.amount = this.controlsAmount ? 1000 : 1; + // this.fluidTank.fill(toFill, true); + // } + // } + // } else if (mouseButton == 2 && currentFluid != null && canDrainSlot) { + // this.fluidTank.drain(isShiftKeyDown ? Integer.MAX_VALUE : 1000, true); + // } } public void tryScrollPhantom(int direction) { @@ -407,42 +416,46 @@ public void tryScrollPhantom(int direction) { } private void playSound(FluidStack fluid, boolean fill) { -// EntityPlayer player = getContext().getPlayer(); -// SoundEvent soundevent = fill ? fluid.getFluid().getFillSound(fluid) : fluid.getFluid().getEmptySound(fluid); -// player.world.playSound(null, player.posX, player.posY + 0.5, player.posZ, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F); + // EntityPlayer player = getContext().getPlayer(); + // SoundEvent soundevent = fill ? fluid.getFluid().getFillSound(fluid) : + // fluid.getFluid().getEmptySound(fluid); + // player.world.playSound(null, player.posX, player.posY + 0.5, player.posZ, soundevent, + // SoundCategory.BLOCKS, 1.0F, 1.0F); } @Override public IGhostIngredientHandler.@Nullable Target getTarget(@NotNull ItemStack ingredient) { -// if (!isPhantom()) { -// return null; -// } -// if (ingredient instanceof FluidStack) { -// return ((FluidStack) ingredient).amount > 0 ? new GhostIngredientWrapper<>(this) : null; -// } -// if (ingredient instanceof ItemStack) { -// if (((ItemStack) ingredient).isEmpty()) return null; -// IFluidHandlerItem fluidHandlerItem = ((ItemStack) ingredient).getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); -// if (fluidHandlerItem != null) { -// return new GhostIngredientWrapper<>(this); -// } -// } + // if (!isPhantom()) { + // return null; + // } + // if (ingredient instanceof FluidStack) { + // return ((FluidStack) ingredient).amount > 0 ? new GhostIngredientWrapper<>(this) : null; + // } + // if (ingredient instanceof ItemStack) { + // if (((ItemStack) ingredient).isEmpty()) return null; + // IFluidHandlerItem fluidHandlerItem = ((ItemStack) + // ingredient).getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); + // if (fluidHandlerItem != null) { + // return new GhostIngredientWrapper<>(this); + // } + // } return null; } @Override public void accept(@NotNull ItemStack ingredient) { -// FluidStack fluid = null; -// if (ingredient instanceof FluidStack) { -// fluid = (FluidStack) ingredient; -// } else if (ingredient instanceof ItemStack) { -// IFluidHandlerItem fluidHandlerItem = ((ItemStack) ingredient).getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); -// if (fluidHandlerItem == null) return; -// fluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false); -// } -// if (fluid == null) return; -// final FluidStack finalFluid = fluid; -// syncToServer(4, buffer -> NetworkUtils.writeFluidStack(buffer, finalFluid)); + // FluidStack fluid = null; + // if (ingredient instanceof FluidStack) { + // fluid = (FluidStack) ingredient; + // } else if (ingredient instanceof ItemStack) { + // IFluidHandlerItem fluidHandlerItem = ((ItemStack) + // ingredient).getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); + // if (fluidHandlerItem == null) return; + // fluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false); + // } + // if (fluid == null) return; + // final FluidStack finalFluid = fluid; + // syncToServer(4, buffer -> NetworkUtils.writeFluidStack(buffer, finalFluid)); } public boolean canFillSlot() { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/ListWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/ListWidget.java index 70954cf..348bb9c 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/ListWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/ListWidget.java @@ -1,6 +1,5 @@ package com.gtnewhorizons.modularui.common.widget; -import com.gtnewhorizons.modularui.common.internal.wrapper.MultiList; import com.gtnewhorizons.modularui.api.drawable.GuiHelper; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; @@ -8,20 +7,22 @@ import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.api.widget.scroll.IVerticalScrollable; import com.gtnewhorizons.modularui.api.widget.scroll.ScrollType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - +import com.gtnewhorizons.modularui.common.internal.wrapper.MultiList; import java.util.List; import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Function; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ListWidget extends MultiChildWidget implements Interactable, IVerticalScrollable { private int scrollOffset = 0; private int totalHeight = 0; + @Nullable private ScrollBar scrollBar; + private int maxHeight = -1; private final MultiList allChildren = new MultiList<>(); @@ -29,7 +30,8 @@ public static ListWidget builder(List list, BiFunction ListWidget builder(List list, BiFunction widgetCreator) { ListWidget listWidget = new ListWidget(); for (int i = 0; i < size; i++) { - Widget widget = Objects.requireNonNull(widgetCreator.apply(i), "ListWidget creator produced a null child! This is forbidden!"); + Widget widget = Objects.requireNonNull( + widgetCreator.apply(i), "ListWidget creator produced a null child! This is forbidden!"); listWidget.addChild(widget); } return listWidget; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/MultiChildWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/MultiChildWidget.java index 60c293d..afd84b2 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/MultiChildWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/MultiChildWidget.java @@ -1,15 +1,13 @@ package com.gtnewhorizons.modularui.common.widget; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Widget; -import org.jetbrains.annotations.NotNull; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jetbrains.annotations.NotNull; public class MultiChildWidget extends Widget implements IWidgetParent { @@ -61,7 +59,8 @@ public static Size getSizeOf(List widgets) { public static boolean checkChild(Widget parent, Widget widget) { if (widget == null) { - ModularUI.logger.error("Tried adding null widget to " + parent.getClass().getSimpleName()); + ModularUI.logger.error( + "Tried adding null widget to " + parent.getClass().getSimpleName()); return false; } if (widget == parent) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/PageControlWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/PageControlWidget.java index f35fadc..29feb78 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/PageControlWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/PageControlWidget.java @@ -1,15 +1,13 @@ package com.gtnewhorizons.modularui.common.widget; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Widget; -import org.jetbrains.annotations.NotNull; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jetbrains.annotations.NotNull; /** * Parent widget that can contain children and switch them with pagination. @@ -69,7 +67,8 @@ public void prevPage() { public void setActivePage(int page) { if (page > pages.size() - 1 || page < 0) { - throw new IndexOutOfBoundsException("Tried setting active page to " + page + " while only 0 - " + (pages.size() - 1) + " is allowed"); + throw new IndexOutOfBoundsException( + "Tried setting active page to " + page + " while only 0 - " + (pages.size() - 1) + " is allowed"); } if (!isInitialised()) { this.currentPage = page; diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/ProgressBar.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/ProgressBar.java index 7e0f6b0..50416f0 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/ProgressBar.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/ProgressBar.java @@ -1,14 +1,13 @@ package com.gtnewhorizons.modularui.common.widget; import codechicken.lib.math.MathHelper; -import com.gtnewhorizons.modularui.config.Config; import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.Widget; -import org.jetbrains.annotations.NotNull; - +import com.gtnewhorizons.modularui.config.Config; import java.util.function.Supplier; +import org.jetbrains.annotations.NotNull; public class ProgressBar extends Widget { @@ -87,45 +86,50 @@ public float getProgressUV(float uv) { private void drawCircular(float progress) { float[] subAreas = { - getProgressUV((float)MathHelper.clip(progress / 0.25f, 0, 1)), - getProgressUV((float)MathHelper.clip((progress - 0.25f) / 0.25f, 0, 1)), - getProgressUV((float)MathHelper.clip((progress - 0.5f) / 0.25f, 0, 1)), - getProgressUV((float)MathHelper.clip((progress - 0.75f) / 0.25f, 0, 1)) + getProgressUV((float) MathHelper.clip(progress / 0.25f, 0, 1)), + getProgressUV((float) MathHelper.clip((progress - 0.25f) / 0.25f, 0, 1)), + getProgressUV((float) MathHelper.clip((progress - 0.5f) / 0.25f, 0, 1)), + getProgressUV((float) MathHelper.clip((progress - 0.75f) / 0.25f, 0, 1)) }; float halfWidth = size.width / 2f; float halfHeight = size.height / 2f; float progressScaled = subAreas[0] * halfHeight; fullTexture[0].drawSubArea( - 0, size.height - progressScaled, - halfWidth, progressScaled, - 0.0f, 1.0f - progressScaled / halfHeight, - 1.0f, 1.0f - ); // BL, draw UP + 0, + size.height - progressScaled, + halfWidth, + progressScaled, + 0.0f, + 1.0f - progressScaled / halfHeight, + 1.0f, + 1.0f); // BL, draw UP progressScaled = subAreas[1] * halfWidth; fullTexture[1].drawSubArea( - 0, 0, - progressScaled, halfHeight, - 0.0f, 0.0f, - progressScaled / (halfWidth), 1.0f - ); // TL, draw RIGHT + 0, 0, progressScaled, halfHeight, 0.0f, 0.0f, progressScaled / (halfWidth), 1.0f); // TL, draw RIGHT progressScaled = subAreas[2] * halfHeight; fullTexture[2].drawSubArea( - halfWidth, 0, - halfWidth, progressScaled, - 0.0f, 0.0f, - 1.0f, progressScaled / halfHeight - ); // TR, draw DOWN + halfWidth, + 0, + halfWidth, + progressScaled, + 0.0f, + 0.0f, + 1.0f, + progressScaled / halfHeight); // TR, draw DOWN progressScaled = subAreas[3] * halfWidth; fullTexture[3].drawSubArea( - size.width - progressScaled, halfHeight, - progressScaled, halfHeight, - 1.0f - progressScaled / halfWidth, 0.0f, - 1.0f, 1.0f - ); // BR, draw LEFT + size.width - progressScaled, + halfHeight, + progressScaled, + halfHeight, + 1.0f - progressScaled / halfWidth, + 0.0f, + 1.0f, + 1.0f); // BR, draw LEFT } @Override @@ -170,6 +174,10 @@ public ProgressBar setDirection(Direction direction) { } public enum Direction { - LEFT, RIGHT, UP, DOWN, CIRCULAR_CW; + LEFT, + RIGHT, + UP, + DOWN, + CIRCULAR_CW; } } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/ScrollBar.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/ScrollBar.java index 2da0af1..6046d8e 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/ScrollBar.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/ScrollBar.java @@ -18,9 +18,7 @@ public class ScrollBar extends Widget implements Interactable { public static ScrollBar defaultTextScrollBar() { return new ScrollBar() - .setBarTexture(new Rectangle() - .setColor(Color.WHITE.normal) - .setCornerRadius(1)); + .setBarTexture(new Rectangle().setColor(Color.WHITE.normal).setCornerRadius(1)); } private ScrollType scrollType; @@ -30,7 +28,10 @@ public static ScrollBar defaultTextScrollBar() { private int handleClickOffset = -1; private int posOffset = 0; - public void setScrollType(ScrollType scrollType, @Nullable IHorizontalScrollable horizontalScrollable, @Nullable IVerticalScrollable verticalScrollable) { + public void setScrollType( + ScrollType scrollType, + @Nullable IHorizontalScrollable horizontalScrollable, + @Nullable IVerticalScrollable verticalScrollable) { this.scrollType = scrollType; this.verticalScrollable = verticalScrollable; this.horizontalScrollable = horizontalScrollable; @@ -38,13 +39,15 @@ public void setScrollType(ScrollType scrollType, @Nullable IHorizontalScrollable @Override public void onInit() { - if ((scrollType == ScrollType.VERTICAL && verticalScrollable == null) || (scrollType == ScrollType.HORIZONTAL && horizontalScrollable == null)) { + if ((scrollType == ScrollType.VERTICAL && verticalScrollable == null) + || (scrollType == ScrollType.HORIZONTAL && horizontalScrollable == null)) { throw new IllegalStateException("Scroll bar was not properly initialized"); } if (isAutoSized()) { setSizeProvider((screenSize, window, parent) -> { if (scrollType == ScrollType.HORIZONTAL) { - return new Size(horizontalScrollable.getVisibleWidth(), horizontalScrollable.getHorizontalBarHeight()); + return new Size( + horizontalScrollable.getVisibleWidth(), horizontalScrollable.getHorizontalBarHeight()); } else if (scrollType == ScrollType.VERTICAL) { return new Size(verticalScrollable.getVerticalBarWidth(), verticalScrollable.getVisibleHeight()); } @@ -54,7 +57,8 @@ public void onInit() { if (isAutoPositioned()) { setPosProvider((screenSize, window, parent) -> { if (scrollType == ScrollType.HORIZONTAL) { - return new Pos2d(0, parent.getSize().height - horizontalScrollable.getHorizontalBarHeight() + posOffset); + return new Pos2d( + 0, parent.getSize().height - horizontalScrollable.getHorizontalBarHeight() + posOffset); } else if (scrollType == ScrollType.VERTICAL) { return new Pos2d(parent.getSize().width - verticalScrollable.getVerticalBarWidth() + posOffset, 0); } @@ -101,11 +105,23 @@ public void draw(float partialTicks) { if (isActive() && this.barTexture != null) { int size = calculateMainAxisSize(); if (scrollType == ScrollType.HORIZONTAL) { - float offset = horizontalScrollable.getHorizontalScrollOffset() / (float) (horizontalScrollable.getActualWidth()); - this.barTexture.draw(horizontalScrollable.getVisibleWidth() * offset, 0, size, horizontalScrollable.getHorizontalBarHeight(), partialTicks); + float offset = horizontalScrollable.getHorizontalScrollOffset() + / (float) (horizontalScrollable.getActualWidth()); + this.barTexture.draw( + horizontalScrollable.getVisibleWidth() * offset, + 0, + size, + horizontalScrollable.getHorizontalBarHeight(), + partialTicks); } else if (scrollType == ScrollType.VERTICAL) { - float offset = verticalScrollable.getVerticalScrollOffset() / (float) (verticalScrollable.getActualHeight()); - this.barTexture.draw(0, verticalScrollable.getVisibleHeight() * offset, verticalScrollable.getVerticalBarWidth(), size, partialTicks); + float offset = + verticalScrollable.getVerticalScrollOffset() / (float) (verticalScrollable.getActualHeight()); + this.barTexture.draw( + 0, + verticalScrollable.getVisibleHeight() * offset, + verticalScrollable.getVerticalBarWidth(), + size, + partialTicks); } } } @@ -161,19 +177,25 @@ public ClickResult onClick(int buttonId, boolean doubleClick) { int barSize = calculateMainAxisSize(); int actualSize = getActualSize(); if (scrollType == ScrollType.HORIZONTAL) { - float offset = horizontalScrollable.getHorizontalScrollOffset() / (float) (actualSize) * horizontalScrollable.getVisibleWidth(); + float offset = horizontalScrollable.getHorizontalScrollOffset() + / (float) (actualSize) + * horizontalScrollable.getVisibleWidth(); if (relative.x >= offset && relative.x <= offset + barSize) { this.handleClickOffset = (int) (relative.x - offset); } else { - float newOffset = Math.max(0, (relative.x - barSize / 2f) / (float) horizontalScrollable.getVisibleWidth()); + float newOffset = + Math.max(0, (relative.x - barSize / 2f) / (float) horizontalScrollable.getVisibleWidth()); setScrollOffset((int) (newOffset * actualSize)); } } else if (scrollType == ScrollType.VERTICAL) { - float offset = verticalScrollable.getVerticalScrollOffset() / (float) (actualSize) * verticalScrollable.getVisibleHeight(); + float offset = verticalScrollable.getVerticalScrollOffset() + / (float) (actualSize) + * verticalScrollable.getVisibleHeight(); if (relative.y >= offset && relative.y <= offset + barSize) { this.handleClickOffset = (int) (relative.y - offset); } else { - float newOffset = Math.max(0, (relative.y - barSize / 2f) / (float) verticalScrollable.getVisibleHeight()); + float newOffset = + Math.max(0, (relative.y - barSize / 2f) / (float) verticalScrollable.getVisibleHeight()); setScrollOffset((int) (newOffset * actualSize)); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/Scrollable.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/Scrollable.java index 4ac3763..8eb5df8 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/Scrollable.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/Scrollable.java @@ -11,13 +11,13 @@ import com.gtnewhorizons.modularui.api.widget.scroll.IHorizontalScrollable; import com.gtnewhorizons.modularui.api.widget.scroll.IVerticalScrollable; import com.gtnewhorizons.modularui.api.widget.scroll.ScrollType; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.UnknownNullability; - import java.util.ArrayList; import java.util.List; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnknownNullability; -public class Scrollable extends Widget implements IWidgetBuilder, IWidgetParent, Interactable, IHorizontalScrollable, IVerticalScrollable { +public class Scrollable extends Widget + implements IWidgetBuilder, IWidgetParent, Interactable, IHorizontalScrollable, IVerticalScrollable { private int xScroll = 0, yScroll = 0; private final List children = new ArrayList<>(); diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SingleChildWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SingleChildWidget.java index e11d0ff..a6a58f6 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SingleChildWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SingleChildWidget.java @@ -1,22 +1,19 @@ package com.gtnewhorizons.modularui.common.widget; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Widget; -import org.jetbrains.annotations.NotNull; - import java.util.Collections; import java.util.List; +import org.jetbrains.annotations.NotNull; public class SingleChildWidget extends Widget implements IWidgetParent { private Widget child; - public SingleChildWidget() { - } + public SingleChildWidget() {} public SingleChildWidget(Size size) { super(size); diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SliderWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SliderWidget.java index 7adfc46..b9a8f5c 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SliderWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SliderWidget.java @@ -7,19 +7,20 @@ import com.gtnewhorizons.modularui.api.widget.Interactable; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.network.PacketBuffer; - import java.io.IOException; import java.util.function.Consumer; import java.util.function.Supplier; +import net.minecraft.network.PacketBuffer; public class SliderWidget extends SyncedWidget implements Interactable { private IDrawable slider = ModularUITextures.BASE_BUTTON; private Size handleSize = new Size(8, 0); private float min = 0, max = 1; + @SideOnly(Side.CLIENT) private float sliderPos = 0; + private float value = 0; private Supplier getter; private Consumer setter; @@ -40,7 +41,9 @@ public float toPos(float value) { @SideOnly(Side.CLIENT) public void updateSlider(int relativePos, boolean sync) { - setValue(toValue((float)MathHelper.clip(relativePos - handleSize.width / 2f, 0, size.width - handleSize.width)), sync); + setValue( + toValue((float) MathHelper.clip(relativePos - handleSize.width / 2f, 0, size.width - handleSize.width)), + sync); } @Override @@ -50,12 +53,18 @@ public void onInit() { @Override public void onRebuild() { - this.handleSize = new Size(handleSize.width > 0 ? handleSize.width : 8, handleSize.height > 0 ? handleSize.height : size.height); + this.handleSize = new Size( + handleSize.width > 0 ? handleSize.width : 8, handleSize.height > 0 ? handleSize.height : size.height); } @Override public void draw(float partialTicks) { - slider.draw(sliderPos, size.height / 2f - handleSize.height / 2f, handleSize.width, handleSize.height, partialTicks); + slider.draw( + sliderPos, + size.height / 2f - handleSize.height / 2f, + handleSize.width, + handleSize.height, + partialTicks); } @Override diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotGroup.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotGroup.java index 94d6029..8b23267 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotGroup.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotGroup.java @@ -1,7 +1,6 @@ package com.gtnewhorizons.modularui.common.widget; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.forge.IItemHandlerModifiable; import com.gtnewhorizons.modularui.api.forge.PlayerMainInvWrapper; import com.gtnewhorizons.modularui.api.math.Alignment; @@ -9,16 +8,15 @@ import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.wrapper.BaseSlot; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.fluids.IFluidTank; -import org.jetbrains.annotations.Nullable; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fluids.IFluidTank; +import org.jetbrains.annotations.Nullable; public class SlotGroup extends MultiChildWidget { @@ -37,26 +35,41 @@ public static SlotGroup playerInventoryGroup(EntityPlayer player) { } for (int i = 0; i < 9; i++) { - SlotWidget slot = new SlotWidget(new BaseSlot(wrapper, i)) - .setPos(new Pos2d(i * 18, 58)); + SlotWidget slot = new SlotWidget(new BaseSlot(wrapper, i)).setPos(new Pos2d(i * 18, 58)); slotGroup.addSlot(slot); } return slotGroup; } - public static SlotGroup ofItemHandler(IItemHandlerModifiable itemHandler, int slotsWidth, boolean output, @Nullable String sortArea) { + public static SlotGroup ofItemHandler( + IItemHandlerModifiable itemHandler, int slotsWidth, boolean output, @Nullable String sortArea) { return ofItemHandler(itemHandler, slotsWidth, 0, 0, itemHandler.getSlots() - 1, sortArea, output); } - public static SlotGroup ofItemHandler(IItemHandlerModifiable itemHandler, int slotsWidth, int shiftClickPriority, @Nullable String sortArea) { - return ofItemHandler(itemHandler, slotsWidth, shiftClickPriority, 0, itemHandler.getSlots() - 1, sortArea, false); + public static SlotGroup ofItemHandler( + IItemHandlerModifiable itemHandler, int slotsWidth, int shiftClickPriority, @Nullable String sortArea) { + return ofItemHandler( + itemHandler, slotsWidth, shiftClickPriority, 0, itemHandler.getSlots() - 1, sortArea, false); } - public static SlotGroup ofItemHandler(IItemHandlerModifiable itemHandler, int slotsWidth, int shiftClickPriority, int startFromSlot, int endAtSlot, @Nullable String sortArea) { + public static SlotGroup ofItemHandler( + IItemHandlerModifiable itemHandler, + int slotsWidth, + int shiftClickPriority, + int startFromSlot, + int endAtSlot, + @Nullable String sortArea) { return ofItemHandler(itemHandler, slotsWidth, shiftClickPriority, startFromSlot, endAtSlot, sortArea, false); } - public static SlotGroup ofItemHandler(IItemHandlerModifiable itemHandler, int slotsWidth, int shiftClickPriority, int startFromSlot, int endAtSlot, @Nullable String sortArea, boolean output) { + public static SlotGroup ofItemHandler( + IItemHandlerModifiable itemHandler, + int slotsWidth, + int shiftClickPriority, + int startFromSlot, + int endAtSlot, + @Nullable String sortArea, + boolean output) { SlotGroup slotGroup = new SlotGroup(); if (itemHandler.getSlots() >= endAtSlot) { endAtSlot = itemHandler.getSlots() - 1; @@ -68,7 +81,9 @@ public static SlotGroup ofItemHandler(IItemHandlerModifiable itemHandler, int sl slotsWidth = Math.max(slotsWidth, 1); int x = 0, y = 0; for (int i = startFromSlot; i < endAtSlot + 1; i++) { - slotGroup.addSlot(new SlotWidget(new BaseSlot(itemHandler, i, false).setAccess(!output, true).setShiftClickPriority(shiftClickPriority)) + slotGroup.addSlot(new SlotWidget(new BaseSlot(itemHandler, i, false) + .setAccess(!output, true) + .setShiftClickPriority(shiftClickPriority)) .setPos(new Pos2d(x * 18, y * 18))); if (++x == slotsWidth) { x = 0; @@ -171,7 +186,9 @@ public SlotGroup build() { ModularUI.logger.warn("Key {} was not found in Slot group.", c); continue; } - Widget widget = widgetCreator.apply(charCount.computeIfAbsent(c, key -> new AtomicInteger()).getAndIncrement()); + Widget widget = widgetCreator.apply(charCount + .computeIfAbsent(c, key -> new AtomicInteger()) + .getAndIncrement()); if (widget != null) { slotGroup.addChild(widget.setPos(offsetPos.add(j * cellSize.width, i * cellSize.height))); } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotWidget.java index 1e7c703..546b398 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SlotWidget.java @@ -11,6 +11,7 @@ import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.nei.IGhostIngredientHandler; +import com.gtnewhorizons.modularui.api.widget.*; import com.gtnewhorizons.modularui.api.widget.IGhostIngredientTarget; import com.gtnewhorizons.modularui.api.widget.IIngredientProvider; import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; @@ -22,9 +23,15 @@ import com.gtnewhorizons.modularui.common.internal.wrapper.GhostIngredientWrapper; import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; import com.gtnewhorizons.modularui.mixins.GuiContainerMixin; -import com.gtnewhorizons.modularui.api.widget.*; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Predicate; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.resources.I18n; @@ -37,21 +44,15 @@ import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Predicate; - -public class SlotWidget extends Widget implements IVanillaSlot, Interactable, ISyncedWidget, IIngredientProvider, IGhostIngredientTarget { +public class SlotWidget extends Widget + implements IVanillaSlot, Interactable, ISyncedWidget, IIngredientProvider, IGhostIngredientTarget { public static final Size SIZE = new Size(18, 18); private final TextRenderer textRenderer = new TextRenderer(); private final BaseSlot slot; private ItemStack lastStoredPhantomItem = null; + @Nullable private String sortAreaName = null; @@ -116,7 +117,8 @@ public void draw(float partialTicks) { @Override public void onRebuild() { - Pos2d pos = getAbsolutePos().subtract(getContext().getMainWindow().getPos()).add(1, 1); + Pos2d pos = + getAbsolutePos().subtract(getContext().getMainWindow().getPos()).add(1, 1); if (this.slot.xDisplayPosition != pos.x || this.slot.yDisplayPosition != pos.y) { this.slot.xDisplayPosition = pos.x; this.slot.yDisplayPosition = pos.y; @@ -224,9 +226,7 @@ public SlotWidget setEnabled(boolean enabled) { } @Override - public void readOnClient(int id, PacketBuffer buf) { - - } + public void readOnClient(int id, PacketBuffer buf) {} @Override public void readOnServer(int id, PacketBuffer buf) throws IOException { @@ -345,25 +345,37 @@ private void drawSlot(Slot slotIn) { int y = slotIn.yDisplayPosition; ItemStack itemstack = slotIn.getStack(); boolean flag = false; - boolean flag1 = slotIn == getGuiAccessor().getClickedSlot() && getGuiAccessor().getDraggedStack() != null && !getGuiAccessor().getIsRightMouseClick(); + boolean flag1 = slotIn == getGuiAccessor().getClickedSlot() + && getGuiAccessor().getDraggedStack() != null + && !getGuiAccessor().getIsRightMouseClick(); ItemStack itemstack1 = getScreen().mc.thePlayer.inventory.getItemStack(); int amount = -1; String format = null; - if (slotIn == this.getGuiAccessor().getClickedSlot() && getGuiAccessor().getDraggedStack() != null && getGuiAccessor().getIsRightMouseClick() && itemstack != null) { + if (slotIn == this.getGuiAccessor().getClickedSlot() + && getGuiAccessor().getDraggedStack() != null + && getGuiAccessor().getIsRightMouseClick() + && itemstack != null) { itemstack = itemstack.copy(); itemstack.stackSize = itemstack.stackSize / 2; - } else if (getScreen().isDragSplitting2() && getScreen().getDragSlots().contains(slotIn) && itemstack1 != null) { + } else if (getScreen().isDragSplitting2() + && getScreen().getDragSlots().contains(slotIn) + && itemstack1 != null) { if (getScreen().getDragSlots().size() == 1) { return; } // Container#canAddItemToSlot - if (Container.func_94527_a(slotIn, itemstack1, true) && getScreen().inventorySlots.canDragIntoSlot(slotIn)) { + if (Container.func_94527_a(slotIn, itemstack1, true) + && getScreen().inventorySlots.canDragIntoSlot(slotIn)) { itemstack = itemstack1.copy(); flag = true; // Container#computeStackSize - Container.func_94525_a(getScreen().getDragSlots(), getGuiAccessor().getDragSplittingLimit(), itemstack, slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize); + Container.func_94525_a( + getScreen().getDragSlots(), + getGuiAccessor().getDragSplittingLimit(), + itemstack, + slotIn.getStack() == null ? 0 : slotIn.getStack().stackSize); int k = Math.min(itemstack.getMaxStackSize(), slotIn.getSlotStackLimit()); if (itemstack.stackSize > k) { @@ -391,7 +403,14 @@ private void drawSlot(Slot slotIn) { RenderHelper.enableGUIStandardItemLighting(); GlStateManager.enableDepth(); // render the item itself - getScreen().getItemRenderer().renderItemAndEffectIntoGUI(getScreen().getFontRenderer(), Minecraft.getMinecraft().getTextureManager(), itemstack, 1, 1); + getScreen() + .getItemRenderer() + .renderItemAndEffectIntoGUI( + getScreen().getFontRenderer(), + Minecraft.getMinecraft().getTextureManager(), + itemstack, + 1, + 1); if (amount < 0) { amount = itemstack.stackSize; } @@ -426,7 +445,15 @@ private void drawSlot(Slot slotIn) { int cachedCount = itemstack.stackSize; itemstack.stackSize = 1; // required to not render the amount overlay // render other overlays like durability bar - getScreen().getItemRenderer().renderItemOverlayIntoGUI(getScreen().getFontRenderer(), Minecraft.getMinecraft().getTextureManager(), itemstack, 1, 1, null); + getScreen() + .getItemRenderer() + .renderItemOverlayIntoGUI( + getScreen().getFontRenderer(), + Minecraft.getMinecraft().getTextureManager(), + itemstack, + 1, + 1, + null); itemstack.stackSize = cachedCount; GlStateManager.disableDepth(); } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListItem.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListItem.java index 105234a..97c6f4d 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListItem.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListItem.java @@ -9,11 +9,10 @@ import com.gtnewhorizons.modularui.api.widget.IDraggable; import com.gtnewhorizons.modularui.api.widget.IWidgetParent; import com.gtnewhorizons.modularui.api.widget.Widget; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - import java.util.ArrayList; import java.util.List; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class SortableListItem extends Widget implements IWidgetParent, IDraggable { @@ -139,7 +138,8 @@ public void onDragEnd(boolean successful) { public boolean canDropHere(@Nullable Widget widget, boolean isInBounds) { if (widget != null && widget.getParent() instanceof SortableListItem) { SortableListItem listItem = (SortableListItem) widget.getParent(); - return value.getClass().isAssignableFrom(listItem.value.getClass()) && currentIndex != listItem.currentIndex; + return value.getClass().isAssignableFrom(listItem.value.getClass()) + && currentIndex != listItem.currentIndex; } return false; } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListWidget.java index db168d8..5864a91 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SortableListWidget.java @@ -1,9 +1,7 @@ package com.gtnewhorizons.modularui.common.widget; - import com.gtnewhorizons.modularui.ModularUI; import com.gtnewhorizons.modularui.api.widget.Widget; - import java.util.*; import java.util.function.Consumer; import java.util.function.Function; @@ -14,10 +12,8 @@ public class SortableListWidget extends ListWidget { private final Map> widgetMap = new HashMap<>(); private final List startValues; private Function widgetCreator = t -> new TextWidget(t.toString()); - private Consumer> saveFunction = list -> { - }; - private Consumer onRemoveElement = t -> { - }; + private Consumer> saveFunction = list -> {}; + private Consumer onRemoveElement = t -> {}; private boolean elementsRemovable = false; public static SortableListWidget removable(Collection allValues, List startValues) { @@ -72,7 +68,9 @@ public void onPause() { } public List createElements() { - return this.children.stream().map(widget -> ((SortableListItem) widget).getValue()).collect(Collectors.toList()); + return this.children.stream() + .map(widget -> ((SortableListItem) widget).getValue()) + .collect(Collectors.toList()); } protected void removeElement(int index) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/SyncedWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/SyncedWidget.java index b6c0a29..3c1de19 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/SyncedWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/SyncedWidget.java @@ -1,9 +1,9 @@ package com.gtnewhorizons.modularui.common.widget; +import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.JsonHelper; -import com.google.gson.JsonObject; /** * An optional base class for synced widgets. diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/TabButton.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/TabButton.java index cd7f0a6..eb794c9 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/TabButton.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/TabButton.java @@ -3,7 +3,6 @@ import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.widget.Interactable; import com.gtnewhorizons.modularui.api.widget.Widget; - import javax.annotation.Nullable; /** diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/TabContainer.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/TabContainer.java index d48dbb0..c26343f 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/TabContainer.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/TabContainer.java @@ -2,7 +2,6 @@ import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.Widget; - import java.util.ArrayList; import java.util.List; @@ -19,7 +18,6 @@ public class TabContainer extends PageControlWidget { private final List allChildren = new ArrayList<>(); private Size buttonSize = null; - @Override public void initChildren() { allChildren.clear(); @@ -33,7 +31,9 @@ public void onInit() { for (TabButton tabButton : tabButtons) { tabButton.setTabController(this); if (tabButton.getPage() < 0 || tabButton.getPage() >= getPages().size()) { - throw new IndexOutOfBoundsException(String.format("TabButton page is %s, but must be 0 - %s", tabButton.getPage(), getPages().size() - 1)); + throw new IndexOutOfBoundsException(String.format( + "TabButton page is %s, but must be 0 - %s", + tabButton.getPage(), getPages().size() - 1)); } if (buttonSize != null && tabButton.isAutoSized()) { tabButton.setSize(buttonSize); diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/TextWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/TextWidget.java index b89c886..67c0514 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/TextWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/TextWidget.java @@ -1,17 +1,16 @@ package com.gtnewhorizons.modularui.common.widget; +import com.google.gson.JsonObject; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.drawable.TextRenderer; import com.gtnewhorizons.modularui.api.math.Alignment; import com.gtnewhorizons.modularui.api.math.Size; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.internal.Theme; -import com.google.gson.JsonObject; +import java.util.function.Supplier; import net.minecraft.util.EnumChatFormatting; import org.jetbrains.annotations.NotNull; -import java.util.function.Supplier; - /** * Draws text. Accepts some text formatting rules. * See also {@link Text} @@ -55,7 +54,7 @@ public static DynamicTextWidget dynamicString(Supplier supplier) { @Override public void readJson(JsonObject json, String type) { super.readJson(json, type); - //getText().readJson(json); + // getText().readJson(json); } @Override diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/WidgetJsonRegistry.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/WidgetJsonRegistry.java index 4b6b430..751d2f7 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/WidgetJsonRegistry.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/WidgetJsonRegistry.java @@ -1,17 +1,15 @@ package com.gtnewhorizons.modularui.common.widget; import com.gtnewhorizons.modularui.ModularUI; - import com.gtnewhorizons.modularui.api.drawable.IDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.widget.Widget; -import net.minecraft.entity.player.EntityPlayer; - -import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; +import javax.annotation.Nullable; +import net.minecraft.entity.player.EntityPlayer; public class WidgetJsonRegistry { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/BaseTextFieldWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/BaseTextFieldWidget.java index 2cb8508..bb780da 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/BaseTextFieldWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/BaseTextFieldWidget.java @@ -1,6 +1,5 @@ package com.gtnewhorizons.modularui.common.widget.textfield; -import com.gtnewhorizons.modularui.api.widget.scroll.ScrollType; import com.gtnewhorizons.modularui.api.GlStateManager; import com.gtnewhorizons.modularui.api.drawable.GuiHelper; import com.gtnewhorizons.modularui.api.math.Alignment; @@ -9,18 +8,18 @@ import com.gtnewhorizons.modularui.api.widget.Interactable; import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.api.widget.scroll.IHorizontalScrollable; +import com.gtnewhorizons.modularui.api.widget.scroll.ScrollType; import com.gtnewhorizons.modularui.common.widget.ScrollBar; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.util.Util; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.input.Keyboard; - import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.Util; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.input.Keyboard; /** * The base of a text input widget. Handles mouse/keyboard input and rendering. @@ -37,11 +36,14 @@ public class BaseTextFieldWidget extends Widget implements IWidgetParent, Intera * all positive and negative numbers */ public static final Pattern WHOLE_NUMS = Pattern.compile("-?[0-9]*([+\\-*/%^][0-9]*)*"); - public static final Pattern DECIMALS = Pattern.compile("[0-9]*(" + getDecimalSeparator() + "[0-9]*)?([+\\-*/%^][0-9]*(" + getDecimalSeparator() + "[0-9]*)?)*"); + + public static final Pattern DECIMALS = Pattern.compile( + "[0-9]*(" + getDecimalSeparator() + "[0-9]*)?([+\\-*/%^][0-9]*(" + getDecimalSeparator() + "[0-9]*)?)*"); /** * alphabets */ public static final Pattern LETTERS = Pattern.compile("[a-zA-Z]*"); + public static final Pattern ANY = Pattern.compile(".*"); /** * ascii letters @@ -104,13 +106,19 @@ public ClickResult onClick(int buttonId, boolean doubleClick) { if (!isRightBelowMouse()) { return ClickResult.IGNORE; } - handler.setCursor(renderer.getCursorPos(handler.getText(), getContext().getCursor().getX() - pos.x + scrollOffset, getContext().getCursor().getY() - pos.y)); + handler.setCursor(renderer.getCursorPos( + handler.getText(), + getContext().getCursor().getX() - pos.x + scrollOffset, + getContext().getCursor().getY() - pos.y)); return ClickResult.SUCCESS; } @Override public void onMouseDragged(int buttonId, long deltaTime) { - handler.setMainCursor(renderer.getCursorPos(handler.getText(), getContext().getCursor().getX() - pos.x + scrollOffset, getContext().getCursor().getY() - pos.y)); + handler.setMainCursor(renderer.getCursorPos( + handler.getText(), + getContext().getCursor().getX() - pos.x + scrollOffset, + getContext().getCursor().getY() - pos.y)); } @Override @@ -272,15 +280,11 @@ public static char getGroupSeparator() { /** * Returns true if either windows ctrl key is down or if either mac meta key is down */ - public static boolean isCtrlKeyDown() + public static boolean isCtrlKeyDown() { - { - if (IS_RUNNING_ON_MAC) - { + if (IS_RUNNING_ON_MAC) { return Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220); - } - else - { + } else { return Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157); } } @@ -288,36 +292,30 @@ public static boolean isCtrlKeyDown() /** * Returns true if either shift key is down */ - public static boolean isShiftKeyDown() - { + public static boolean isShiftKeyDown() { return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54); } /** * Returns true if either alt key is down */ - public static boolean isAltKeyDown() - { + public static boolean isAltKeyDown() { return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184); } - public static boolean isKeyComboCtrlX(int keyID) - { + public static boolean isKeyComboCtrlX(int keyID) { return keyID == 45 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown(); } - public static boolean isKeyComboCtrlV(int keyID) - { + public static boolean isKeyComboCtrlV(int keyID) { return keyID == 47 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown(); } - public static boolean isKeyComboCtrlC(int keyID) - { + public static boolean isKeyComboCtrlC(int keyID) { return keyID == 46 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown(); } - public static boolean isKeyComboCtrlA(int keyID) - { + public static boolean isKeyComboCtrlA(int keyID) { return keyID == 30 && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown(); } } diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldHandler.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldHandler.java index a08b1fc..e5d3fed 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldHandler.java @@ -2,14 +2,13 @@ import com.google.common.base.Joiner; import com.gtnewhorizons.modularui.common.widget.ScrollBar; -import org.jetbrains.annotations.Nullable; - import java.awt.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; +import org.jetbrains.annotations.Nullable; /** * Handles the text itself like inserting and deleting text. Also handles the cursor and marking text. @@ -21,12 +20,16 @@ public class TextFieldHandler { private final List text = new ArrayList<>(); private final Point cursor = new Point(), cursorEnd = new Point(); private TextFieldRenderer renderer; + @Nullable private ScrollBar scrollBar; + private boolean mainCursorStart = true; private int maxLines = 1; + @Nullable private Pattern pattern; + private int maxCharacters = -1; public void setPattern(@Nullable Pattern pattern) { @@ -89,7 +92,8 @@ public void setMainCursor(int linePos, int charPos) { this.renderer.draw(this.text); this.renderer.setSimulate(false); String line = this.text.get(main.y); - this.scrollBar.setScrollOffsetOfCursor(this.renderer.getPosOf(this.renderer.measureLines(Collections.singletonList(line)), main).x); + this.scrollBar.setScrollOffsetOfCursor( + this.renderer.getPosOf(this.renderer.measureLines(Collections.singletonList(line)), main).x); } } } @@ -217,8 +221,7 @@ public List getText() { return this.text; } - public void onChanged() { - } + public void onChanged() {} public String getSelectedText() { if (!hasTextMarked()) return ""; @@ -239,7 +242,9 @@ public String getSelectedText() { } public boolean test(String text) { - return maxLines > 1 || ((pattern == null || pattern.matcher(text).matches()) && (maxCharacters < 0 || maxCharacters >= text.length())); + return maxLines > 1 + || ((pattern == null || pattern.matcher(text).matches()) + && (maxCharacters < 0 || maxCharacters >= text.length())); } public void insert(String text) { diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldRenderer.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldRenderer.java index 4af30b2..9fbd303 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldRenderer.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldRenderer.java @@ -5,13 +5,12 @@ import com.gtnewhorizons.modularui.api.math.Color; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.renderer.Tessellator; -import org.apache.commons.lang3.tuple.Pair; - import java.awt.*; import java.awt.geom.Point2D; import java.util.Collections; import java.util.List; +import net.minecraft.client.renderer.Tessellator; +import org.apache.commons.lang3.tuple.Pair; public class TextFieldRenderer extends TextRenderer { @@ -93,7 +92,8 @@ public Point getCursorPos(List lines, int x, int y) { int index = (int) (y / (getFontHeight())); if (index < 0) return new Point(); if (index >= measuredLines.size()) - return new Point(measuredLines.get(measuredLines.size() - 1).getKey().length(), measuredLines.size() - 1); + return new Point( + measuredLines.get(measuredLines.size() - 1).getKey().length(), measuredLines.size() - 1); Pair line = measuredLines.get(index); x -= getStartX(line.getValue()) + this.x; if (line.getValue() <= 0) return new Point(0, index); @@ -115,7 +115,9 @@ public Point2D.Float getPosOf(List> measuredLines, Point cur } Pair line = measuredLines.get(cursorPos.y); String sub = line.getKey().substring(0, Math.min(line.getKey().length(), cursorPos.x)); - return new Point2D.Float(getStartX(line.getRight()) + getFontRenderer().getStringWidth(sub) * scale, getStartY(measuredLines.size()) + cursorPos.y * getFontHeight()); + return new Point2D.Float( + getStartX(line.getRight()) + getFontRenderer().getStringWidth(sub) * scale, + getStartY(measuredLines.size()) + cursorPos.y * getFontHeight()); } @SideOnly(Side.CLIENT) @@ -126,8 +128,7 @@ public void drawMarked(float y0, float x0, float x1) { float green = Color.getGreenF(markedColor); float blue = Color.getBlueF(markedColor); float alpha = Color.getAlphaF(markedColor); - if (alpha == 0) - alpha = 1f; + if (alpha == 0) alpha = 1f; Tessellator tessellator = Tessellator.instance; GlStateManager.color(red, green, blue, alpha); GlStateManager.disableTexture2D(); @@ -152,8 +153,7 @@ private void drawCursor(float x0, float y0) { float green = Color.getGreenF(color); float blue = Color.getBlueF(color); float alpha = Color.getAlphaF(color); - if (alpha == 0) - alpha = 1f; + if (alpha == 0) alpha = 1f; Tessellator tessellator = Tessellator.instance; GlStateManager.disableBlend(); GlStateManager.pushMatrix(); diff --git a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldWidget.java b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldWidget.java index eeada23..21201cd 100644 --- a/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldWidget.java +++ b/src/main/java/com/gtnewhorizons/modularui/common/widget/textfield/TextFieldWidget.java @@ -1,19 +1,18 @@ package com.gtnewhorizons.modularui.common.widget.textfield; -import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import com.gtnewhorizons.modularui.api.GlStateManager; import com.gtnewhorizons.modularui.api.drawable.GuiHelper; import com.gtnewhorizons.modularui.api.math.MathExpression; import com.gtnewhorizons.modularui.api.widget.ISyncedWidget; -import net.minecraft.network.PacketBuffer; -import org.jetbrains.annotations.NotNull; - +import com.gtnewhorizons.modularui.common.internal.network.NetworkUtils; import java.io.IOException; import java.text.ParseException; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.regex.Pattern; +import net.minecraft.network.PacketBuffer; +import org.jetbrains.annotations.NotNull; /** * Text input widget with one line only. Can be synced between client and server. Can handle text validation. @@ -36,8 +35,7 @@ public static Number parse(String num) { } @Override - public void onInit() { - } + public void onInit() {} @Override public void draw(float partialTicks) { @@ -102,10 +100,9 @@ public void detectAndSendChanges(boolean init) { public void readOnClient(int id, PacketBuffer buf) { if (id == 1) { if (!isFocused()) { - try{ + try { setText(buf.readStringFromBuffer(Short.MAX_VALUE)); - } - catch (IOException e){ + } catch (IOException e) { } if (this.setter != null && (this.getter == null || !getText().equals(this.getter.get()))) { @@ -118,10 +115,9 @@ public void readOnClient(int id, PacketBuffer buf) { @Override public void readOnServer(int id, PacketBuffer buf) { if (id == 1) { - try{ + try { setText(buf.readStringFromBuffer(Short.MAX_VALUE)); - } - catch (IOException e){ + } catch (IOException e) { } if (this.setter != null) { @@ -272,5 +268,4 @@ public TextFieldWidget setNumbersLong(Supplier min, Supplier max) { public TextFieldWidget setNumbers(int min, int max) { return setNumbers(val -> Math.min(max, Math.max(min, val))); } - } diff --git a/src/main/java/com/gtnewhorizons/modularui/config/Config.java b/src/main/java/com/gtnewhorizons/modularui/config/Config.java index 59a3679..471b1aa 100644 --- a/src/main/java/com/gtnewhorizons/modularui/config/Config.java +++ b/src/main/java/com/gtnewhorizons/modularui/config/Config.java @@ -1,7 +1,6 @@ package com.gtnewhorizons.modularui.config; import java.io.File; - import net.minecraftforge.common.config.Configuration; public class Config { @@ -30,55 +29,47 @@ public static void syncConfig() { config.setCategoryComment(CATEGORY_DEBUG, "Debug"); openCloseDurationMs = config.get( - CATEGORY_ANIMATIONS, - "openCloseDurationMs", - 250, - "How many milliseconds will it take to draw open/close animation", - 0, - 3000 - ).getInt(); + CATEGORY_ANIMATIONS, + "openCloseDurationMs", + 250, + "How many milliseconds will it take to draw open/close animation", + 0, + 3000) + .getInt(); openCloseFade = config.get( - CATEGORY_ANIMATIONS, - "openCloseFade", - false, - "Whether to draw fade in/out animation on GUI open/close" - ).getBoolean(); + CATEGORY_ANIMATIONS, + "openCloseFade", + false, + "Whether to draw fade in/out animation on GUI open/close") + .getBoolean(); openCloseScale = config.get( - CATEGORY_ANIMATIONS, - "openCloseScale", - true, - "Whether to draw scale in/out animation on GUI open/close" - ).getBoolean(); + CATEGORY_ANIMATIONS, + "openCloseScale", + true, + "Whether to draw scale in/out animation on GUI open/close") + .getBoolean(); openCloseTranslateFromBottom = config.get( - CATEGORY_ANIMATIONS, - "openCloseTranslateFromBottom", - true, - "Whether to draw GUI coming out of / going out to the bottom of the screen on GUI open/close" - ).getBoolean(); + CATEGORY_ANIMATIONS, + "openCloseTranslateFromBottom", + true, + "Whether to draw GUI coming out of / going out to the bottom of the screen on GUI open/close") + .getBoolean(); openCloseRotateFast = config.get( - CATEGORY_ANIMATIONS, - "openCloseRotateFast", - false, - "Whether to draw GUI rotating fast on GUI open/close" - ).getBoolean(); - - smoothProgressbar = config.get( - CATEGORY_ANIMATIONS, - "smoothProgressbar", - true, - "Draw progress bar smoothly" - ).getBoolean(); - - debug = config.get( - CATEGORY_DEBUG, - "debug", - false, - "Enable Debug information" - ).getBoolean(); + CATEGORY_ANIMATIONS, + "openCloseRotateFast", + false, + "Whether to draw GUI rotating fast on GUI open/close") + .getBoolean(); + + smoothProgressbar = config.get(CATEGORY_ANIMATIONS, "smoothProgressbar", true, "Draw progress bar smoothly") + .getBoolean(); + + debug = config.get(CATEGORY_DEBUG, "debug", false, "Enable Debug information") + .getBoolean(); if (config.hasChanged()) { config.save(); diff --git a/src/main/java/com/gtnewhorizons/modularui/config/GuiFactory.java b/src/main/java/com/gtnewhorizons/modularui/config/GuiFactory.java index e7dc056..e9536df 100644 --- a/src/main/java/com/gtnewhorizons/modularui/config/GuiFactory.java +++ b/src/main/java/com/gtnewhorizons/modularui/config/GuiFactory.java @@ -1,18 +1,15 @@ package com.gtnewhorizons.modularui.config; import cpw.mods.fml.client.IModGuiFactory; +import java.util.Set; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import java.util.Set; - @SuppressWarnings("unused") public class GuiFactory implements IModGuiFactory { @Override - public void initialize(Minecraft minecraftInstance) { - - } + public void initialize(Minecraft minecraftInstance) {} @Override public Class mainConfigGuiClass() { diff --git a/src/main/java/com/gtnewhorizons/modularui/config/ModularUIGuiConfig.java b/src/main/java/com/gtnewhorizons/modularui/config/ModularUIGuiConfig.java index fbee147..2afeb7a 100644 --- a/src/main/java/com/gtnewhorizons/modularui/config/ModularUIGuiConfig.java +++ b/src/main/java/com/gtnewhorizons/modularui/config/ModularUIGuiConfig.java @@ -3,24 +3,23 @@ import com.gtnewhorizons.modularui.ModularUI; import cpw.mods.fml.client.config.GuiConfig; import cpw.mods.fml.client.config.IConfigElement; -import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.common.config.ConfigElement; - import java.util.ArrayList; import java.util.List; import java.util.Locale; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; @SuppressWarnings("rawtypes") public class ModularUIGuiConfig extends GuiConfig { public ModularUIGuiConfig(GuiScreen parentScreen) { super( - parentScreen, - getConfigElements(), - ModularUI.MODID, - false, - false, - GuiConfig.getAbridgedConfigPath(Config.config.toString())); + parentScreen, + getConfigElements(), + ModularUI.MODID, + false, + false, + GuiConfig.getAbridgedConfigPath(Config.config.toString())); } private static List getConfigElements() { diff --git a/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIHandler.java b/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIHandler.java index 0086541..2dbbcf5 100644 --- a/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIHandler.java +++ b/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIHandler.java @@ -1,24 +1,25 @@ -//package com.gtnewhorizons.modularui.integration.jei; +// package com.gtnewhorizons.modularui.integration.jei; // -//import com.gtnewhorizons.modularui.api.screen.ModularWindow; -//import com.gtnewhorizons.modularui.api.widget.IGhostIngredientTarget; -//import com.gtnewhorizons.modularui.api.widget.IIngredientProvider; -//import com.gtnewhorizons.modularui.api.widget.IWidgetParent; -//import com.gtnewhorizons.modularui.api.widget.Widget; -//import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; -//import mezz.jei.api.gui.IAdvancedGuiHandler; -//import mezz.jei.api.gui.IGhostIngredientHandler; -//import mezz.jei.api.gui.IGuiProperties; -//import mezz.jei.api.gui.IGuiScreenHandler; -//import mezz.jei.gui.overlay.GuiProperties; -//import org.jetbrains.annotations.NotNull; -//import org.jetbrains.annotations.Nullable; +// import com.gtnewhorizons.modularui.api.screen.ModularWindow; +// import com.gtnewhorizons.modularui.api.widget.IGhostIngredientTarget; +// import com.gtnewhorizons.modularui.api.widget.IIngredientProvider; +// import com.gtnewhorizons.modularui.api.widget.IWidgetParent; +// import com.gtnewhorizons.modularui.api.widget.Widget; +// import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +// import mezz.jei.api.gui.IAdvancedGuiHandler; +// import mezz.jei.api.gui.IGhostIngredientHandler; +// import mezz.jei.api.gui.IGuiProperties; +// import mezz.jei.api.gui.IGuiScreenHandler; +// import mezz.jei.gui.overlay.GuiProperties; +// import org.jetbrains.annotations.NotNull; +// import org.jetbrains.annotations.Nullable; // -//import java.awt.*; -//import java.util.LinkedList; -//import java.util.List; +// import java.awt.*; +// import java.util.LinkedList; +// import java.util.List; // -//public class ModularUIHandler implements IAdvancedGuiHandler, IGhostIngredientHandler, IGuiScreenHandler { +// public class ModularUIHandler implements IAdvancedGuiHandler, IGhostIngredientHandler, +// IGuiScreenHandler { // // @Override // public @NotNull Class getGuiContainerClass() { @@ -64,4 +65,4 @@ // public IGuiProperties apply(@NotNull ModularGui guiScreen) { // return guiScreen.getContext().doShowJei() ? GuiProperties.create(guiScreen) : null; // } -//} +// } diff --git a/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIJeiPlugin.java b/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIJeiPlugin.java index b951e9e..0019544 100644 --- a/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIJeiPlugin.java +++ b/src/main/java/com/gtnewhorizons/modularui/integration/jei/ModularUIJeiPlugin.java @@ -1,13 +1,13 @@ -//package com.gtnewhorizons.modularui.integration.jei; +// package com.gtnewhorizons.modularui.integration.jei; // -//import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; -//import mezz.jei.api.IModPlugin; -//import mezz.jei.api.IModRegistry; -//import mezz.jei.api.JEIPlugin; -//import org.jetbrains.annotations.NotNull; +// import com.gtnewhorizons.modularui.common.internal.wrapper.ModularGui; +// import mezz.jei.api.IModPlugin; +// import mezz.jei.api.IModRegistry; +// import mezz.jei.api.JEIPlugin; +// import org.jetbrains.annotations.NotNull; // -//@JEIPlugin -//public class ModularUIJeiPlugin implements IModPlugin { +// @JEIPlugin +// public class ModularUIJeiPlugin implements IModPlugin { // // @Override // public void register(@NotNull IModRegistry registry) { @@ -16,4 +16,4 @@ // registry.addGhostIngredientHandler(ModularGui.class, uiHandler); // registry.addGuiScreenHandler(ModularGui.class, uiHandler); // } -//} +// } diff --git a/src/main/java/com/gtnewhorizons/modularui/mixins/GuiContainerMixin.java b/src/main/java/com/gtnewhorizons/modularui/mixins/GuiContainerMixin.java index db395e8..51ca08b 100644 --- a/src/main/java/com/gtnewhorizons/modularui/mixins/GuiContainerMixin.java +++ b/src/main/java/com/gtnewhorizons/modularui/mixins/GuiContainerMixin.java @@ -1,5 +1,6 @@ package com.gtnewhorizons.modularui.mixins; +import java.util.Set; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -7,8 +8,6 @@ import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Invoker; -import java.util.Set; - @Mixin(GuiContainer.class) public interface GuiContainerMixin { diff --git a/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindAccess.java b/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindAccess.java index 49e2f93..8c0932d 100644 --- a/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindAccess.java +++ b/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindAccess.java @@ -5,8 +5,6 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import java.util.Set; - @Mixin(KeyBinding.class) public interface KeyBindAccess { diff --git a/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindMixin.java b/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindMixin.java index 9da97ba..990d550 100644 --- a/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindMixin.java +++ b/src/main/java/com/gtnewhorizons/modularui/mixins/KeyBindMixin.java @@ -1,19 +1,19 @@ -//package com.gtnewhorizons.modularui.core.mixin; +// package com.gtnewhorizons.modularui.core.mixin; // -//import com.gtnewhorizons.modularui.api.KeyBindAPI; -//import com.gtnewhorizons.modularui.common.keybind.KeyBindHandler; -//import com.gtnewhorizons.modularui.api.KeyBindAPI; -//import net.minecraft.client.settings.KeyBinding; -//import org.spongepowered.asm.mixin.Mixin; -//import org.spongepowered.asm.mixin.Overwrite; -//import org.spongepowered.asm.mixin.injection.At; -//import org.spongepowered.asm.mixin.injection.Inject; -//import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +// import com.gtnewhorizons.modularui.api.KeyBindAPI; +// import com.gtnewhorizons.modularui.common.keybind.KeyBindHandler; +// import com.gtnewhorizons.modularui.api.KeyBindAPI; +// import net.minecraft.client.settings.KeyBinding; +// import org.spongepowered.asm.mixin.Mixin; +// import org.spongepowered.asm.mixin.Overwrite; +// import org.spongepowered.asm.mixin.injection.At; +// import org.spongepowered.asm.mixin.injection.Inject; +// import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; // -//import java.util.Collection; +// import java.util.Collection; // -//@Mixin(KeyBinding.class) -//public class KeyBindMixin { +// @Mixin(KeyBinding.class) +// public class KeyBindMixin { // // @Inject(method = "conflicts", at = @At("HEAD"), cancellable = true, remap = false) // public void conflicts(KeyBinding other, CallbackInfoReturnable cir) { @@ -42,4 +42,4 @@ // } // } // } -//} +// } diff --git a/src/main/java/com/gtnewhorizons/modularui/mixins/SPacketSetSlotMixin.java b/src/main/java/com/gtnewhorizons/modularui/mixins/SPacketSetSlotMixin.java index ee30996..cfcb0f9 100644 --- a/src/main/java/com/gtnewhorizons/modularui/mixins/SPacketSetSlotMixin.java +++ b/src/main/java/com/gtnewhorizons/modularui/mixins/SPacketSetSlotMixin.java @@ -1,18 +1,18 @@ -//package com.gtnewhorizons.modularui.core.mixin; +// package com.gtnewhorizons.modularui.core.mixin; // -//import net.minecraft.item.ItemStack; -//import net.minecraft.network.PacketBuffer; -//import net.minecraft.network.play.server.SPacketSetSlot; -//import org.spongepowered.asm.mixin.Mixin; -//import org.spongepowered.asm.mixin.Shadow; -//import org.spongepowered.asm.mixin.injection.At; -//import org.spongepowered.asm.mixin.injection.Inject; -//import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +// import net.minecraft.item.ItemStack; +// import net.minecraft.network.PacketBuffer; +// import net.minecraft.network.play.server.SPacketSetSlot; +// import org.spongepowered.asm.mixin.Mixin; +// import org.spongepowered.asm.mixin.Shadow; +// import org.spongepowered.asm.mixin.injection.At; +// import org.spongepowered.asm.mixin.injection.Inject; +// import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // -//import java.io.IOException; +// import java.io.IOException; // -//@Mixin(SPacketSetSlot.class) -//public class SPacketSetSlotMixin { +// @Mixin(SPacketSetSlot.class) +// public class SPacketSetSlotMixin { // // @Shadow // private ItemStack item; @@ -26,4 +26,4 @@ // public void writePacketData(PacketBuffer buf, CallbackInfo ci) throws IOException { // buf.writeVarInt(item.getCount()); // } -//} +// } diff --git a/src/main/java/com/gtnewhorizons/modularui/test/SyncedTileEntityBase.java b/src/main/java/com/gtnewhorizons/modularui/test/SyncedTileEntityBase.java index 290e2df..aa285e1 100644 --- a/src/main/java/com/gtnewhorizons/modularui/test/SyncedTileEntityBase.java +++ b/src/main/java/com/gtnewhorizons/modularui/test/SyncedTileEntityBase.java @@ -2,6 +2,11 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import javax.annotation.Nonnull; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; @@ -10,12 +15,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants.NBT; -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.function.Consumer; - public abstract class SyncedTileEntityBase extends TileEntity { public abstract void writeInitialSyncData(PacketBuffer buf); @@ -91,5 +90,4 @@ public void readFromNBT(@Nonnull NBTTagCompound tag) { ByteBuf backedBuffer = Unpooled.copiedBuffer(updateData); receiveInitialSyncData(new PacketBuffer(backedBuffer)); } - } diff --git a/src/main/java/com/gtnewhorizons/modularui/test/TestBlock.java b/src/main/java/com/gtnewhorizons/modularui/test/TestBlock.java index eaf4744..2581954 100644 --- a/src/main/java/com/gtnewhorizons/modularui/test/TestBlock.java +++ b/src/main/java/com/gtnewhorizons/modularui/test/TestBlock.java @@ -1,6 +1,7 @@ package com.gtnewhorizons.modularui.test; import com.gtnewhorizons.modularui.api.UIInfos; +import javax.annotation.Nullable; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; @@ -9,8 +10,6 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; -import javax.annotation.Nullable; - public class TestBlock extends Block implements ITileEntityProvider { public TestBlock(Material p_i45394_1_) { @@ -24,10 +23,19 @@ public TileEntity createNewTileEntity(World worldIn, int meta) { } @Override - public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) - { + public boolean onBlockActivated( + World p_149727_1_, + int p_149727_2_, + int p_149727_3_, + int p_149727_4_, + EntityPlayer p_149727_5_, + int p_149727_6_, + float p_149727_7_, + float p_149727_8_, + float p_149727_9_) { if (!p_149727_1_.isRemote) { - UIInfos.TILE_MODULAR_UI.open(p_149727_5_, p_149727_1_, Vec3.createVectorHelper(p_149727_2_, p_149727_3_, p_149727_4_)); + UIInfos.TILE_MODULAR_UI.open( + p_149727_5_, p_149727_1_, Vec3.createVectorHelper(p_149727_2_, p_149727_3_, p_149727_4_)); } return true; } diff --git a/src/main/java/com/gtnewhorizons/modularui/test/TestTile.java b/src/main/java/com/gtnewhorizons/modularui/test/TestTile.java index 4cb48ee..013a050 100644 --- a/src/main/java/com/gtnewhorizons/modularui/test/TestTile.java +++ b/src/main/java/com/gtnewhorizons/modularui/test/TestTile.java @@ -1,9 +1,9 @@ package com.gtnewhorizons.modularui.test; - import com.gtnewhorizons.modularui.ModularUI; import com.gtnewhorizons.modularui.api.ModularUITextures; import com.gtnewhorizons.modularui.api.drawable.AdaptableUITexture; +import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; import com.gtnewhorizons.modularui.api.drawable.Text; import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.forge.ItemStackHandler; @@ -13,8 +13,11 @@ import com.gtnewhorizons.modularui.api.math.MainAxisAlignment; import com.gtnewhorizons.modularui.api.math.Pos2d; import com.gtnewhorizons.modularui.api.math.Size; +import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; +import com.gtnewhorizons.modularui.api.widget.Widget; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; import com.gtnewhorizons.modularui.common.widget.ChangeableWidget; import com.gtnewhorizons.modularui.common.widget.Column; @@ -34,10 +37,9 @@ import com.gtnewhorizons.modularui.common.widget.TabContainer; import com.gtnewhorizons.modularui.common.widget.TextWidget; import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget; -import com.gtnewhorizons.modularui.api.drawable.ItemDrawable; -import com.gtnewhorizons.modularui.api.screen.ITileWithModularUI; -import com.gtnewhorizons.modularui.api.widget.IWidgetBuilder; -import com.gtnewhorizons.modularui.api.widget.Widget; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; @@ -48,10 +50,6 @@ import net.minecraftforge.fluids.FluidTank; import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - public class TestTile extends SyncedTileEntityBase implements ITileWithModularUI { private int serverValue = 0; @@ -70,47 +68,57 @@ public int getSlotLimit(int slot) { private int ticks = 0; private float sliderValue = 0; private int serverCounter = 0; - private static final AdaptableUITexture DISPLAY = AdaptableUITexture.of("modularui:gui/background/display", 143, 75, 2); - private static final AdaptableUITexture BACKGROUND = AdaptableUITexture.of("modularui:gui/background/background", 176, 166, 3); + private static final AdaptableUITexture DISPLAY = + AdaptableUITexture.of("modularui:gui/background/display", 143, 75, 2); + private static final AdaptableUITexture BACKGROUND = + AdaptableUITexture.of("modularui:gui/background/background", 176, 166, 3); private static final UITexture PROGRESS_BAR = UITexture.fullImage("modularui", "gui/widgets/progress_bar_arrow"); - private static final UITexture PROGRESS_BAR_MIXER = UITexture.fullImage("modularui", "gui/widgets/progress_bar_mixer"); + private static final UITexture PROGRESS_BAR_MIXER = + UITexture.fullImage("modularui", "gui/widgets/progress_bar_mixer"); @Override public ModularWindow createWindow(UIBuildContext buildContext) { phantomInventory.setStackInSlot(1, new ItemStack(Items.diamond, Integer.MAX_VALUE)); - Text[] TEXT = {new Text("Blue \u00a7nUnderlined\u00a7rBlue ").color(0x3058B8), new Text("Mint").color(0x469E8F)}; + Text[] TEXT = {new Text("Blue \u00a7nUnderlined\u00a7rBlue ").color(0x3058B8), new Text("Mint").color(0x469E8F) + }; ModularWindow.Builder builder = ModularWindow.builder(new Size(176, 272)); - //.addFromJson("modularui:test", buildContext); + // .addFromJson("modularui:test", buildContext); /*buildContext.applyToWidget("background", DrawableWidget.class, widget -> { widget.addTooltip("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.") .addTooltip("Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.") .addTooltip("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet"); });*/ List nums = IntStream.range(1, 101).boxed().collect(Collectors.toList()); - builder.setBackground(ModularUITextures.VANILLA_BACKGROUND) - .bindPlayerInventory(buildContext.getPlayer()); + builder.setBackground(ModularUITextures.VANILLA_BACKGROUND).bindPlayerInventory(buildContext.getPlayer()); Column column = new Column(); addInfo(column); ChangeableWidget changeableWidget = new ChangeableWidget(this::dynamicWidget); buildContext.addSyncedWindow(1, this::createAnotherWindow); - return builder - .widget(new TabContainer() + return builder.widget(new TabContainer() .setButtonSize(new Size(28, 32)) .addTabButton(new TabButton(0) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0, 1f, 0.5f)) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0.5f, 1f, 1f)) + .setBackground( + false, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0, 1f, 0.5f)) + .setBackground( + true, ModularUITextures.VANILLA_TAB_TOP_START.getSubArea(0, 0.5f, 1f, 1f)) .setPos(0, -28)) .addTabButton(new TabButton(1) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f)) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f)) + .setBackground( + false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f)) + .setBackground( + true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f)) .setPos(28, -28)) .addTabButton(new TabButton(2) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f)) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f)) + .setBackground( + false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f)) + .setBackground( + true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f)) .setPos(56, -28)) .addTabButton(new TabButton(3) - .setBackground(false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f)) - .setBackground(true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f)) + .setBackground( + false, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0, 1f, 0.5f)) + .setBackground( + true, ModularUITextures.VANILLA_TAB_TOP_MIDDLE.getSubArea(0, 0.5f, 1f, 1f)) .setPos(84, -28)) .addPage(new MultiChildWidget() .addChild(new TextWidget("Page 1")) @@ -118,21 +126,20 @@ public ModularWindow createWindow(UIBuildContext buildContext) { .setChangeListener(() -> { serverCounter = 0; changeableWidget.notifyChangeServer(); - }).setShiftClickPrio(0) + }) + .setShiftClickPrio(0) .setPos(10, 30)) .addChild(SlotWidget.phantom(phantomInventory, 1) .setShiftClickPrio(1) .setIgnoreStackSizeLimit(true) .setPos(28, 30)) - .addChild(changeableWidget - .setPos(12, 55)) + .addChild(changeableWidget.setPos(12, 55)) .addChild(SlotGroup.ofItemHandler(items, 3, false, "inv") .setPos(12, 80)) .setPos(10, 10) .setDebugLabel("Page1")) .addPage(new MultiChildWidget() - .addChild(new TextWidget("Page 2") - .setPos(10, 10)) + .addChild(new TextWidget("Page 2").setPos(10, 10)) .addChild(column.setPos(7, 19)) .addChild(new ButtonWidget() .setOnClick((clickData, widget) -> { @@ -142,7 +149,8 @@ public ModularWindow createWindow(UIBuildContext buildContext) { .setBackground(ModularUITextures.VANILLA_BACKGROUND, new Text("Window")) .setSize(80, 20) .setPos(20, 100)) - .addChild(new ItemDrawable(new ItemStack(Blocks.command_block)).asWidget() + .addChild(new ItemDrawable(new ItemStack(Blocks.command_block)) + .asWidget() .setSize(32, 16) .setPos(20, 80)) .addChild(new SliderWidget() @@ -163,9 +171,15 @@ public ModularWindow createWindow(UIBuildContext buildContext) { .setGetter(() -> serverValue) .setSetter(val -> this.serverValue = val) .setTexture(UITexture.fullImage("modularui", "gui/widgets/cycle_button_demo")) - .addTooltip(0, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.") - .addTooltip(1, "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.") - .addTooltip(2, "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet") + .addTooltip( + 0, + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.") + .addTooltip( + 1, + "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.") + .addTooltip( + 2, + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet") .setPos(new Pos2d(68, 0))) .addChild(new TextFieldWidget() .setGetter(() -> textFieldValue) @@ -201,7 +215,8 @@ public ModularWindow createWindow(UIBuildContext buildContext) { .setDirection(ProgressBar.Direction.CIRCULAR_CW) .setTexture(PROGRESS_BAR_MIXER, 20) .setPos(99, 85)) - .addChild(FluidSlotWidget.phantom(fluidTank2, true).setPos(38, 47)) + .addChild(FluidSlotWidget.phantom(fluidTank2, true) + .setPos(38, 47)) .addChild(new FluidSlotWidget(fluidTank1).setPos(20, 47)) .addChild(new ButtonWidget() .setOnClick((clickData, widget) -> { @@ -226,21 +241,66 @@ public ModularWindow createWindow(UIBuildContext buildContext) { .addChild(new Scrollable() .setHorizontalScroll() .setVerticalScroll() - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(0, 0)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(20, 20)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(40, 40)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(60, 60)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(80, 80)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(100, 100)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(120, 120)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(140, 140)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(160, 160)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(180, 180)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(200, 200)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(220, 220)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(240, 240)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(260, 260)) - .widget(ModularUITextures.ICON_INFO.asWidget().setSize(20, 20).setPos(280, 280)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(0, 0)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(20, 20)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(40, 40)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(60, 60)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(80, 80)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(100, 100)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(120, 120)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(140, 140)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(160, 160)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(180, 180)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(200, 200)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(220, 220)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(240, 240)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(260, 260)) + .widget(ModularUITextures.ICON_INFO + .asWidget() + .setSize(20, 20) + .setPos(280, 280)) .widget(new TextFieldWidget() .setGetter(() -> textFieldValue) .setSetter(val -> textFieldValue = val) @@ -260,7 +320,9 @@ public ModularWindow createWindow(UIBuildContext buildContext) { .setSize(14, 14) .setPos(3, 3)) .widget(new SortableListWidget<>(nums) - .setWidgetCreator(integer -> new TextWidget(integer.toString()).setSize(20, 20).addTooltip(integer.toString())) + .setWidgetCreator(integer -> new TextWidget(integer.toString()) + .setSize(20, 20) + .addTooltip(integer.toString())) .setSize(50, 135) .setPos(5, 20)) .setExpandedSize(60, 160) @@ -283,8 +345,7 @@ public ModularWindow createAnotherWindow(EntityPlayer player) { public > void addInfo(T builder) { builder.widget(new TextWidget(new Text("Probably a Machine Name").color(0x13610C))) - .widget(new TextWidget("Invalid Structure or whatever") - .addTooltip("This has a tooltip")); + .widget(new TextWidget("Invalid Structure or whatever").addTooltip("This has a tooltip")); if (true) { builder.widget(new TextWidget("Maintanance Problems")); } @@ -324,9 +385,7 @@ public void receiveInitialSyncData(PacketBuffer buf) { } @Override - public void receiveCustomData(int discriminator, PacketBuffer buf) { - - } + public void receiveCustomData(int discriminator, PacketBuffer buf) {} @Override public void writeToNBT(NBTTagCompound nbt) {