From 4e5d978ce4d99a7a46a1c0429688b157b8219249 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sat, 27 May 2023 15:03:31 +0200 Subject: [PATCH 01/51] first working in world screen --- .../modularui/test/ModularScreenEntity.java | 98 +++++++++++++++++++ .../modularui/test/ScreenEntityRender.java | 35 +++++++ 2 files changed, 133 insertions(+) create mode 100644 src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java create mode 100644 src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java diff --git a/src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java b/src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java new file mode 100644 index 000000000..4299d5c06 --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java @@ -0,0 +1,98 @@ +package com.cleanroommc.modularui.test; + +import com.cleanroommc.modularui.screen.GuiScreenWrapper; +import com.cleanroommc.modularui.screen.ModularContainer; +import com.cleanroommc.modularui.screen.ModularScreen; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.jetbrains.annotations.NotNull; + +public class ModularScreenEntity extends Entity { + + private GuiScreenWrapper wrapper; + private ModularScreen screen; + + public ModularScreenEntity(World worldIn) { + super(worldIn); + } + + public void setScreen(ModularScreen screen) { + this.screen = screen; + this.wrapper = new GuiScreenWrapper(new ModularContainer(), screen); + ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + int i = scaledresolution.getScaledWidth(); + int j = scaledresolution.getScaledHeight(); + this.wrapper.setWorldAndResolution(Minecraft.getMinecraft(), i, j); + } + + public ModularScreen getScreen() { + return screen; + } + + public GuiScreenWrapper getWrapper() { + return wrapper; + } + + public void spawnInWorld() { + getEntityWorld().spawnEntity(this); + } + + @Override + protected void entityInit() { + + } + + @Override + protected void readEntityFromNBT(@NotNull NBTTagCompound compound) { + + } + + @Override + protected void writeEntityToNBT(@NotNull NBTTagCompound compound) { + + } + + @Override + public boolean doesEntityNotTriggerPressurePlate() { + return true; + } + + @Override + public boolean isImmuneToExplosions() { + return true; + } + + @Override + public boolean isCreatureType(@NotNull EnumCreatureType type, boolean forSpawnCount) { + return false; + } + + @Override + public boolean canTrample(@NotNull World world, @NotNull Block block, @NotNull BlockPos pos, float fallDistance) { + return false; + } + + @Override + protected boolean canBeRidden(@NotNull Entity entityIn) { + return false; + } + + @Override + public boolean shouldRenderInPass(int pass) { + return pass == 1; + } + + @SideOnly(Side.CLIENT) + @Override + public int getBrightnessForRender(){ + return 15728880; + } +} diff --git a/src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java new file mode 100644 index 000000000..9c31f2d50 --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java @@ -0,0 +1,35 @@ +package com.cleanroommc.modularui.test; + +import com.cleanroommc.modularui.screen.GuiScreenWrapper; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.util.ResourceLocation; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ScreenEntityRender extends Render { + + public ScreenEntityRender(RenderManager renderManager) { + super(renderManager); + } + + @Nullable + @Override + protected ResourceLocation getEntityTexture(@NotNull ModularScreenEntity entity) { + return null; + } + + @Override + public void doRender(@NotNull ModularScreenEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { + GuiScreenWrapper screenWrapper = entity.getWrapper(); + if (screenWrapper == null) return; + + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, z); + GlStateManager.scale(0.02, 0.02, 0.02); + GlStateManager.rotate(180, 0, 0, 1); + screenWrapper.drawScreen(Integer.MIN_VALUE, Integer.MIN_VALUE, partialTicks); + GlStateManager.popMatrix(); + } +} From ca4eb9bffbdb71f0a968db9d6f642358122fb53e Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sun, 28 May 2023 18:23:20 +0200 Subject: [PATCH 02/51] replace scissor with stencil masks --- .../modularui/drawable/Scissor.java | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/main/java/com/cleanroommc/modularui/drawable/Scissor.java diff --git a/src/main/java/com/cleanroommc/modularui/drawable/Scissor.java b/src/main/java/com/cleanroommc/modularui/drawable/Scissor.java new file mode 100644 index 000000000..ea1220bfc --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/drawable/Scissor.java @@ -0,0 +1,152 @@ +package com.cleanroommc.modularui.drawable; + +import com.cleanroommc.modularui.api.layout.IViewportStack; +import com.cleanroommc.modularui.screen.viewport.GuiContext; +import com.cleanroommc.modularui.utils.Color; +import com.cleanroommc.modularui.widget.sizer.Area; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.opengl.GL11; + +import java.util.Stack; + +public class Scissor { + + private final static Stack rawScissors = new Stack<>(); + private final static Stack scissors = new Stack<>(); + private static int stencilValue = 0; + + public static void reset() { + scissors.clear(); + stencilValue = 0; + GL11.glStencilMask(0xFF); + GL11.glClearStencil(0); + GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT); + GL11.glStencilFunc(GL11.GL_ALWAYS, 0, 0xFF); + GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); + GL11.glStencilMask(0x00); + } + + public static void scissor(Area area, @Nullable GuiContext context) { + scissor(area.x, area.y, area.width, area.height, context); + } + + public static void scissorAtZero(Area area, @Nullable GuiContext context) { + scissor(0, 0, area.width, area.height, context); + } + + public static void scissorTransformed(Area area) { + scissorTransformed(area.x, area.y, area.width, area.height); + } + + public static void scissorTransformed(int x, int y, int w, int h) { + scissor(x, y, w, h, null); + } + + /** + * Scissor a transformed part of the screen. + * OpenGL's transformations do effect these values. + * If the context is not null, it's viewport transformations are applied to the area that will be stored in the stack, + * but not to the actual stencil. + */ + public static void scissor(int x, int y, int w, int h, @Nullable GuiContext context) { + Area rawScissor = new Area(x, y, w, h); + Area scissor = rawScissor.createCopy(); + if (context != null) { + scissor.transformAndRectanglerize(context); + } + if (!scissors.isEmpty()) { + scissors.peek().clamp(scissor); + } + scissorArea(x, y, w, h); + scissors.add(scissor); + rawScissors.add(rawScissor); + } + + private static void scissorArea(int x, int y, int w, int h) { + // increase stencil values in the area + setStencilValue(x, y, w, h, stencilValue, Mode.INCR); + stencilValue++; + GL11.glStencilFunc(GL11.GL_LEQUAL, stencilValue, 0xFF); + GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); + GL11.glStencilMask(0x00); + + //GuiDraw.drawRect(x - 100, y - 100, w + 200, h + 200, Color.withAlpha(Color.BLUE.normal, 0.3f)); + } + + private static void setStencilValue(int x, int y, int w, int h, int stencilValue, Mode mode) { + // Set stencil func + mode.stencilFunc(stencilValue); + GL11.glStencilMask(0xFF); + // Draw masking shape + if (mode != Mode.SET) { + GuiDraw.drawRect(x, y, w, h, Color.withAlpha(Color.GREEN.normal, 0.15f)); + } else { + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + float x0 = x, x1 = x + w, y0 = y, y1 = y + h; + bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); + bufferbuilder.pos(x0, y0, 0.0f).endVertex(); + bufferbuilder.pos(x0, y1, 0.0f).endVertex(); + bufferbuilder.pos(x1, y1, 0.0f).endVertex(); + bufferbuilder.pos(x1, y0, 0.0f).endVertex(); + tessellator.draw(); + } + + // Re-enable drawing to color buffer + depth buffer + GlStateManager.colorMask(true, true, true, true); + GlStateManager.depthMask(true); + } + + public static void unscissor(GuiContext context) { + scissors.pop(); + Area area = rawScissors.pop(); + if (scissors.isEmpty()) { + reset(); + return; + } + setStencilValue(0, 0, area.width, area.height, stencilValue, Mode.DECR); + stencilValue--; + GL11.glStencilFunc(GL11.GL_LEQUAL, stencilValue, 0xFF); + GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); + GL11.glStencilMask(0x00); + } + + public static boolean isInsideScissorArea(Area area, IViewportStack stack) { + if (scissors.isEmpty()) return true; + Area.SHARED.set(0, 0, area.width, area.height); + Area.SHARED.transformAndRectanglerize(stack); + return scissors.peek().intersects(Area.SHARED); + } + + public enum Mode { + + SET { + @Override + void stencilFunc(int stencilValue) { + GL11.glStencilFunc(GL11.GL_ALWAYS, stencilValue, 0xFF); + GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE); + } + }, + INCR { + @Override + void stencilFunc(int stencilValue) { + GL11.glStencilFunc(GL11.GL_EQUAL, stencilValue, 0xFF); + GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_INCR, GL11.GL_INCR); + } + }, + DECR { + @Override + void stencilFunc(int stencilValue) { + GL11.glStencilFunc(GL11.GL_EQUAL, stencilValue, 0xFF); + GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_DECR, GL11.GL_DECR); + } + }; + + void stencilFunc(int stencilValue) { + } + } +} From c5b777e28aa1c3ae54dba2b4aa98f77cd0c22387 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sun, 28 May 2023 19:25:11 +0200 Subject: [PATCH 03/51] fixes and rename stuff --- .../modularui/drawable/Scissor.java | 152 ------------------ 1 file changed, 152 deletions(-) delete mode 100644 src/main/java/com/cleanroommc/modularui/drawable/Scissor.java diff --git a/src/main/java/com/cleanroommc/modularui/drawable/Scissor.java b/src/main/java/com/cleanroommc/modularui/drawable/Scissor.java deleted file mode 100644 index ea1220bfc..000000000 --- a/src/main/java/com/cleanroommc/modularui/drawable/Scissor.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.cleanroommc.modularui.drawable; - -import com.cleanroommc.modularui.api.layout.IViewportStack; -import com.cleanroommc.modularui.screen.viewport.GuiContext; -import com.cleanroommc.modularui.utils.Color; -import com.cleanroommc.modularui.widget.sizer.Area; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.opengl.GL11; - -import java.util.Stack; - -public class Scissor { - - private final static Stack rawScissors = new Stack<>(); - private final static Stack scissors = new Stack<>(); - private static int stencilValue = 0; - - public static void reset() { - scissors.clear(); - stencilValue = 0; - GL11.glStencilMask(0xFF); - GL11.glClearStencil(0); - GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT); - GL11.glStencilFunc(GL11.GL_ALWAYS, 0, 0xFF); - GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); - GL11.glStencilMask(0x00); - } - - public static void scissor(Area area, @Nullable GuiContext context) { - scissor(area.x, area.y, area.width, area.height, context); - } - - public static void scissorAtZero(Area area, @Nullable GuiContext context) { - scissor(0, 0, area.width, area.height, context); - } - - public static void scissorTransformed(Area area) { - scissorTransformed(area.x, area.y, area.width, area.height); - } - - public static void scissorTransformed(int x, int y, int w, int h) { - scissor(x, y, w, h, null); - } - - /** - * Scissor a transformed part of the screen. - * OpenGL's transformations do effect these values. - * If the context is not null, it's viewport transformations are applied to the area that will be stored in the stack, - * but not to the actual stencil. - */ - public static void scissor(int x, int y, int w, int h, @Nullable GuiContext context) { - Area rawScissor = new Area(x, y, w, h); - Area scissor = rawScissor.createCopy(); - if (context != null) { - scissor.transformAndRectanglerize(context); - } - if (!scissors.isEmpty()) { - scissors.peek().clamp(scissor); - } - scissorArea(x, y, w, h); - scissors.add(scissor); - rawScissors.add(rawScissor); - } - - private static void scissorArea(int x, int y, int w, int h) { - // increase stencil values in the area - setStencilValue(x, y, w, h, stencilValue, Mode.INCR); - stencilValue++; - GL11.glStencilFunc(GL11.GL_LEQUAL, stencilValue, 0xFF); - GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); - GL11.glStencilMask(0x00); - - //GuiDraw.drawRect(x - 100, y - 100, w + 200, h + 200, Color.withAlpha(Color.BLUE.normal, 0.3f)); - } - - private static void setStencilValue(int x, int y, int w, int h, int stencilValue, Mode mode) { - // Set stencil func - mode.stencilFunc(stencilValue); - GL11.glStencilMask(0xFF); - // Draw masking shape - if (mode != Mode.SET) { - GuiDraw.drawRect(x, y, w, h, Color.withAlpha(Color.GREEN.normal, 0.15f)); - } else { - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder bufferbuilder = tessellator.getBuffer(); - float x0 = x, x1 = x + w, y0 = y, y1 = y + h; - bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); - bufferbuilder.pos(x0, y0, 0.0f).endVertex(); - bufferbuilder.pos(x0, y1, 0.0f).endVertex(); - bufferbuilder.pos(x1, y1, 0.0f).endVertex(); - bufferbuilder.pos(x1, y0, 0.0f).endVertex(); - tessellator.draw(); - } - - // Re-enable drawing to color buffer + depth buffer - GlStateManager.colorMask(true, true, true, true); - GlStateManager.depthMask(true); - } - - public static void unscissor(GuiContext context) { - scissors.pop(); - Area area = rawScissors.pop(); - if (scissors.isEmpty()) { - reset(); - return; - } - setStencilValue(0, 0, area.width, area.height, stencilValue, Mode.DECR); - stencilValue--; - GL11.glStencilFunc(GL11.GL_LEQUAL, stencilValue, 0xFF); - GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP); - GL11.glStencilMask(0x00); - } - - public static boolean isInsideScissorArea(Area area, IViewportStack stack) { - if (scissors.isEmpty()) return true; - Area.SHARED.set(0, 0, area.width, area.height); - Area.SHARED.transformAndRectanglerize(stack); - return scissors.peek().intersects(Area.SHARED); - } - - public enum Mode { - - SET { - @Override - void stencilFunc(int stencilValue) { - GL11.glStencilFunc(GL11.GL_ALWAYS, stencilValue, 0xFF); - GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE); - } - }, - INCR { - @Override - void stencilFunc(int stencilValue) { - GL11.glStencilFunc(GL11.GL_EQUAL, stencilValue, 0xFF); - GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_INCR, GL11.GL_INCR); - } - }, - DECR { - @Override - void stencilFunc(int stencilValue) { - GL11.glStencilFunc(GL11.GL_EQUAL, stencilValue, 0xFF); - GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_DECR, GL11.GL_DECR); - } - }; - - void stencilFunc(int stencilValue) { - } - } -} From 92c0f4906eaeb41dbc6919a29bf6d8de293a7405 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Thu, 1 Jun 2023 18:18:21 +0200 Subject: [PATCH 04/51] holo ui's can face any direction... somewhat --- .../modularui/test/ModularScreenEntity.java | 98 ------------------- .../modularui/test/ScreenEntityRender.java | 35 ------- 2 files changed, 133 deletions(-) delete mode 100644 src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java delete mode 100644 src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java diff --git a/src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java b/src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java deleted file mode 100644 index 4299d5c06..000000000 --- a/src/main/java/com/cleanroommc/modularui/test/ModularScreenEntity.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.cleanroommc.modularui.test; - -import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import com.cleanroommc.modularui.screen.ModularContainer; -import com.cleanroommc.modularui.screen.ModularScreen; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EnumCreatureType; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import org.jetbrains.annotations.NotNull; - -public class ModularScreenEntity extends Entity { - - private GuiScreenWrapper wrapper; - private ModularScreen screen; - - public ModularScreenEntity(World worldIn) { - super(worldIn); - } - - public void setScreen(ModularScreen screen) { - this.screen = screen; - this.wrapper = new GuiScreenWrapper(new ModularContainer(), screen); - ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int i = scaledresolution.getScaledWidth(); - int j = scaledresolution.getScaledHeight(); - this.wrapper.setWorldAndResolution(Minecraft.getMinecraft(), i, j); - } - - public ModularScreen getScreen() { - return screen; - } - - public GuiScreenWrapper getWrapper() { - return wrapper; - } - - public void spawnInWorld() { - getEntityWorld().spawnEntity(this); - } - - @Override - protected void entityInit() { - - } - - @Override - protected void readEntityFromNBT(@NotNull NBTTagCompound compound) { - - } - - @Override - protected void writeEntityToNBT(@NotNull NBTTagCompound compound) { - - } - - @Override - public boolean doesEntityNotTriggerPressurePlate() { - return true; - } - - @Override - public boolean isImmuneToExplosions() { - return true; - } - - @Override - public boolean isCreatureType(@NotNull EnumCreatureType type, boolean forSpawnCount) { - return false; - } - - @Override - public boolean canTrample(@NotNull World world, @NotNull Block block, @NotNull BlockPos pos, float fallDistance) { - return false; - } - - @Override - protected boolean canBeRidden(@NotNull Entity entityIn) { - return false; - } - - @Override - public boolean shouldRenderInPass(int pass) { - return pass == 1; - } - - @SideOnly(Side.CLIENT) - @Override - public int getBrightnessForRender(){ - return 15728880; - } -} diff --git a/src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java deleted file mode 100644 index 9c31f2d50..000000000 --- a/src/main/java/com/cleanroommc/modularui/test/ScreenEntityRender.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.cleanroommc.modularui.test; - -import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.entity.Render; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.util.ResourceLocation; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class ScreenEntityRender extends Render { - - public ScreenEntityRender(RenderManager renderManager) { - super(renderManager); - } - - @Nullable - @Override - protected ResourceLocation getEntityTexture(@NotNull ModularScreenEntity entity) { - return null; - } - - @Override - public void doRender(@NotNull ModularScreenEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { - GuiScreenWrapper screenWrapper = entity.getWrapper(); - if (screenWrapper == null) return; - - GlStateManager.pushMatrix(); - GlStateManager.translate(x, y, z); - GlStateManager.scale(0.02, 0.02, 0.02); - GlStateManager.rotate(180, 0, 0, 1); - screenWrapper.drawScreen(Integer.MIN_VALUE, Integer.MIN_VALUE, partialTicks); - GlStateManager.popMatrix(); - } -} From 87f3c83fee4399b88ef80598b848b35197ff34f7 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sun, 18 Jun 2023 19:41:08 +0200 Subject: [PATCH 05/51] move some stuff to GuiUtils & experimental annotations --- src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 085aa86cd..fba7a5173 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; +import org.jetbrains.annotations.ApiStatus; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; From 1bc428663d5bebb5b5beb75479f0f308cba31b1f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 23 Feb 2024 22:22:25 -0700 Subject: [PATCH 06/51] try move to quaternion --- .../com/cleanroommc/modularui/holoui/HoloUI.java | 9 +++++++++ .../com/cleanroommc/modularui/holoui/Plane3D.java | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index fba7a5173..3ced77d30 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -6,6 +6,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.ApiStatus; @@ -44,6 +46,13 @@ public Builder at(double x, double y, double z) { return this; } + public Builder at(BlockPos pos) { + this.x = pos.getX() + 0.5D; + this.y = pos.getY() + 0.5D; + this.z = pos.getZ() + 0.5D; + return this; + } + public Builder inFrontOf(EntityPlayer player, double distance, boolean fixed) { Vec3d look = player.getLookVec(); this.orientation = fixed ? ScreenOrientation.FIXED : ScreenOrientation.TO_PLAYER; diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 7fcaa70da..6d066d014 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -2,11 +2,13 @@ import com.cleanroommc.modularui.utils.GuiUtils; -import com.cleanroommc.modularui.utils.Matrix4f; - import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.ApiStatus; +import org.lwjgl.util.vector.Matrix4f; +import org.lwjgl.util.vector.Quaternion; /** * Highly experimental @@ -18,6 +20,7 @@ public class Plane3D { private float scale = 1f; private float aX = 0.5f, aY = 0.5f; private float nX = 0, nY = 0, nZ = 1; + private final Quaternion facer = new Quaternion(); public void transformRectangle() { // translate to anchor @@ -76,6 +79,14 @@ public void setNormal(float x, float y, float z) { this.nZ = z; } + public void setTarget(Entity entity) { + BlockPos pos = entity.getPosition(); + this.facer.x = pos.getX(); + this.facer.y = pos.getY(); + this.facer.z = pos.getZ(); + this.facer.w = 1; + } + public void setAnchor(float x, float y) { this.aX = x; this.aY = y; From d7ca5e5faab95e0e25e9b5fe5097e7dcdba4e0fa Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 01:12:38 -0700 Subject: [PATCH 07/51] set normals --- src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 3ced77d30..dff006e8b 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -56,6 +56,7 @@ public Builder at(BlockPos pos) { public Builder inFrontOf(EntityPlayer player, double distance, boolean fixed) { Vec3d look = player.getLookVec(); this.orientation = fixed ? ScreenOrientation.FIXED : ScreenOrientation.TO_PLAYER; + if (fixed) plane3D.setNormal((float) -look.x, 0, (float) -look.z); return at(player.posX + look.x * distance, player.posY + player.getEyeHeight() + look.y * distance, player.posZ + look.z * distance); } From 6b9248a93f0848d2003f59dcd070b045de7bfce4 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 01:13:19 -0700 Subject: [PATCH 08/51] fix in world transforms --- .../cleanroommc/modularui/holoui/Plane3D.java | 86 +++++++++++-------- .../modularui/holoui/ScreenEntityRender.java | 12 ++- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 6d066d014..28a37e1af 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -6,9 +6,10 @@ import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.ApiStatus; import org.lwjgl.util.vector.Matrix4f; -import org.lwjgl.util.vector.Quaternion; +import org.lwjgl.util.vector.Vector3f; /** * Highly experimental @@ -19,10 +20,14 @@ public class Plane3D { private float w = 480, h = 270; private float scale = 1f; private float aX = 0.5f, aY = 0.5f; - private float nX = 0, nY = 0, nZ = 1; - private final Quaternion facer = new Quaternion(); + private Vec3d normal = Direction.ORIGIN.asVec3d(); - public void transformRectangle() { + + public void transform() { + transform(this.normal, Direction.ORIGIN.asVec3d(), this.normal.scale(-1)); + } + + public void transform(Vec3d target, Vec3d orig, Vec3d looking) { // translate to anchor GlStateManager.translate(-this.w * this.aX, -this.h * this.aY, 0); // translate for scale and rotation @@ -32,19 +37,22 @@ public void transformRectangle() { // rotate 180 deg GlStateManager.rotate(180, 0, 0, 1); // apply facing direction - if (this.nX != 0 || this.nY != 0 || this.nZ != 1) { - Matrix4f rotation = new Matrix4f(); - rotation.m00 = -this.nZ + (this.nY * this.nY * (1 + this.nZ)) / (this.nX * this.nX + this.nY * this.nY); - rotation.m10 = -(this.nX * this.nY * (1 + this.nZ)) / (this.nX * this.nX + this.nY * this.nY); - rotation.m20 = this.nX; - rotation.m01 = -(this.nX * this.nY * (1 + this.nZ)) / (this.nX * this.nX + this.nY * this.nY); - rotation.m11 = -this.nZ + (this.nX * this.nX * (1 + this.nZ)) / (this.nX * this.nX + this.nY * this.nY); - rotation.m21 = this.nY; - rotation.m02 = -this.nX; - rotation.m12 = -this.nY; - rotation.m22 = -this.nZ; - GuiUtils.applyTransformationMatrix(rotation); - } + Vec3d diff = orig.subtract(target); + double yaw = Math.atan(diff.z / diff.x); + if (diff.x < 0) yaw += (Math.PI / 2); + else yaw -= (Math.PI / 2); + + Vec3d vec = new Vec3d(looking.x, 0, looking.z); + double pitch = Math.atan(looking.y / vec.length()); +// if (orig.x < 0) pitch -= (Math.PI / 2); + + Matrix4f mYaw = new Matrix4f() + .rotate((float) yaw, Direction.UP.asVector3f()); + Matrix4f mPitch = new Matrix4f() + .rotate((float) pitch, Direction.LEFT.asVector3f()); + + GuiUtils.applyTransformationMatrix(mYaw); + GuiUtils.applyTransformationMatrix(mPitch); // un-translate for scale and rotation GlStateManager.translate(-(this.w / 2f), -(this.h / 2f), 0); } @@ -67,24 +75,7 @@ public void setHeightWithProp(float h) { } public void setNormal(float x, float y, float z) { - float square = x * x + y * y + z * z; - if (square != 1) { - float factor = (float) Math.sqrt(square); - x /= factor; - y /= factor; - z /= factor; - } - this.nX = x; - this.nY = y; - this.nZ = z; - } - - public void setTarget(Entity entity) { - BlockPos pos = entity.getPosition(); - this.facer.x = pos.getX(); - this.facer.y = pos.getY(); - this.facer.z = pos.getZ(); - this.facer.w = 1; + this.normal = new Vec3d(x, y, z).normalize(); } public void setAnchor(float x, float y) { @@ -107,4 +98,29 @@ public void setScale(float scale) { public float getScale() { return this.scale; } + + private enum Direction { + ORIGIN(0, 0, 0), + LEFT(1, 0, 0), + UP(0, 1, 0), + NORTH(0, 0, 1), + RIGHT(-1, 0, 0), + DOWN(0, -1, 0), + SOUTH(0, 0, -1); + + private final Vector3f vector3f; + private final Vec3d vec3d; + Direction(float x, float y, float z) { + vector3f = new Vector3f(x, y, z); + vec3d = new Vec3d(x, y, z); + } + + Vector3f asVector3f() { + return vector3f; + } + + Vec3d asVec3d() { + return vec3d; + } + } } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index a8e389f42..c6f6e61ca 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -35,16 +35,14 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl if (screenWrapper == null) return; Plane3D plane3D = entity.getPlane3D(); + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, z); if (entity.getOrientation() == ScreenOrientation.TO_PLAYER) { EntityPlayer player = Minecraft.getMinecraft().player; - float xN = (float) (player.posX - entity.posX); - float yN = (float) (player.posY - entity.posY); - float zN = (float) (player.posZ - entity.posZ); - plane3D.setNormal(xN, yN, zN); + plane3D.transform(player.getPositionVector(), entity.getPositionVector(), player.getLookVec()); + } else { + plane3D.transform(); } - GlStateManager.pushMatrix(); - GlStateManager.translate(x, y, z); - plane3D.transformRectangle(); screenWrapper.drawScreen(0, 0, partialTicks); GlStateManager.popMatrix(); } From e033a673b0174afacbc30f2a53fa37bc7ce34fdb Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 01:53:10 -0700 Subject: [PATCH 09/51] add some comments --- src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 28a37e1af..8f07235f2 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -36,15 +36,17 @@ public void transform(Vec3d target, Vec3d orig, Vec3d looking) { GlStateManager.scale(0.0625 * this.scale, 0.0625 * this.scale, 0.0625 * this.scale); // rotate 180 deg GlStateManager.rotate(180, 0, 0, 1); + // apply facing direction + // handle yaw (left-right) Vec3d diff = orig.subtract(target); double yaw = Math.atan(diff.z / diff.x); if (diff.x < 0) yaw += (Math.PI / 2); else yaw -= (Math.PI / 2); + // handle pitch (up-down) Vec3d vec = new Vec3d(looking.x, 0, looking.z); double pitch = Math.atan(looking.y / vec.length()); -// if (orig.x < 0) pitch -= (Math.PI / 2); Matrix4f mYaw = new Matrix4f() .rotate((float) yaw, Direction.UP.asVector3f()); From aa9d277fedba6ad1d49ab038b6ddc6233cf8dc5a Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 02:00:17 -0700 Subject: [PATCH 10/51] flip cardinal directions to match minecraft make normal default north --- .../com/cleanroommc/modularui/holoui/Plane3D.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 8f07235f2..71da58ea9 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -3,8 +3,6 @@ import com.cleanroommc.modularui.utils.GuiUtils; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.ApiStatus; @@ -20,7 +18,7 @@ public class Plane3D { private float w = 480, h = 270; private float scale = 1f; private float aX = 0.5f, aY = 0.5f; - private Vec3d normal = Direction.ORIGIN.asVec3d(); + private Vec3d normal = Direction.NORTH.asVec3d(); public void transform() { @@ -51,7 +49,7 @@ public void transform(Vec3d target, Vec3d orig, Vec3d looking) { Matrix4f mYaw = new Matrix4f() .rotate((float) yaw, Direction.UP.asVector3f()); Matrix4f mPitch = new Matrix4f() - .rotate((float) pitch, Direction.LEFT.asVector3f()); + .rotate((float) pitch, Direction.EAST.asVector3f()); GuiUtils.applyTransformationMatrix(mYaw); GuiUtils.applyTransformationMatrix(mPitch); @@ -103,12 +101,12 @@ public float getScale() { private enum Direction { ORIGIN(0, 0, 0), - LEFT(1, 0, 0), UP(0, 1, 0), - NORTH(0, 0, 1), - RIGHT(-1, 0, 0), DOWN(0, -1, 0), - SOUTH(0, 0, -1); + NORTH(0, 0, -1), + SOUTH(0, 0, 1), + EAST(1, 0, 0), + WEST(-1, 0, 0); private final Vector3f vector3f; private final Vec3d vec3d; From 4637375d7ed707d74fe371039e6cb65a035875d4 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:53:30 -0700 Subject: [PATCH 11/51] merge if checks --- .../com/cleanroommc/modularui/holoui/HoloScreenEntity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 33d68fa85..d962572e6 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -84,14 +84,13 @@ public void onEntityUpdate() { this.prevPosZ = this.posZ; this.prevRotationPitch = this.rotationPitch; this.prevRotationYaw = this.rotationYaw; - if (this.world.isRemote) { - this.extinguish(); - } + if (this.posY < -64.0D) { this.outOfWorld(); } if (this.world.isRemote) { + this.extinguish(); int w = (int) this.plane3D.getWidth(), h = (int) this.plane3D.getHeight(); if (w != this.wrapper.width || h != this.wrapper.height) { this.wrapper.onResize(Minecraft.getMinecraft(), w, h); From 67e900528f3e9881b204f1f8652389e8a5325fc8 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:53:49 -0700 Subject: [PATCH 12/51] store rotation info --- src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 71da58ea9..c64a00d3e 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -19,6 +19,7 @@ public class Plane3D { private float scale = 1f; private float aX = 0.5f, aY = 0.5f; private Vec3d normal = Direction.NORTH.asVec3d(); + private Vec3d rotation = this.normal; public void transform() { @@ -45,6 +46,7 @@ public void transform(Vec3d target, Vec3d orig, Vec3d looking) { // handle pitch (up-down) Vec3d vec = new Vec3d(looking.x, 0, looking.z); double pitch = Math.atan(looking.y / vec.length()); + this.rotation = new Vec3d(pitch, yaw, 0); Matrix4f mYaw = new Matrix4f() .rotate((float) yaw, Direction.UP.asVector3f()); @@ -78,6 +80,10 @@ public void setNormal(float x, float y, float z) { this.normal = new Vec3d(x, y, z).normalize(); } + public Vec3d getRotation() { + return this.rotation; + } + public void setAnchor(float x, float y) { this.aX = x; this.aY = y; From 95f50489d3859e44297f7f68b58acdbcda27fc08 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:54:24 -0700 Subject: [PATCH 13/51] trig fuckery --- .../modularui/holoui/ScreenEntityRender.java | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index c6f6e61ca..f1c1aadcf 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -1,5 +1,6 @@ package com.cleanroommc.modularui.holoui; +import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.screen.GuiContainerWrapper; import net.minecraft.client.Minecraft; @@ -9,10 +10,16 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.Vec3i; + import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.vecmath.Vector2d; + /** * Highly experimental */ @@ -37,13 +44,57 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl Plane3D plane3D = entity.getPlane3D(); GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); + EntityPlayer player = Minecraft.getMinecraft().player; if (entity.getOrientation() == ScreenOrientation.TO_PLAYER) { - EntityPlayer player = Minecraft.getMinecraft().player; plane3D.transform(player.getPositionVector(), entity.getPositionVector(), player.getLookVec()); } else { plane3D.transform(); } - screenWrapper.drawScreen(0, 0, partialTicks); + var mouse = calculateMousePos(player, entity, player.getLookVec()); + screenWrapper.drawScreen(mouse.getX(), mouse.getY(), partialTicks); GlStateManager.popMatrix(); } + + private Vec3i calculateMousePos(EntityPlayer player, HoloScreenEntity entity, Vec3d looking) { + var holoPos = entity.getPositionVector(); + var pos = player.getPositionVector().add(0, player.getEyeHeight(), 0); + + var plane = entity.getPlane3D(); + var planeRot = plane.getRotation(); + + // get the difference of the player's eye position and holo position + // rotate diff based on plane rotation + double worldAngle = calculateHorizontalAngle(holoPos); + var posR = pos.rotateYaw((float) (planeRot.y - worldAngle)); + var holoR = holoPos.rotateYaw((float) (planeRot.y - worldAngle)); + + // x should be the left-right offset from the player to the holo screen + // z should be the distance from the player to the holo screen's plane + var diff = holoR.subtract(posR); + + // rotate to make x zero + var lookRot = looking + .rotateYaw((float) (planeRot.y - worldAngle)) + .rotatePitch((float) planeRot.x); + + // the x, y of look rot should be the mouse pos if scaled by looRot z + // the scale factor should be the distance from the player to the plane by the z component of lookRot + double sf = diff.z / lookRot.z; + double mX = ((lookRot.x * sf) - diff.x) * 16; + double mY = ((lookRot.y * -sf) + diff.y) * 16; + mY += plane.getHeight() / 2; + mX += plane.getWidth() / 2; + + return new Vec3i(mX, mY, 0); + } + + private double calculateHorizontalAngle(Vec3d vec) { + // x is opposite, z is adjacent, theta = atan(x/z) + double a3 = Math.atan(vec.x / vec.z); + if (vec.z < 0) { + // if z is negative, the angle returned by atan has to be offset by PI + a3 += vec.x < 0 ? -Math.PI : Math.PI; + } + return a3; + } } From fc4825d3806b025f0537ee8f05f2a005411b53a5 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:17:12 -0700 Subject: [PATCH 14/51] comment --- .../com/cleanroommc/modularui/holoui/ScreenEntityRender.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index f1c1aadcf..ba99a6c54 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -69,6 +69,7 @@ private Vec3i calculateMousePos(EntityPlayer player, HoloScreenEntity entity, Ve var holoR = holoPos.rotateYaw((float) (planeRot.y - worldAngle)); // x should be the left-right offset from the player to the holo screen + // y should be the up-down offset from the player to the holo screen // z should be the distance from the player to the holo screen's plane var diff = holoR.subtract(posR); From 774323012e14666530b937db1ec6fca2bfae4c23 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:30:26 -0700 Subject: [PATCH 15/51] move holo opening to a new item --- .../cleanroommc/modularui/test/TestBlock.java | 3 ++ .../modularui/test/TestHoloItem.java | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java diff --git a/src/main/java/com/cleanroommc/modularui/test/TestBlock.java b/src/main/java/com/cleanroommc/modularui/test/TestBlock.java index 9b9c742fe..8417d9ec4 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestBlock.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestBlock.java @@ -40,6 +40,7 @@ public static void preInit() { testItemBlock.setRegistryName(rl); GameRegistry.registerTileEntity(TestTile.class, rl); TestItem.testItem.setRegistryName(ModularUI.ID, "test_item"); + TestHoloItem.testHoloItem.setRegistryName(ModularUI.ID, "test_holo_item"); } @SubscribeEvent @@ -53,12 +54,14 @@ public static void registerItems(RegistryEvent.Register event) { IForgeRegistry registry = event.getRegistry(); registry.register(testItemBlock); registry.register(TestItem.testItem); + registry.register(TestHoloItem.testHoloItem); } @SubscribeEvent public static void registerModel(ModelRegistryEvent event) { ModelResourceLocation mrl = new ModelResourceLocation(new ResourceLocation("diamond"), "inventory"); ModelLoader.setCustomModelResourceLocation(TestItem.testItem, 0, mrl); + ModelLoader.setCustomModelResourceLocation(TestHoloItem.testHoloItem, 0, mrl); } public TestBlock() { diff --git a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java new file mode 100644 index 000000000..93362f331 --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java @@ -0,0 +1,40 @@ +package com.cleanroommc.modularui.test; + +import com.cleanroommc.modularui.factory.HandGuiData; +import com.cleanroommc.modularui.holoui.HoloUI; + +import com.cleanroommc.modularui.screen.ModularScreen; + +import com.cleanroommc.modularui.value.sync.GuiSyncManager; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.world.World; + +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public class TestHoloItem extends TestItem { + + public static final TestHoloItem testHoloItem = new TestHoloItem(); + @NotNull + @Override + public ActionResult onItemRightClick(World world, @NotNull EntityPlayer player, @NotNull EnumHand hand) { + if (world.isRemote) { + Objects.requireNonNull(player); + Objects.requireNonNull(hand); + HandGuiData guiData = new HandGuiData(player, hand); + GuiSyncManager manager = new GuiSyncManager(player); + ModularScreen s = new ModularScreen(buildUI(guiData, manager)); + HoloUI.builder() + .inFrontOf(Minecraft.getMinecraft().player, 5, true) + .open(s); + } + return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); + } +} From 694cfca8c9e421257c727dc4f58d10a6932329e0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:02:00 -0700 Subject: [PATCH 16/51] add holo factor and manager fix some issues --- .../cleanroommc/modularui/CommonProxy.java | 1 + .../modularui/factory/GuiManager.java | 2 +- .../modularui/factory/HoloGuiFactory.java | 43 +++++++ .../modularui/factory/HoloGuiManager.java | 112 ++++++++++++++++++ .../modularui/holoui/HoloScreenEntity.java | 6 +- .../cleanroommc/modularui/holoui/HoloUI.java | 11 +- .../network/packets/OpenGuiPacket.java | 8 +- .../modularui/test/TestHoloItem.java | 15 +-- 8 files changed, 181 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/cleanroommc/modularui/factory/HoloGuiFactory.java create mode 100644 src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java diff --git a/src/main/java/com/cleanroommc/modularui/CommonProxy.java b/src/main/java/com/cleanroommc/modularui/CommonProxy.java index 4f3f33b9b..f378226bb 100644 --- a/src/main/java/com/cleanroommc/modularui/CommonProxy.java +++ b/src/main/java/com/cleanroommc/modularui/CommonProxy.java @@ -40,6 +40,7 @@ void preInit(FMLPreInitializationEvent event) { NetworkHandler.init(); GuiFactories.init(); + GuiManager.registerFactory(HoloGuiFactory.INSTANCE); } void postInit(FMLPostInitializationEvent event) { diff --git a/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java index 738054b09..35e54910f 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/GuiManager.java @@ -37,7 +37,7 @@ public class GuiManager { - private static final Object2ObjectMap> FACTORIES = new Object2ObjectOpenHashMap<>(16); + protected static final Object2ObjectMap> FACTORIES = new Object2ObjectOpenHashMap<>(16); private static IMuiScreen lastMui; private static final List openedContainers = new ArrayList<>(4); diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiFactory.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiFactory.java new file mode 100644 index 000000000..65bc507ed --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiFactory.java @@ -0,0 +1,43 @@ +package com.cleanroommc.modularui.factory; + +import com.cleanroommc.modularui.api.IGuiHolder; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; + +import net.minecraft.util.EnumHand; + +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public class HoloGuiFactory extends AbstractUIFactory{ + + public static final HoloGuiFactory INSTANCE = new HoloGuiFactory(); + + protected HoloGuiFactory() { + super("mui:holo"); + } + + public static void open(EntityPlayerMP player, EnumHand hand) { + Objects.requireNonNull(player); + Objects.requireNonNull(hand); + HandGuiData guiData = new HandGuiData(player, hand); + HoloGuiManager.open(INSTANCE, guiData, player); + } + @Override + public @NotNull IGuiHolder getGuiHolder(HandGuiData data) { + return Objects.requireNonNull(castGuiHolder(data.getUsedItemStack().getItem()), "Item was not a gui holder!"); + } + + @Override + public void writeGuiData(HandGuiData guiData, PacketBuffer buffer) { + buffer.writeByte(guiData.getHand().ordinal()); + } + + @Override + public @NotNull HandGuiData readGuiData(EntityPlayer player, PacketBuffer buffer) { + return new HandGuiData(player, EnumHand.values()[buffer.readByte()]); + } +} diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java new file mode 100644 index 000000000..c9e592207 --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -0,0 +1,112 @@ +package com.cleanroommc.modularui.factory; + +import com.cleanroommc.modularui.api.JeiSettings; +import com.cleanroommc.modularui.api.UIFactory; +import com.cleanroommc.modularui.holoui.HoloUI; +import com.cleanroommc.modularui.network.NetworkHandler; +import com.cleanroommc.modularui.network.packets.OpenGuiPacket; +import com.cleanroommc.modularui.screen.*; +import com.cleanroommc.modularui.value.sync.GuiSyncManager; +import com.cleanroommc.modularui.widget.WidgetTree; + +import io.netty.buffer.Unpooled; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.event.entity.player.PlayerContainerEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class HoloGuiManager extends GuiManager { + + + private static GuiScreenWrapper lastMui; + private static final List openedContainers = new ArrayList<>(4); + + public static void open(@NotNull UIFactory factory, @NotNull T guiData, EntityPlayerMP player) { + if (player instanceof FakePlayer || openedContainers.contains(player)) return; + openedContainers.add(player); + // create panel, collect sync handlers and create container + guiData.setJeiSettings(JeiSettings.DUMMY); + GuiSyncManager syncManager = new GuiSyncManager(player); + ModularPanel panel = factory.createPanel(guiData, syncManager); + WidgetTree.collectSyncValues(syncManager, panel); + ModularContainer container = new ModularContainer(syncManager); + // sync to client + player.getNextWindowId(); + player.closeContainer(); + int windowId = player.currentWindowId; + PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); + factory.writeGuiData(guiData, buffer); + NetworkHandler.sendToPlayer(new OpenGuiPacket<>(windowId, factory, buffer), player); + // open container // this mimics forge behaviour + player.openContainer = container; + player.openContainer.windowId = windowId; + player.openContainer.addListener(player); + // finally invoke event + MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container)); + } + + @SideOnly(Side.CLIENT) + public static void open(int windowId, @NotNull UIFactory factory, @NotNull PacketBuffer data, @NotNull EntityPlayerSP player) { + T guiData = factory.readGuiData(player, data); + JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); + guiData.setJeiSettings(jeiSettings); + GuiSyncManager syncManager = new GuiSyncManager(player); + ModularPanel panel = factory.createPanel(guiData, syncManager); + WidgetTree.collectSyncValues(syncManager, panel); + ModularScreen screen = factory.createScreen(guiData, panel); + screen.getContext().setJeiSettings(jeiSettings); + GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(syncManager), screen); + guiScreenWrapper.inventorySlots.windowId = windowId; +// Minecraft.getMinecraft().displayGuiScreen(guiScreenWrapper); + HoloUI.builder() + .inFrontOf(player, 5, true) + .open(guiScreenWrapper); + player.openContainer = guiScreenWrapper.inventorySlots; + } + + @SideOnly(Side.CLIENT) + static void openScreen(ModularScreen screen, JeiSettingsImpl jeiSettings) { + screen.getContext().setJeiSettings(jeiSettings); + GuiScreenWrapper screenWrapper = new GuiScreenWrapper(new ModularContainer(), screen); + Minecraft.getMinecraft().displayGuiScreen(screenWrapper); + } + + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void onGuiOpen(GuiOpenEvent event) { + if (lastMui != null && event.getGui() == null) { + if (lastMui.getScreen().getPanelManager().isOpen()) { + lastMui.getScreen().getPanelManager().closeAll(); + } + lastMui.getScreen().getPanelManager().dispose(); + lastMui = null; + } else if (event.getGui() instanceof GuiScreenWrapper screenWrapper) { + if (lastMui == null) { + lastMui = screenWrapper; + } else if (lastMui == event.getGui()) { + lastMui.getScreen().getPanelManager().reopen(); + } else { + if (lastMui.getScreen().getPanelManager().isOpen()) { + lastMui.getScreen().getPanelManager().closeAll(); + } + lastMui.getScreen().getPanelManager().dispose(); + lastMui = screenWrapper; + } + } + } +} diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index d962572e6..0666c23bd 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -42,7 +42,11 @@ public HoloScreenEntity(World world) { public void setScreen(ModularScreen screen) { this.screen = screen; - this.wrapper = new GuiContainerWrapper(new ModularContainer(null), screen); + } + + public void setWrapper(GuiContainerWrapper wrapper) { + this.setScreen(wrapper.getScreen()); + this.wrapper = wrapper; this.wrapper.setWorldAndResolution(Minecraft.getMinecraft(), (int) this.plane3D.getWidth(), (int) this.plane3D.getHeight()); } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index dff006e8b..6e3a41880 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -1,5 +1,6 @@ package com.cleanroommc.modularui.holoui; +import com.cleanroommc.modularui.screen.GuiScreenWrapper; import com.cleanroommc.modularui.screen.JeiSettingsImpl; import com.cleanroommc.modularui.screen.ModularScreen; @@ -91,13 +92,13 @@ public Builder plane(Plane3D plane) { return this; } - public void open(ModularScreen screen) { - JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); - jeiSettings.disableJei(); - screen.getContext().setJeiSettings(jeiSettings); + public void open(GuiScreenWrapper wrapper) { +// JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); +// jeiSettings.disableJei(); +// screen.getContext().setJeiSettings(jeiSettings); HoloScreenEntity holoScreenEntity = new HoloScreenEntity(Minecraft.getMinecraft().world, this.plane3D); holoScreenEntity.setPosition(this.x, this.y, this.z); - holoScreenEntity.setScreen(screen); + holoScreenEntity.setWrapper(wrapper); holoScreenEntity.spawnInWorld(); holoScreenEntity.setOrientation(this.orientation); } diff --git a/src/main/java/com/cleanroommc/modularui/network/packets/OpenGuiPacket.java b/src/main/java/com/cleanroommc/modularui/network/packets/OpenGuiPacket.java index 6d58f0712..80677382c 100644 --- a/src/main/java/com/cleanroommc/modularui/network/packets/OpenGuiPacket.java +++ b/src/main/java/com/cleanroommc/modularui/network/packets/OpenGuiPacket.java @@ -3,6 +3,8 @@ import com.cleanroommc.modularui.api.UIFactory; import com.cleanroommc.modularui.factory.GuiData; import com.cleanroommc.modularui.factory.GuiManager; +import com.cleanroommc.modularui.factory.HoloGuiFactory; +import com.cleanroommc.modularui.factory.HoloGuiManager; import com.cleanroommc.modularui.network.IPacket; import com.cleanroommc.modularui.network.NetworkHandler; import com.cleanroommc.modularui.network.NetworkUtils; @@ -49,7 +51,11 @@ public void read(PacketBuffer buf) { @SideOnly(Side.CLIENT) @Override public @Nullable IPacket executeClient(NetHandlerPlayClient handler) { - GuiManager.open(this.windowId, this.factory, this.data, Minecraft.getMinecraft().player); + if (this.factory instanceof HoloGuiFactory) { + HoloGuiManager.open(this.windowId, this.factory, this.data, Minecraft.getMinecraft().player); + } else { + GuiManager.open(this.windowId, this.factory, this.data, Minecraft.getMinecraft().player); + } return null; } } diff --git a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java index 93362f331..e5ed7b7d1 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java @@ -1,14 +1,18 @@ package com.cleanroommc.modularui.test; import com.cleanroommc.modularui.factory.HandGuiData; +import com.cleanroommc.modularui.factory.HoloGuiFactory; import com.cleanroommc.modularui.holoui.HoloUI; import com.cleanroommc.modularui.screen.ModularScreen; import com.cleanroommc.modularui.value.sync.GuiSyncManager; +import com.cleanroommc.modularui.widget.WidgetTree; + import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; @@ -25,15 +29,8 @@ public class TestHoloItem extends TestItem { @NotNull @Override public ActionResult onItemRightClick(World world, @NotNull EntityPlayer player, @NotNull EnumHand hand) { - if (world.isRemote) { - Objects.requireNonNull(player); - Objects.requireNonNull(hand); - HandGuiData guiData = new HandGuiData(player, hand); - GuiSyncManager manager = new GuiSyncManager(player); - ModularScreen s = new ModularScreen(buildUI(guiData, manager)); - HoloUI.builder() - .inFrontOf(Minecraft.getMinecraft().player, 5, true) - .open(s); + if (!world.isRemote) { + HoloGuiFactory.open((EntityPlayerMP) player, hand); } return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand)); } From 7b19fe08809bc4e1bec1dd3bbab92d8703e54bc2 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 15:05:43 -0700 Subject: [PATCH 17/51] try to get mouse working --- .../cleanroommc/modularui/CommonProxy.java | 1 + .../modularui/factory/HoloGuiManager.java | 58 ++++++++++++++----- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/CommonProxy.java b/src/main/java/com/cleanroommc/modularui/CommonProxy.java index f378226bb..557f2e0cb 100644 --- a/src/main/java/com/cleanroommc/modularui/CommonProxy.java +++ b/src/main/java/com/cleanroommc/modularui/CommonProxy.java @@ -31,6 +31,7 @@ public class CommonProxy { void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(CommonProxy.class); MinecraftForge.EVENT_BUS.register(GuiManager.class); + MinecraftForge.EVENT_BUS.register(HoloGuiManager.class); if (ModularUIConfig.enableTestGuis) { MinecraftForge.EVENT_BUS.register(TestBlock.class); diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index c9e592207..6f4c43f23 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -1,16 +1,16 @@ package com.cleanroommc.modularui.factory; +import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.api.JeiSettings; import com.cleanroommc.modularui.api.UIFactory; import com.cleanroommc.modularui.holoui.HoloUI; import com.cleanroommc.modularui.network.NetworkHandler; import com.cleanroommc.modularui.network.packets.OpenGuiPacket; import com.cleanroommc.modularui.screen.*; +import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.value.sync.GuiSyncManager; import com.cleanroommc.modularui.widget.WidgetTree; -import io.netty.buffer.Unpooled; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayer; @@ -21,19 +21,27 @@ import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import io.netty.buffer.Unpooled; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.input.Mouse; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.UUID; public class HoloGuiManager extends GuiManager { private static GuiScreenWrapper lastMui; private static final List openedContainers = new ArrayList<>(4); + private static final Map> map = new Object2ObjectOpenHashMap<>(); public static void open(@NotNull UIFactory factory, @NotNull T guiData, EntityPlayerMP player) { if (player instanceof FakePlayer || openedContainers.contains(player)) return; @@ -44,17 +52,19 @@ public static void open(@NotNull UIFactory factory, @NotN ModularPanel panel = factory.createPanel(guiData, syncManager); WidgetTree.collectSyncValues(syncManager, panel); ModularContainer container = new ModularContainer(syncManager); + map.computeIfAbsent(player.getUniqueID(), uuid -> new ArrayList<>()) + .add(new Data(container, panel, null)); // sync to client - player.getNextWindowId(); - player.closeContainer(); - int windowId = player.currentWindowId; +// player.getNextWindowId(); +// player.closeContainer(); +// int windowId = player.currentWindowId; PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); factory.writeGuiData(guiData, buffer); - NetworkHandler.sendToPlayer(new OpenGuiPacket<>(windowId, factory, buffer), player); + NetworkHandler.sendToPlayer(new OpenGuiPacket<>(0, factory, buffer), player); // open container // this mimics forge behaviour - player.openContainer = container; - player.openContainer.windowId = windowId; - player.openContainer.addListener(player); +// player.openContainer = container; +// player.openContainer.windowId = windowId; +// player.openContainer.addListener(player); // finally invoke event MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container)); } @@ -71,18 +81,36 @@ public static void open(int windowId, @NotNull UIFactory screen.getContext().setJeiSettings(jeiSettings); GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(syncManager), screen); guiScreenWrapper.inventorySlots.windowId = windowId; -// Minecraft.getMinecraft().displayGuiScreen(guiScreenWrapper); + map.computeIfAbsent(player.getUniqueID(), uuid -> new ArrayList<>()) + .add(new Data(screen.getContainer(), panel, screen)); HoloUI.builder() .inFrontOf(player, 5, true) .open(guiScreenWrapper); - player.openContainer = guiScreenWrapper.inventorySlots; } @SideOnly(Side.CLIENT) - static void openScreen(ModularScreen screen, JeiSettingsImpl jeiSettings) { - screen.getContext().setJeiSettings(jeiSettings); - GuiScreenWrapper screenWrapper = new GuiScreenWrapper(new ModularContainer(), screen); - Minecraft.getMinecraft().displayGuiScreen(screenWrapper); + @SubscribeEvent + public static void onClick(InputEvent.MouseInputEvent event) { + var mouse = MouseData.create(Mouse.getEventButton()); + boolean pressed = Mouse.getEventButtonState(); + var player = Minecraft.getMinecraft().player; + if (player != null && mouse.mouseButton != -1 && pressed) { + for (var data : map.get(player.getUniqueID())) { + ModularUI.LOGGER.warn("click"); + } + } + } + + private static class Data { + @Nullable + public ModularScreen screen; + public ModularPanel panel; + public ModularContainer container; + protected Data(ModularContainer container, ModularPanel panel, @Nullable ModularScreen screen) { + this.container = container; + this.panel = panel; + this.screen = screen; + } } From 0c738ee2c9f8230c51e99790191cd8eb92a9181f Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:53:03 -0700 Subject: [PATCH 18/51] imports --- .../modularui/holoui/HoloScreenEntity.java | 1 - .../com/cleanroommc/modularui/test/TestHoloItem.java | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 0666c23bd..a64620b6b 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -1,7 +1,6 @@ package com.cleanroommc.modularui.holoui; import com.cleanroommc.modularui.screen.GuiContainerWrapper; -import com.cleanroommc.modularui.screen.ModularContainer; import com.cleanroommc.modularui.screen.ModularScreen; import net.minecraft.block.Block; diff --git a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java index e5ed7b7d1..30bfb7383 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java @@ -1,16 +1,7 @@ package com.cleanroommc.modularui.test; -import com.cleanroommc.modularui.factory.HandGuiData; import com.cleanroommc.modularui.factory.HoloGuiFactory; -import com.cleanroommc.modularui.holoui.HoloUI; -import com.cleanroommc.modularui.screen.ModularScreen; - -import com.cleanroommc.modularui.value.sync.GuiSyncManager; - -import com.cleanroommc.modularui.widget.WidgetTree; - -import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -21,8 +12,6 @@ import org.jetbrains.annotations.NotNull; -import java.util.Objects; - public class TestHoloItem extends TestItem { public static final TestHoloItem testHoloItem = new TestHoloItem(); From 046f21d5faeba502fb0e220f7b71cb3f7a62bd66 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:53:36 -0700 Subject: [PATCH 19/51] add contains check --- src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 6e3a41880..2e7fd6ad7 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -27,7 +27,8 @@ public class HoloUI { private static final Map> syncedHolos = new Object2ObjectOpenHashMap<>(); public static void registerSyncedHoloUI(ResourceLocation loc, Supplier screen) { - syncedHolos.put(loc, screen); + if (!syncedHolos.containsKey(loc)) + syncedHolos.put(loc, screen); } public static Builder builder() { From 533745dbefcecda146b9edc96e79dff4da1d933e Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:55:08 -0700 Subject: [PATCH 20/51] update screen and animator handle mouse input add method to check if within a screen --- .../modularui/factory/HoloGuiManager.java | 36 +++------------- .../modularui/holoui/ScreenEntityRender.java | 43 +++++++++++++++---- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 6f4c43f23..c5c1ed6f3 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -1,13 +1,12 @@ package com.cleanroommc.modularui.factory; -import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.api.JeiSettings; import com.cleanroommc.modularui.api.UIFactory; import com.cleanroommc.modularui.holoui.HoloUI; +import com.cleanroommc.modularui.holoui.ScreenEntityRender; import com.cleanroommc.modularui.network.NetworkHandler; import com.cleanroommc.modularui.network.packets.OpenGuiPacket; import com.cleanroommc.modularui.screen.*; -import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.value.sync.GuiSyncManager; import com.cleanroommc.modularui.widget.WidgetTree; @@ -16,6 +15,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.PacketBuffer; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.FakePlayer; @@ -26,22 +26,16 @@ import net.minecraftforge.fml.relauncher.SideOnly; import io.netty.buffer.Unpooled; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.lwjgl.input.Mouse; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.UUID; public class HoloGuiManager extends GuiManager { private static GuiScreenWrapper lastMui; private static final List openedContainers = new ArrayList<>(4); - private static final Map> map = new Object2ObjectOpenHashMap<>(); public static void open(@NotNull UIFactory factory, @NotNull T guiData, EntityPlayerMP player) { if (player instanceof FakePlayer || openedContainers.contains(player)) return; @@ -52,8 +46,7 @@ public static void open(@NotNull UIFactory factory, @NotN ModularPanel panel = factory.createPanel(guiData, syncManager); WidgetTree.collectSyncValues(syncManager, panel); ModularContainer container = new ModularContainer(syncManager); - map.computeIfAbsent(player.getUniqueID(), uuid -> new ArrayList<>()) - .add(new Data(container, panel, null)); + HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), () -> null); // sync to client // player.getNextWindowId(); // player.closeContainer(); @@ -81,8 +74,7 @@ public static void open(int windowId, @NotNull UIFactory screen.getContext().setJeiSettings(jeiSettings); GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(syncManager), screen); guiScreenWrapper.inventorySlots.windowId = windowId; - map.computeIfAbsent(player.getUniqueID(), uuid -> new ArrayList<>()) - .add(new Data(screen.getContainer(), panel, screen)); + HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel::getScreen); HoloUI.builder() .inFrontOf(player, 5, true) .open(guiScreenWrapper); @@ -91,25 +83,9 @@ public static void open(int windowId, @NotNull UIFactory @SideOnly(Side.CLIENT) @SubscribeEvent public static void onClick(InputEvent.MouseInputEvent event) { - var mouse = MouseData.create(Mouse.getEventButton()); - boolean pressed = Mouse.getEventButtonState(); var player = Minecraft.getMinecraft().player; - if (player != null && mouse.mouseButton != -1 && pressed) { - for (var data : map.get(player.getUniqueID())) { - ModularUI.LOGGER.warn("click"); - } - } - } - - private static class Data { - @Nullable - public ModularScreen screen; - public ModularPanel panel; - public ModularContainer container; - protected Data(ModularContainer container, ModularPanel panel, @Nullable ModularScreen screen) { - this.container = container; - this.panel = panel; - this.screen = screen; + if (player != null) { + ScreenEntityRender.clickScreen(player); } } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index ba99a6c54..d3c22f4c1 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -2,29 +2,32 @@ import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.screen.GuiContainerWrapper; +import com.cleanroommc.modularui.utils.Animator; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.crash.CrashReport; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; - -import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.vecmath.Vector2d; +import java.util.Map; /** * Highly experimental */ @ApiStatus.Experimental public class ScreenEntityRender extends Render { + private static final Map lookingPlayers = new Object2ObjectOpenHashMap<>(); public ScreenEntityRender(RenderManager renderManager) { super(renderManager); @@ -50,14 +53,33 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl } else { plane3D.transform(); } - var mouse = calculateMousePos(player, entity, player.getLookVec()); + var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); screenWrapper.drawScreen(mouse.getX(), mouse.getY(), partialTicks); + screenWrapper.getScreen().onFrameUpdate(); + Animator.advance(); + if (withinScreen(mouse, entity.getPlane3D()) && !lookingPlayers.containsKey(player)) { + lookingPlayers.put(player, screenWrapper); + } else if (!withinScreen(mouse, entity.getPlane3D())) { + lookingPlayers.remove(player); + } GlStateManager.popMatrix(); } - private Vec3i calculateMousePos(EntityPlayer player, HoloScreenEntity entity, Vec3d looking) { + public static void clickScreen(EntityPlayer player) { + if (lookingPlayers.containsKey(player)) { + try { + lookingPlayers.get(player).handleMouseInput(); + } catch (Throwable throwable1) { + CrashReport c = CrashReport.makeCrashReport(throwable1, "Updating screen events"); + c.makeCategory("Affected screen") + .addDetail("Screen name", () -> lookingPlayers.get(player).getClass().getCanonicalName()); + throw new ReportedException(c); + } + } + } + + private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity entity, Vec3d looking) { var holoPos = entity.getPositionVector(); - var pos = player.getPositionVector().add(0, player.getEyeHeight(), 0); var plane = entity.getPlane3D(); var planeRot = plane.getRotation(); @@ -65,7 +87,7 @@ private Vec3i calculateMousePos(EntityPlayer player, HoloScreenEntity entity, Ve // get the difference of the player's eye position and holo position // rotate diff based on plane rotation double worldAngle = calculateHorizontalAngle(holoPos); - var posR = pos.rotateYaw((float) (planeRot.y - worldAngle)); + var posR = player.rotateYaw((float) (planeRot.y - worldAngle)); var holoR = holoPos.rotateYaw((float) (planeRot.y - worldAngle)); // x should be the left-right offset from the player to the holo screen @@ -89,7 +111,12 @@ private Vec3i calculateMousePos(EntityPlayer player, HoloScreenEntity entity, Ve return new Vec3i(mX, mY, 0); } - private double calculateHorizontalAngle(Vec3d vec) { + private static boolean withinScreen(Vec3i mousePos, Plane3D plane) { + return mousePos.getX() > 0 && mousePos.getX() < plane.getWidth() && + mousePos.getY() > 0 && mousePos.getY() < plane.getHeight(); + } + + private static double calculateHorizontalAngle(Vec3d vec) { // x is opposite, z is adjacent, theta = atan(x/z) double a3 = Math.atan(vec.x / vec.z); if (vec.z < 0) { From ecd70ceb3c8ec9f5202269622bace1e7b1061801 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:15:53 -0700 Subject: [PATCH 21/51] tick screen remove player when not rendering --- .../modularui/holoui/HoloScreenEntity.java | 1 + .../modularui/holoui/ScreenEntityRender.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index a64620b6b..1d4501e1a 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -100,6 +100,7 @@ public void onEntityUpdate() { } } + this.screen.onUpdate(); this.firstUpdate = false; this.world.profiler.endSection(); } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index d3c22f4c1..750dcf872 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.culling.ICamera; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.crash.CrashReport; @@ -78,10 +79,19 @@ public static void clickScreen(EntityPlayer player) { } } - private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity entity, Vec3d looking) { - var holoPos = entity.getPositionVector(); + @Override + public boolean shouldRender(HoloScreenEntity screen, ICamera camera, double camX, double camY, double camZ) { + boolean render = super.shouldRender(screen, camera, camX, camY, camZ); + if (!render) { + lookingPlayers.remove(Minecraft.getMinecraft().player); + } + return render; + } + + private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Vec3d looking) { + var holoPos = screen.getPositionVector(); - var plane = entity.getPlane3D(); + var plane = screen.getPlane3D(); var planeRot = plane.getRotation(); // get the difference of the player's eye position and holo position From 187d695b5362cd8eccfe1fdedeb5eff0b7de7217 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 28 Feb 2024 21:29:01 -0700 Subject: [PATCH 22/51] test other orientation dont rotate pitch by plane x rot --- .../java/com/cleanroommc/modularui/factory/HoloGuiManager.java | 2 +- .../com/cleanroommc/modularui/holoui/ScreenEntityRender.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index c5c1ed6f3..615c7e0d0 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -76,7 +76,7 @@ public static void open(int windowId, @NotNull UIFactory guiScreenWrapper.inventorySlots.windowId = windowId; HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel::getScreen); HoloUI.builder() - .inFrontOf(player, 5, true) + .inFrontOf(player, 5, false) .open(guiScreenWrapper); } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index 750dcf872..1c62fc698 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -107,8 +107,7 @@ private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Ve // rotate to make x zero var lookRot = looking - .rotateYaw((float) (planeRot.y - worldAngle)) - .rotatePitch((float) planeRot.x); + .rotateYaw((float) (planeRot.y - worldAngle)); // the x, y of look rot should be the mouse pos if scaled by looRot z // the scale factor should be the distance from the player to the plane by the z component of lookRot From 8fec74d5868ede5b94e3cec0774c380833333932 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 28 Feb 2024 21:38:28 -0700 Subject: [PATCH 23/51] don't interact with any items in any hand try and replace existing holo screens --- .../com/cleanroommc/modularui/factory/HoloGuiManager.java | 2 +- src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 615c7e0d0..4a0d7fa27 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -84,7 +84,7 @@ public static void open(int windowId, @NotNull UIFactory @SubscribeEvent public static void onClick(InputEvent.MouseInputEvent event) { var player = Minecraft.getMinecraft().player; - if (player != null) { + if (player != null && player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty()) { ScreenEntityRender.clickScreen(player); } } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 2e7fd6ad7..aa029e484 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -27,8 +27,10 @@ public class HoloUI { private static final Map> syncedHolos = new Object2ObjectOpenHashMap<>(); public static void registerSyncedHoloUI(ResourceLocation loc, Supplier screen) { - if (!syncedHolos.containsKey(loc)) - syncedHolos.put(loc, screen); + var old = syncedHolos.put(loc, screen); + if (old != null && old.get() != null) { + old.get().close(true); + } } public static Builder builder() { From 5780987ecf075fd03ffd95609afeb2c32994dbc8 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 28 Feb 2024 21:58:43 -0700 Subject: [PATCH 24/51] don't pitch render based on looking account for pitch for mouse pos --- .../cleanroommc/modularui/holoui/Plane3D.java | 4 ++-- .../modularui/holoui/ScreenEntityRender.java | 22 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index c64a00d3e..2d9620747 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -44,8 +44,8 @@ public void transform(Vec3d target, Vec3d orig, Vec3d looking) { else yaw -= (Math.PI / 2); // handle pitch (up-down) - Vec3d vec = new Vec3d(looking.x, 0, looking.z); - double pitch = Math.atan(looking.y / vec.length()); + Vec3d vec = new Vec3d(diff.x, 0, diff.z); + double pitch = Math.atan(diff.y / vec.length()); this.rotation = new Vec3d(pitch, yaw, 0); Matrix4f mYaw = new Matrix4f() diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index 1c62fc698..d13bf04d5 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -96,9 +96,12 @@ private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Ve // get the difference of the player's eye position and holo position // rotate diff based on plane rotation - double worldAngle = calculateHorizontalAngle(holoPos); - var posR = player.rotateYaw((float) (planeRot.y - worldAngle)); - var holoR = holoPos.rotateYaw((float) (planeRot.y - worldAngle)); + double worldAngle = calculateAngle(holoPos.x, holoPos.z); + double verticalAngle = calculateAngle(holoPos.y, holoPos.z); + var posR = player.rotateYaw((float) (planeRot.y - worldAngle)) + .rotatePitch((float) (planeRot.x + verticalAngle)); + var holoR = holoPos.rotateYaw((float) (planeRot.y - worldAngle)) + .rotatePitch((float) (planeRot.x + verticalAngle)); // x should be the left-right offset from the player to the holo screen // y should be the up-down offset from the player to the holo screen @@ -107,13 +110,14 @@ private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Ve // rotate to make x zero var lookRot = looking - .rotateYaw((float) (planeRot.y - worldAngle)); + .rotateYaw((float) (planeRot.y - worldAngle)) + .rotatePitch((float) (planeRot.x + verticalAngle)); // the x, y of look rot should be the mouse pos if scaled by looRot z // the scale factor should be the distance from the player to the plane by the z component of lookRot double sf = diff.z / lookRot.z; double mX = ((lookRot.x * sf) - diff.x) * 16; - double mY = ((lookRot.y * -sf) + diff.y) * 16; + double mY = ((lookRot.y * sf) - diff.y) * 16; mY += plane.getHeight() / 2; mX += plane.getWidth() / 2; @@ -125,12 +129,12 @@ private static boolean withinScreen(Vec3i mousePos, Plane3D plane) { mousePos.getY() > 0 && mousePos.getY() < plane.getHeight(); } - private static double calculateHorizontalAngle(Vec3d vec) { + private static double calculateAngle(double opposite, double adjacent) { // x is opposite, z is adjacent, theta = atan(x/z) - double a3 = Math.atan(vec.x / vec.z); - if (vec.z < 0) { + double a3 = Math.atan(opposite / adjacent); + if (adjacent < 0) { // if z is negative, the angle returned by atan has to be offset by PI - a3 += vec.x < 0 ? -Math.PI : Math.PI; + a3 += opposite < 0 ? -Math.PI : Math.PI; } return a3; } From ac939cfc8d2319b22ca23520086f602d4a7ddf7d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:03:19 -0700 Subject: [PATCH 25/51] move some stuff around --- .../modularui/holoui/ScreenEntityRender.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index d13bf04d5..426e5b109 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -90,7 +90,6 @@ public boolean shouldRender(HoloScreenEntity screen, ICamera camera, double camX private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Vec3d looking) { var holoPos = screen.getPositionVector(); - var plane = screen.getPlane3D(); var planeRot = plane.getRotation(); @@ -103,16 +102,16 @@ private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Ve var holoR = holoPos.rotateYaw((float) (planeRot.y - worldAngle)) .rotatePitch((float) (planeRot.x + verticalAngle)); + // rotate looking so that 0, 0, 0 is facing exactly at the origin of the screen + var lookRot = looking + .rotateYaw((float) (planeRot.y - worldAngle)) + .rotatePitch((float) (planeRot.x + verticalAngle)); + // x should be the left-right offset from the player to the holo screen // y should be the up-down offset from the player to the holo screen // z should be the distance from the player to the holo screen's plane var diff = holoR.subtract(posR); - // rotate to make x zero - var lookRot = looking - .rotateYaw((float) (planeRot.y - worldAngle)) - .rotatePitch((float) (planeRot.x + verticalAngle)); - // the x, y of look rot should be the mouse pos if scaled by looRot z // the scale factor should be the distance from the player to the plane by the z component of lookRot double sf = diff.z / lookRot.z; From 467a629fa50b60f4e47a25b2d4975e61db8ed117 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:23:17 -0700 Subject: [PATCH 26/51] test scale --- .../java/com/cleanroommc/modularui/factory/HoloGuiManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 4a0d7fa27..b1c0bfcd8 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -76,7 +76,8 @@ public static void open(int windowId, @NotNull UIFactory guiScreenWrapper.inventorySlots.windowId = windowId; HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel::getScreen); HoloUI.builder() - .inFrontOf(player, 5, false) +// .screenScale(0.25f) + .inFrontOf(player, 5, true) .open(guiScreenWrapper); } From 45a0329d988e3700ca4b71da38d3cfdbc6b02fb0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:08:08 -0700 Subject: [PATCH 27/51] move bool to context --- .../com/cleanroommc/modularui/screen/viewport/GuiContext.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java b/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java index b66cca731..c06c24159 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java +++ b/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java @@ -44,6 +44,7 @@ public static GuiContext getDefault() { /* Render states */ private float partialTicks; private long tick = 0; + public boolean isHoloScreen = false; public boolean isAbove(IGuiElement widget) { return isMouseAbove(widget.getArea()); From 491cf570cc88f5ad1dc25e39359695f6cdaff52e Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:26:55 -0700 Subject: [PATCH 28/51] use uuid instead of player --- .../modularui/holoui/ScreenEntityRender.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index 426e5b109..d5e2ad0a1 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -22,13 +22,14 @@ import org.jetbrains.annotations.Nullable; import java.util.Map; +import java.util.UUID; /** * Highly experimental */ @ApiStatus.Experimental public class ScreenEntityRender extends Render { - private static final Map lookingPlayers = new Object2ObjectOpenHashMap<>(); + private static final Map lookingPlayers = new Object2ObjectOpenHashMap<>(); public ScreenEntityRender(RenderManager renderManager) { super(renderManager); @@ -44,36 +45,40 @@ protected ResourceLocation getEntityTexture(@NotNull HoloScreenEntity entity) { public void doRender(@NotNull HoloScreenEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { GuiContainerWrapper screenWrapper = entity.getWrapper(); if (screenWrapper == null) return; + var screen = screenWrapper.getScreen(); Plane3D plane3D = entity.getPlane3D(); GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); EntityPlayer player = Minecraft.getMinecraft().player; if (entity.getOrientation() == ScreenOrientation.TO_PLAYER) { - plane3D.transform(player.getPositionVector(), entity.getPositionVector(), player.getLookVec()); + plane3D.transform(player.getPositionVector(), entity.getPositionVector()); } else { plane3D.transform(); } var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); screenWrapper.drawScreen(mouse.getX(), mouse.getY(), partialTicks); - screenWrapper.getScreen().onFrameUpdate(); +// screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); + screen.onFrameUpdate(); + + UUID id = player.getUniqueID(); Animator.advance(); - if (withinScreen(mouse, entity.getPlane3D()) && !lookingPlayers.containsKey(player)) { - lookingPlayers.put(player, screenWrapper); + if (withinScreen(mouse, entity.getPlane3D()) && !lookingPlayers.containsKey(id)) { + lookingPlayers.put(id, screenWrapper); } else if (!withinScreen(mouse, entity.getPlane3D())) { - lookingPlayers.remove(player); + lookingPlayers.remove(id); } GlStateManager.popMatrix(); } public static void clickScreen(EntityPlayer player) { - if (lookingPlayers.containsKey(player)) { + if (lookingPlayers.containsKey(player.getUniqueID())) { try { - lookingPlayers.get(player).handleMouseInput(); + lookingPlayers.get(player.getUniqueID()).handleMouseInput(); } catch (Throwable throwable1) { CrashReport c = CrashReport.makeCrashReport(throwable1, "Updating screen events"); c.makeCategory("Affected screen") - .addDetail("Screen name", () -> lookingPlayers.get(player).getClass().getCanonicalName()); + .addDetail("Screen name", () -> lookingPlayers.get(player.getUniqueID()).getClass().getCanonicalName()); throw new ReportedException(c); } } From 145f8c3b0e50549cc6e8e780bd1360bc384e7887 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:27:08 -0700 Subject: [PATCH 29/51] remove unused parameter --- src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 2d9620747..71523cf2f 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -23,10 +23,10 @@ public class Plane3D { public void transform() { - transform(this.normal, Direction.ORIGIN.asVec3d(), this.normal.scale(-1)); + transform(this.normal, Direction.ORIGIN.asVec3d()); } - public void transform(Vec3d target, Vec3d orig, Vec3d looking) { + public void transform(Vec3d target, Vec3d orig) { // translate to anchor GlStateManager.translate(-this.w * this.aX, -this.h * this.aY, 0); // translate for scale and rotation From 0fd3af7c5557a959f9e88223e416ac9fcab14583 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:27:28 -0700 Subject: [PATCH 30/51] handle z index correctly when holo screen --- .../java/com/cleanroommc/modularui/widgets/ItemSlot.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index b06013547..76deb47ec 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -224,8 +224,9 @@ private void drawSlot(Slot slotIn) { } } - ((GuiAccessor) guiScreen).setZLevel(100f); - renderItem.zLevel = 100.0F; + float z = getContext().isHoloScreen ? -150f : 100f; + ((GuiAccessor) guiScreen).setZLevel(z); + renderItem.zLevel = z; if (!flag1) { if (flag) { From 2e9bbf41b491d1a0f9505620995af0d42bc7500d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:28:06 -0700 Subject: [PATCH 31/51] add holo screen entity to context --- .../java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java | 1 + .../com/cleanroommc/modularui/screen/viewport/GuiContext.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 1d4501e1a..251605de6 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -41,6 +41,7 @@ public HoloScreenEntity(World world) { public void setScreen(ModularScreen screen) { this.screen = screen; + this.screen.getContext().holoScreen = this; } public void setWrapper(GuiContainerWrapper wrapper) { diff --git a/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java b/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java index c06c24159..b46c92b6a 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java +++ b/src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java @@ -5,6 +5,7 @@ import com.cleanroommc.modularui.api.drawable.IDrawable; import com.cleanroommc.modularui.api.widget.IGuiElement; import com.cleanroommc.modularui.screen.ClientScreenHandler; +import com.cleanroommc.modularui.holoui.HoloScreenEntity; import com.cleanroommc.modularui.widget.sizer.Area; import net.minecraft.client.Minecraft; @@ -45,6 +46,7 @@ public static GuiContext getDefault() { private float partialTicks; private long tick = 0; public boolean isHoloScreen = false; + public HoloScreenEntity holoScreen = null; public boolean isAbove(IGuiElement widget) { return isMouseAbove(widget.getArea()); From 9314b93f65803852fabb7cb804a1e6e1ba927735 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:28:20 -0700 Subject: [PATCH 32/51] misc --- .../cleanroommc/modularui/factory/HoloGuiManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index b1c0bfcd8..e1a65678f 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -46,14 +46,14 @@ public static void open(@NotNull UIFactory factory, @NotN ModularPanel panel = factory.createPanel(guiData, syncManager); WidgetTree.collectSyncValues(syncManager, panel); ModularContainer container = new ModularContainer(syncManager); - HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), () -> null); + HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel, null); // sync to client -// player.getNextWindowId(); + player.getNextWindowId(); // player.closeContainer(); -// int windowId = player.currentWindowId; + int windowId = player.currentWindowId; PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); factory.writeGuiData(guiData, buffer); - NetworkHandler.sendToPlayer(new OpenGuiPacket<>(0, factory, buffer), player); + NetworkHandler.sendToPlayer(new OpenGuiPacket<>(windowId, factory, buffer), player); // open container // this mimics forge behaviour // player.openContainer = container; // player.openContainer.windowId = windowId; @@ -74,7 +74,7 @@ public static void open(int windowId, @NotNull UIFactory screen.getContext().setJeiSettings(jeiSettings); GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(syncManager), screen); guiScreenWrapper.inventorySlots.windowId = windowId; - HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel::getScreen); + HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel, guiScreenWrapper); HoloUI.builder() // .screenScale(0.25f) .inFrontOf(player, 5, true) From a660972cd40b8f07b7fd8ab812c5d5b11f58956d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:48:20 -0700 Subject: [PATCH 33/51] handle rendering when holo screen --- src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java | 6 +++--- .../cleanroommc/modularui/holoui/ScreenEntityRender.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index 71523cf2f..f8351638c 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -105,7 +105,7 @@ public float getScale() { return this.scale; } - private enum Direction { + public enum Direction { ORIGIN(0, 0, 0), UP(0, 1, 0), DOWN(0, -1, 0), @@ -121,11 +121,11 @@ private enum Direction { vec3d = new Vec3d(x, y, z); } - Vector3f asVector3f() { + public Vector3f asVector3f() { return vector3f; } - Vec3d asVec3d() { + public Vec3d asVec3d() { return vec3d; } } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index d5e2ad0a1..d7daf8c9d 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -133,7 +133,7 @@ private static boolean withinScreen(Vec3i mousePos, Plane3D plane) { mousePos.getY() > 0 && mousePos.getY() < plane.getHeight(); } - private static double calculateAngle(double opposite, double adjacent) { + public static double calculateAngle(double opposite, double adjacent) { // x is opposite, z is adjacent, theta = atan(x/z) double a3 = Math.atan(opposite / adjacent); if (adjacent < 0) { From c0aa541713277a9e08f80bcdcf32c0568dfc3daf Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:48:41 -0700 Subject: [PATCH 34/51] work on holo screen registration --- .../cleanroommc/modularui/holoui/HoloUI.java | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index aa029e484..751b41ebc 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -1,22 +1,19 @@ package com.cleanroommc.modularui.holoui; import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import com.cleanroommc.modularui.screen.JeiSettingsImpl; -import com.cleanroommc.modularui.screen.ModularScreen; +import com.cleanroommc.modularui.screen.ModularPanel; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import org.jetbrains.annotations.ApiStatus; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.Map; -import java.util.function.Supplier; /** * Highly experimental @@ -24,13 +21,18 @@ @ApiStatus.Experimental public class HoloUI { - private static final Map> syncedHolos = new Object2ObjectOpenHashMap<>(); + private final Map syncedHolos = new Object2ObjectOpenHashMap<>(); + private static final HoloUI INSTANCE = new HoloUI(); - public static void registerSyncedHoloUI(ResourceLocation loc, Supplier screen) { - var old = syncedHolos.put(loc, screen); - if (old != null && old.get() != null) { - old.get().close(true); - } + public static void registerSyncedHoloUI(ResourceLocation loc, ModularPanel mainPanel, GuiScreenWrapper screenWrapperSupplier) { + var old = INSTANCE.register(loc, mainPanel, screenWrapperSupplier); +// if (old != null && old.getPanel() != null) { +// old.getPanel().closeIfOpen(true); +// } + } + + private Data register(ResourceLocation location, ModularPanel panelSupplier, GuiScreenWrapper screenWrapperSupplier) { + return this.syncedHolos.put(location, new Data(panelSupplier, screenWrapperSupplier)); } public static Builder builder() { @@ -99,6 +101,7 @@ public void open(GuiScreenWrapper wrapper) { // JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); // jeiSettings.disableJei(); // screen.getContext().setJeiSettings(jeiSettings); + wrapper.getScreen().getContext().isHoloScreen = true; HoloScreenEntity holoScreenEntity = new HoloScreenEntity(Minecraft.getMinecraft().world, this.plane3D); holoScreenEntity.setPosition(this.x, this.y, this.z); holoScreenEntity.setWrapper(wrapper); @@ -106,4 +109,28 @@ public void open(GuiScreenWrapper wrapper) { holoScreenEntity.setOrientation(this.orientation); } } + + public static class Data { + private final ModularPanel panelSupplier; + @Nullable + private final GuiScreenWrapper screenWrapperSupplier; + + Data(ModularPanel panelSupplier, GuiScreenWrapper screenWrapperSupplier) { + this.panelSupplier = panelSupplier; + this.screenWrapperSupplier = screenWrapperSupplier; + } + + Data(ModularPanel panelSupplier) { + this.panelSupplier = panelSupplier; + this.screenWrapperSupplier = null; + } + + public ModularPanel getPanel() { + return panelSupplier; + } + + public GuiScreenWrapper getScreenWrapper() { + return screenWrapperSupplier; + } + } } From 8afb251687a9b55aa6ea0ced1e95e8e567ba4dea Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:37:54 -0700 Subject: [PATCH 35/51] fix --- .../com/cleanroommc/modularui/holoui/ScreenEntityRender.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index d7daf8c9d..60ae2fa15 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -88,7 +88,7 @@ public static void clickScreen(EntityPlayer player) { public boolean shouldRender(HoloScreenEntity screen, ICamera camera, double camX, double camY, double camZ) { boolean render = super.shouldRender(screen, camera, camX, camY, camZ); if (!render) { - lookingPlayers.remove(Minecraft.getMinecraft().player); + lookingPlayers.remove(Minecraft.getMinecraft().player.getUniqueID()); } return render; } From 67008b71d3d7c6ec5a9a663611c1d1e3932d0397 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:40:41 -0700 Subject: [PATCH 36/51] partially fix block weirdness --- src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index 76deb47ec..5377c4501 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -236,7 +236,9 @@ private void drawSlot(Slot slotIn) { if (!itemstack.isEmpty()) { GlStateManager.enableDepth(); // render the item itself - renderItem.renderItemAndEffectIntoGUI(guiScreen.mc.player, itemstack, 1, 1); +// renderItem.renderItemAndEffectIntoGUI(guiScreen.mc.player, itemstack, 1, 1); +// guiScreen.getItemRenderer().renderItemAndEffectIntoGUI(guiScreen.mc.player, itemstack, 1, 1); + guiScreen.drawItem(itemstack, 1, 1); if (amount < 0) { amount = itemstack.getCount(); } From c07d0b6eec9274b28bcb9b3c686eaa6c6cf60999 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:51:28 -0700 Subject: [PATCH 37/51] fix z issues --- .../java/com/cleanroommc/modularui/widgets/ItemSlot.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index 5377c4501..7cad866f3 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -224,9 +224,10 @@ private void drawSlot(Slot slotIn) { } } - float z = getContext().isHoloScreen ? -150f : 100f; + float z = 100f; + // todo fix ((GuiAccessor) guiScreen).setZLevel(z); - renderItem.zLevel = z; + renderItem.zLevel += z; if (!flag1) { if (flag) { @@ -279,8 +280,9 @@ private void drawSlot(Slot slotIn) { } } + // todo fix ((GuiAccessor) guiScreen).setZLevel(0f); - renderItem.zLevel = 0f; + renderItem.zLevel -= z; } @Override From ce915acdf8d2a122d548d3b83ac17f31ec0ab584 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 13:01:40 -0700 Subject: [PATCH 38/51] don't draw jei add todo --- .../java/com/cleanroommc/modularui/factory/HoloGuiManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index e1a65678f..0cc0508cd 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -81,6 +81,7 @@ public static void open(int windowId, @NotNull UIFactory .open(guiScreenWrapper); } + //todo make this a mixin instead of using event to cancel arm animation stuff @SideOnly(Side.CLIENT) @SubscribeEvent public static void onClick(InputEvent.MouseInputEvent event) { From 6bb682a1bc9ad10b1734ba35df7b8b96089ac418 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 14:28:08 -0700 Subject: [PATCH 39/51] add tracker to holo ent --- src/main/java/com/cleanroommc/modularui/CommonProxy.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cleanroommc/modularui/CommonProxy.java b/src/main/java/com/cleanroommc/modularui/CommonProxy.java index 557f2e0cb..83d066660 100644 --- a/src/main/java/com/cleanroommc/modularui/CommonProxy.java +++ b/src/main/java/com/cleanroommc/modularui/CommonProxy.java @@ -63,6 +63,7 @@ public static void registerBlocks(RegistryEvent.Register event) { .id("modular_screen", 0) .name("ModularScreen") .entity(HoloScreenEntity.class) + .tracker(100, 20, false) .factory(HoloScreenEntity::new) .build()); } From 3aa8d7de1e8a62d3c912cfcd6297f06814578f03 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 14:28:33 -0700 Subject: [PATCH 40/51] improve holo syncing --- .../modularui/factory/HoloGuiManager.java | 31 ++++----- .../modularui/holoui/HoloScreenEntity.java | 31 +++++---- .../cleanroommc/modularui/holoui/HoloUI.java | 63 +++++++------------ 3 files changed, 59 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 0cc0508cd..01660f7b8 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -1,5 +1,6 @@ package com.cleanroommc.modularui.factory; +import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.api.JeiSettings; import com.cleanroommc.modularui.api.UIFactory; import com.cleanroommc.modularui.holoui.HoloUI; @@ -12,10 +13,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.FakePlayer; @@ -28,32 +27,33 @@ import io.netty.buffer.Unpooled; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; - public class HoloGuiManager extends GuiManager { private static GuiScreenWrapper lastMui; - private static final List openedContainers = new ArrayList<>(4); public static void open(@NotNull UIFactory factory, @NotNull T guiData, EntityPlayerMP player) { - if (player instanceof FakePlayer || openedContainers.contains(player)) return; - openedContainers.add(player); + if (player instanceof FakePlayer) return; // create panel, collect sync handlers and create container guiData.setJeiSettings(JeiSettings.DUMMY); GuiSyncManager syncManager = new GuiSyncManager(player); ModularPanel panel = factory.createPanel(guiData, syncManager); WidgetTree.collectSyncValues(syncManager, panel); ModularContainer container = new ModularContainer(syncManager); - HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel, null); + HoloUI.builder() + .inFrontOf(player, 5, true) + .open(screen -> { + screen.setContainer(container); + screen.setPanel(panel); + HoloUI.registerSyncedHoloUI(panel, screen); + }, player.getEntityWorld()); // sync to client - player.getNextWindowId(); +// player.getNextWindowId(); // player.closeContainer(); - int windowId = player.currentWindowId; +// int windowId = player.currentWindowId; PacketBuffer buffer = new PacketBuffer(Unpooled.buffer()); factory.writeGuiData(guiData, buffer); - NetworkHandler.sendToPlayer(new OpenGuiPacket<>(windowId, factory, buffer), player); + NetworkHandler.sendToPlayer(new OpenGuiPacket<>(0, factory, buffer), player); // open container // this mimics forge behaviour // player.openContainer = container; // player.openContainer.windowId = windowId; @@ -74,11 +74,14 @@ public static void open(int windowId, @NotNull UIFactory screen.getContext().setJeiSettings(jeiSettings); GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(syncManager), screen); guiScreenWrapper.inventorySlots.windowId = windowId; - HoloUI.registerSyncedHoloUI(new ResourceLocation("holo", panel.getName()), panel, guiScreenWrapper); HoloUI.builder() // .screenScale(0.25f) .inFrontOf(player, 5, true) - .open(guiScreenWrapper); + .open(screen1 -> { + screen1.setPanel(panel); + screen1.setWrapper(guiScreenWrapper); + HoloUI.registerSyncedHoloUI(panel, screen1); + }, player.getEntityWorld()); } //todo make this a mixin instead of using event to cancel arm animation stuff diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 251605de6..ab57506e7 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -1,7 +1,6 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.GuiContainerWrapper; -import com.cleanroommc.modularui.screen.ModularScreen; +import com.cleanroommc.modularui.screen.*; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -26,7 +25,8 @@ public class HoloScreenEntity extends Entity { private GuiContainerWrapper wrapper; - private ModularScreen screen; + private ModularContainer container; + private ModularPanel panel; private final Plane3D plane3D; private static final DataParameter ORIENTATION = EntityDataManager.createKey(HoloScreenEntity.class, DataSerializers.BYTE); @@ -39,19 +39,24 @@ public HoloScreenEntity(World world) { this(world, new Plane3D()); } - public void setScreen(ModularScreen screen) { - this.screen = screen; - this.screen.getContext().holoScreen = this; - } - public void setWrapper(GuiContainerWrapper wrapper) { - this.setScreen(wrapper.getScreen()); this.wrapper = wrapper; this.wrapper.setWorldAndResolution(Minecraft.getMinecraft(), (int) this.plane3D.getWidth(), (int) this.plane3D.getHeight()); + this.getScreen().getContext().holoScreen = this; + this.getScreen().getContext().isHoloScreen = true; + setContainer(wrapper.getScreen().getContainer()); + } + + public void setContainer(ModularContainer container) { + this.container = container; + } + + public void setPanel(ModularPanel panel) { + this.panel = panel; } public ModularScreen getScreen() { - return this.screen; + return this.getWrapper().getScreen(); } public GuiContainerWrapper getWrapper() { @@ -96,12 +101,16 @@ public void onEntityUpdate() { if (this.world.isRemote) { this.extinguish(); int w = (int) this.plane3D.getWidth(), h = (int) this.plane3D.getHeight(); + if (this.wrapper == null) { + this.getEntityWorld().removeEntity(this); + return; + } if (w != this.wrapper.width || h != this.wrapper.height) { this.wrapper.onResize(Minecraft.getMinecraft(), w, h); } + this.wrapper.getScreen().onUpdate(); } - this.screen.onUpdate(); this.firstUpdate = false; this.world.profiler.endSection(); } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 751b41ebc..d26f9b803 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -1,19 +1,17 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.GuiScreenWrapper; import com.cleanroommc.modularui.screen.ModularPanel; -import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; import java.util.Map; +import java.util.function.Consumer; /** * Highly experimental @@ -21,18 +19,14 @@ @ApiStatus.Experimental public class HoloUI { - private final Map syncedHolos = new Object2ObjectOpenHashMap<>(); - private static final HoloUI INSTANCE = new HoloUI(); + private static final Map syncedHolos = new Object2ObjectOpenHashMap<>(); - public static void registerSyncedHoloUI(ResourceLocation loc, ModularPanel mainPanel, GuiScreenWrapper screenWrapperSupplier) { - var old = INSTANCE.register(loc, mainPanel, screenWrapperSupplier); -// if (old != null && old.getPanel() != null) { -// old.getPanel().closeIfOpen(true); -// } + public static void registerSyncedHoloUI(ModularPanel mainPanel, HoloScreenEntity entity) { + syncedHolos.put(mainPanel.getName(), entity); } - private Data register(ResourceLocation location, ModularPanel panelSupplier, GuiScreenWrapper screenWrapperSupplier) { - return this.syncedHolos.put(location, new Data(panelSupplier, screenWrapperSupplier)); + public static boolean isOpen(ModularPanel panel) { + return syncedHolos.containsKey(panel.getName()); } public static Builder builder() { @@ -97,40 +91,27 @@ public Builder plane(Plane3D plane) { return this; } - public void open(GuiScreenWrapper wrapper) { + public void open(Consumer entityConsumer, World world) { // JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); // jeiSettings.disableJei(); // screen.getContext().setJeiSettings(jeiSettings); - wrapper.getScreen().getContext().isHoloScreen = true; - HoloScreenEntity holoScreenEntity = new HoloScreenEntity(Minecraft.getMinecraft().world, this.plane3D); - holoScreenEntity.setPosition(this.x, this.y, this.z); - holoScreenEntity.setWrapper(wrapper); - holoScreenEntity.spawnInWorld(); - holoScreenEntity.setOrientation(this.orientation); - } - } - - public static class Data { - private final ModularPanel panelSupplier; - @Nullable - private final GuiScreenWrapper screenWrapperSupplier; - - Data(ModularPanel panelSupplier, GuiScreenWrapper screenWrapperSupplier) { - this.panelSupplier = panelSupplier; - this.screenWrapperSupplier = screenWrapperSupplier; - } - - Data(ModularPanel panelSupplier) { - this.panelSupplier = panelSupplier; - this.screenWrapperSupplier = null; - } - public ModularPanel getPanel() { - return panelSupplier; +// wrapper.getScreen().getContext().isHoloScreen = true; + HoloScreenEntity screen = new HoloScreenEntity(world, this.plane3D); + screen.setPosition(this.x, this.y, this.z); + screen.setOrientation(this.orientation); + entityConsumer.accept(screen); + screen.spawnInWorld(); +// holoScreenEntity.setPosition(this.x, this.y, this.z); +// holoScreenEntity.setWrapper(wrapper); +// holoScreenEntity.spawnInWorld(); +// holoScreenEntity.setOrientation(this.orientation); } - public GuiScreenWrapper getScreenWrapper() { - return screenWrapperSupplier; + public void reposition(String name) { + var screen = syncedHolos.get(name); + screen.setPosition(this.x, this.y, this.z); + screen.setOrientation(this.orientation); } } } From 81fc0c877cfad7c7e4cc89db8f08b85be211254e Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 14:28:56 -0700 Subject: [PATCH 41/51] initial reposition --- .../com/cleanroommc/modularui/factory/HoloGuiManager.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 01660f7b8..29af75e17 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -38,6 +38,13 @@ public static void open(@NotNull UIFactory factory, @NotN guiData.setJeiSettings(JeiSettings.DUMMY); GuiSyncManager syncManager = new GuiSyncManager(player); ModularPanel panel = factory.createPanel(guiData, syncManager); + if (HoloUI.isOpen(panel)) { + HoloUI.builder() + .inFrontOf(player, 5, true) + .reposition(panel.getName()); + ModularUI.LOGGER.warn("reposition the holo, sync to client"); + return; + } WidgetTree.collectSyncValues(syncManager, panel); ModularContainer container = new ModularContainer(syncManager); HoloUI.builder() From cc314e05e348ca1c6900772b3bd923c558128a38 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Mar 2024 15:04:36 -0700 Subject: [PATCH 42/51] mostly working reposition --- .../modularui/factory/HoloGuiManager.java | 12 +++++- .../cleanroommc/modularui/holoui/HoloUI.java | 6 ++- .../modularui/network/NetworkHandler.java | 1 + .../network/packets/SyncHoloPacket.java | 41 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/cleanroommc/modularui/network/packets/SyncHoloPacket.java diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 29af75e17..e59eb6bc5 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -7,12 +7,14 @@ import com.cleanroommc.modularui.holoui.ScreenEntityRender; import com.cleanroommc.modularui.network.NetworkHandler; import com.cleanroommc.modularui.network.packets.OpenGuiPacket; +import com.cleanroommc.modularui.network.packets.SyncHoloPacket; import com.cleanroommc.modularui.screen.*; import com.cleanroommc.modularui.value.sync.GuiSyncManager; import com.cleanroommc.modularui.widget.WidgetTree; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.PacketBuffer; import net.minecraftforge.client.event.GuiOpenEvent; @@ -41,7 +43,8 @@ public static void open(@NotNull UIFactory factory, @NotN if (HoloUI.isOpen(panel)) { HoloUI.builder() .inFrontOf(player, 5, true) - .reposition(panel.getName()); + .reposition(panel.getName(), player); + NetworkHandler.sendToPlayer(new SyncHoloPacket(panel.getName()), player); ModularUI.LOGGER.warn("reposition the holo, sync to client"); return; } @@ -91,6 +94,13 @@ public static void open(int windowId, @NotNull UIFactory }, player.getEntityWorld()); } + public static void reposition(String panel, EntityPlayer player) { + HoloUI.builder() +// .screenScale(0.25f) + .inFrontOf(player, 5, true) + .reposition(panel, player); + } + //todo make this a mixin instead of using event to cancel arm animation stuff @SideOnly(Side.CLIENT) @SubscribeEvent diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index d26f9b803..c03f4fca9 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -108,10 +108,14 @@ public void open(Consumer entityConsumer, World world) { // holoScreenEntity.setOrientation(this.orientation); } - public void reposition(String name) { + public void reposition(String name, EntityPlayer player) { var screen = syncedHolos.get(name); screen.setPosition(this.x, this.y, this.z); screen.setOrientation(this.orientation); + if (player.world.isRemote){ + var vec = screen.getPositionVector().subtract(player.getPositionVector()); + screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z); + } } } } diff --git a/src/main/java/com/cleanroommc/modularui/network/NetworkHandler.java b/src/main/java/com/cleanroommc/modularui/network/NetworkHandler.java index db83f8760..6e950a95e 100644 --- a/src/main/java/com/cleanroommc/modularui/network/NetworkHandler.java +++ b/src/main/java/com/cleanroommc/modularui/network/NetworkHandler.java @@ -25,6 +25,7 @@ public static void init() { registerC2S(PacketSyncHandler.class); registerC2S(SyncConfig.class); registerS2C(OpenGuiPacket.class); + registerS2C(SyncHoloPacket.class); //registerC2S(OpenGuiHandshake.class); } diff --git a/src/main/java/com/cleanroommc/modularui/network/packets/SyncHoloPacket.java b/src/main/java/com/cleanroommc/modularui/network/packets/SyncHoloPacket.java new file mode 100644 index 000000000..088547f77 --- /dev/null +++ b/src/main/java/com/cleanroommc/modularui/network/packets/SyncHoloPacket.java @@ -0,0 +1,41 @@ +package com.cleanroommc.modularui.network.packets; + +import com.cleanroommc.modularui.factory.HoloGuiManager; +import com.cleanroommc.modularui.network.IPacket; + +import com.cleanroommc.modularui.network.NetworkUtils; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.PacketBuffer; + +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; + +public class SyncHoloPacket implements IPacket { + + String panel; + + public SyncHoloPacket() {} + + public SyncHoloPacket(String panel) { + this.panel = panel; + } + + @Override + public void write(PacketBuffer buf) throws IOException { + NetworkUtils.writeStringSafe(buf, this.panel); + } + + @Override + public void read(PacketBuffer buf) throws IOException { + this.panel = NetworkUtils.readStringSafe(buf); + } + + @Override + public @Nullable IPacket executeClient(NetHandlerPlayClient handler) { + HoloGuiManager.reposition(this.panel, Minecraft.getMinecraft().player); + return null; + } +} From 092e6b36c24e8158fd08b4449f21d0ec820b6d52 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:49:57 -0700 Subject: [PATCH 43/51] test and fix scale --- .../com/cleanroommc/modularui/factory/HoloGuiManager.java | 2 ++ .../com/cleanroommc/modularui/holoui/ScreenEntityRender.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index e59eb6bc5..bd0641bca 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -51,6 +51,7 @@ public static void open(@NotNull UIFactory factory, @NotN WidgetTree.collectSyncValues(syncManager, panel); ModularContainer container = new ModularContainer(syncManager); HoloUI.builder() + .screenScale(0.5f) .inFrontOf(player, 5, true) .open(screen -> { screen.setContainer(container); @@ -87,6 +88,7 @@ public static void open(int windowId, @NotNull UIFactory HoloUI.builder() // .screenScale(0.25f) .inFrontOf(player, 5, true) + .screenScale(0.5f) .open(screen1 -> { screen1.setPanel(panel); screen1.setWrapper(guiScreenWrapper); diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index 60ae2fa15..e418487f7 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -120,8 +120,8 @@ private static Vec3i calculateMousePos(Vec3d player, HoloScreenEntity screen, Ve // the x, y of look rot should be the mouse pos if scaled by looRot z // the scale factor should be the distance from the player to the plane by the z component of lookRot double sf = diff.z / lookRot.z; - double mX = ((lookRot.x * sf) - diff.x) * 16; - double mY = ((lookRot.y * sf) - diff.y) * 16; + double mX = ((lookRot.x * sf) - diff.x) * 16 / plane.getScale(); + double mY = ((lookRot.y * sf) - diff.y) * 16 / plane.getScale(); mY += plane.getHeight() / 2; mX += plane.getWidth() / 2; From b7da624bd681fd2eefec9b8c60bf27f1901e4995 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:32:17 -0700 Subject: [PATCH 44/51] fix rebase --- .../cleanroommc/modularui/factory/HoloGuiManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index bd0641bca..c20e358ea 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -9,7 +9,7 @@ import com.cleanroommc.modularui.network.packets.OpenGuiPacket; import com.cleanroommc.modularui.network.packets.SyncHoloPacket; import com.cleanroommc.modularui.screen.*; -import com.cleanroommc.modularui.value.sync.GuiSyncManager; +import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.widget.WidgetTree; import net.minecraft.client.Minecraft; @@ -38,7 +38,7 @@ public static void open(@NotNull UIFactory factory, @NotN if (player instanceof FakePlayer) return; // create panel, collect sync handlers and create container guiData.setJeiSettings(JeiSettings.DUMMY); - GuiSyncManager syncManager = new GuiSyncManager(player); + PanelSyncManager syncManager = new PanelSyncManager(); ModularPanel panel = factory.createPanel(guiData, syncManager); if (HoloUI.isOpen(panel)) { HoloUI.builder() @@ -49,7 +49,7 @@ public static void open(@NotNull UIFactory factory, @NotN return; } WidgetTree.collectSyncValues(syncManager, panel); - ModularContainer container = new ModularContainer(syncManager); + ModularContainer container = new ModularContainer(null); HoloUI.builder() .screenScale(0.5f) .inFrontOf(player, 5, true) @@ -78,12 +78,12 @@ public static void open(int windowId, @NotNull UIFactory T guiData = factory.readGuiData(player, data); JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); guiData.setJeiSettings(jeiSettings); - GuiSyncManager syncManager = new GuiSyncManager(player); + PanelSyncManager syncManager = new PanelSyncManager(); ModularPanel panel = factory.createPanel(guiData, syncManager); WidgetTree.collectSyncValues(syncManager, panel); ModularScreen screen = factory.createScreen(guiData, panel); screen.getContext().setJeiSettings(jeiSettings); - GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(syncManager), screen); + GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(null), screen); guiScreenWrapper.inventorySlots.windowId = windowId; HoloUI.builder() // .screenScale(0.25f) From 4c904fcbf48abf4d52ccb161fe6a2eb91ee7f7a7 Mon Sep 17 00:00:00 2001 From: brachy84 Date: Sun, 7 Jul 2024 13:25:07 +0200 Subject: [PATCH 45/51] fix errors --- .../modularui/factory/HoloGuiManager.java | 27 ++++++++++------- .../modularui/holoui/HoloScreenEntity.java | 10 ++++++- .../cleanroommc/modularui/holoui/HoloUI.java | 30 ++++++------------- .../modularui/test/TestHoloItem.java | 5 ++++ .../cleanroommc/modularui/test/TestItem.java | 4 +++ 5 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index c20e358ea..fa9044e17 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -1,13 +1,12 @@ package com.cleanroommc.modularui.factory; -import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.api.JeiSettings; import com.cleanroommc.modularui.api.UIFactory; +import com.cleanroommc.modularui.holoui.HoloScreenEntity; import com.cleanroommc.modularui.holoui.HoloUI; import com.cleanroommc.modularui.holoui.ScreenEntityRender; import com.cleanroommc.modularui.network.NetworkHandler; import com.cleanroommc.modularui.network.packets.OpenGuiPacket; -import com.cleanroommc.modularui.network.packets.SyncHoloPacket; import com.cleanroommc.modularui.screen.*; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.widget.WidgetTree; @@ -29,6 +28,8 @@ import io.netty.buffer.Unpooled; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class HoloGuiManager extends GuiManager { @@ -40,23 +41,27 @@ public static void open(@NotNull UIFactory factory, @NotN guiData.setJeiSettings(JeiSettings.DUMMY); PanelSyncManager syncManager = new PanelSyncManager(); ModularPanel panel = factory.createPanel(guiData, syncManager); - if (HoloUI.isOpen(panel)) { - HoloUI.builder() + List screens = player.world.getEntities(HoloScreenEntity.class, entity -> entity.isName(panel.getName())); + if (!screens.isEmpty()) { + for (HoloScreenEntity screen : screens) { + screen.setDead(); + } + /*HoloUI.builder() .inFrontOf(player, 5, true) - .reposition(panel.getName(), player); + .reposition(player, screens); NetworkHandler.sendToPlayer(new SyncHoloPacket(panel.getName()), player); ModularUI.LOGGER.warn("reposition the holo, sync to client"); - return; + return;*/ } WidgetTree.collectSyncValues(syncManager, panel); - ModularContainer container = new ModularContainer(null); + ModularContainer container = new ModularContainer(player, syncManager, panel.getName()); HoloUI.builder() .screenScale(0.5f) .inFrontOf(player, 5, true) .open(screen -> { screen.setContainer(container); screen.setPanel(panel); - HoloUI.registerSyncedHoloUI(panel, screen); + //HoloUI.registerSyncedHoloUI(panel, screen); }, player.getEntityWorld()); // sync to client // player.getNextWindowId(); @@ -83,7 +88,7 @@ public static void open(int windowId, @NotNull UIFactory WidgetTree.collectSyncValues(syncManager, panel); ModularScreen screen = factory.createScreen(guiData, panel); screen.getContext().setJeiSettings(jeiSettings); - GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(null), screen); + GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(player, syncManager, panel.getName()), screen); guiScreenWrapper.inventorySlots.windowId = windowId; HoloUI.builder() // .screenScale(0.25f) @@ -92,7 +97,7 @@ public static void open(int windowId, @NotNull UIFactory .open(screen1 -> { screen1.setPanel(panel); screen1.setWrapper(guiScreenWrapper); - HoloUI.registerSyncedHoloUI(panel, screen1); + //HoloUI.registerSyncedHoloUI(panel, screen1); }, player.getEntityWorld()); } @@ -100,7 +105,7 @@ public static void reposition(String panel, EntityPlayer player) { HoloUI.builder() // .screenScale(0.25f) .inFrontOf(player, 5, true) - .reposition(panel, player); + .reposition(player, player.world.getEntities(HoloScreenEntity.class, entity -> entity.isName(panel))); } //todo make this a mixin instead of using event to cancel arm animation stuff diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index ab57506e7..dd6cb8fde 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -1,6 +1,9 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.*; +import com.cleanroommc.modularui.screen.GuiScreenWrapper; +import com.cleanroommc.modularui.screen.ModularContainer; +import com.cleanroommc.modularui.screen.ModularPanel; +import com.cleanroommc.modularui.screen.ModularScreen; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; @@ -75,6 +78,11 @@ public ScreenOrientation getOrientation() { return ScreenOrientation.values()[this.dataManager.get(ORIENTATION)]; } + public boolean isName(String name) { + if (this.panel == null) return false; + return this.panel.getName().equals(name); + } + public Plane3D getPlane3D() { return this.plane3D; } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index c03f4fca9..946a649d2 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -1,16 +1,13 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.ModularPanel; - import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; -import java.util.Map; +import java.util.Collection; import java.util.function.Consumer; /** @@ -19,16 +16,6 @@ @ApiStatus.Experimental public class HoloUI { - private static final Map syncedHolos = new Object2ObjectOpenHashMap<>(); - - public static void registerSyncedHoloUI(ModularPanel mainPanel, HoloScreenEntity entity) { - syncedHolos.put(mainPanel.getName(), entity); - } - - public static boolean isOpen(ModularPanel panel) { - return syncedHolos.containsKey(panel.getName()); - } - public static Builder builder() { return new Builder(); } @@ -108,13 +95,14 @@ public void open(Consumer entityConsumer, World world) { // holoScreenEntity.setOrientation(this.orientation); } - public void reposition(String name, EntityPlayer player) { - var screen = syncedHolos.get(name); - screen.setPosition(this.x, this.y, this.z); - screen.setOrientation(this.orientation); - if (player.world.isRemote){ - var vec = screen.getPositionVector().subtract(player.getPositionVector()); - screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z); + public void reposition(EntityPlayer player, Collection screens) { + for (HoloScreenEntity screen : screens) { + screen.setPosition(this.x, this.y, this.z); + screen.setOrientation(this.orientation); + if (player.world.isRemote) { + var vec = screen.getPositionVector().subtract(player.getPositionVector()); + screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z); + } } } } diff --git a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java index 30bfb7383..6d766c92e 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestHoloItem.java @@ -15,6 +15,11 @@ public class TestHoloItem extends TestItem { public static final TestHoloItem testHoloItem = new TestHoloItem(); + + public TestHoloItem() { + setTranslationKey("mui.test_holo"); + } + @NotNull @Override public ActionResult onItemRightClick(World world, @NotNull EntityPlayer player, @NotNull EnumHand hand) { diff --git a/src/main/java/com/cleanroommc/modularui/test/TestItem.java b/src/main/java/com/cleanroommc/modularui/test/TestItem.java index e61f93aa4..ba1425285 100644 --- a/src/main/java/com/cleanroommc/modularui/test/TestItem.java +++ b/src/main/java/com/cleanroommc/modularui/test/TestItem.java @@ -38,6 +38,10 @@ public class TestItem extends Item implements IGuiHolder { public static final TestItem testItem = new TestItem(); + public TestItem() { + setTranslationKey("mui.test"); + } + @Override public ModularPanel buildUI(HandGuiData guiData, PanelSyncManager guiSyncManager) { IItemHandlerModifiable itemHandler = (IItemHandlerModifiable) guiData.getUsedItemStack().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); From 664ded7ea5d8c57c4865469f01a60ecaff159863 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 3 Oct 2024 00:21:59 -0700 Subject: [PATCH 46/51] partially fix rebase --- .../cleanroommc/modularui/factory/HoloGuiManager.java | 2 +- .../cleanroommc/modularui/holoui/HoloScreenEntity.java | 5 +---- .../java/com/cleanroommc/modularui/holoui/Plane3D.java | 6 ++++-- .../cleanroommc/modularui/holoui/ScreenEntityRender.java | 5 ++--- .../java/com/cleanroommc/modularui/widgets/ItemSlot.java | 9 ++++----- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index fa9044e17..059fd24f4 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -88,7 +88,7 @@ public static void open(int windowId, @NotNull UIFactory WidgetTree.collectSyncValues(syncManager, panel); ModularScreen screen = factory.createScreen(guiData, panel); screen.getContext().setJeiSettings(jeiSettings); - GuiScreenWrapper guiScreenWrapper = new GuiScreenWrapper(new ModularContainer(player, syncManager, panel.getName()), screen); + GuiContainerWrapper guiScreenWrapper = new GuiContainerWrapper(new ModularContainer(player, syncManager, panel.getName()), screen); guiScreenWrapper.inventorySlots.windowId = windowId; HoloUI.builder() // .screenScale(0.25f) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index dd6cb8fde..5b17efcc4 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -1,9 +1,6 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.screen.GuiScreenWrapper; -import com.cleanroommc.modularui.screen.ModularContainer; -import com.cleanroommc.modularui.screen.ModularPanel; -import com.cleanroommc.modularui.screen.ModularScreen; +import com.cleanroommc.modularui.screen.*; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index f8351638c..f2a2ab416 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -2,12 +2,14 @@ import com.cleanroommc.modularui.utils.GuiUtils; +import com.cleanroommc.modularui.utils.Matrix4f; + +import com.cleanroommc.modularui.utils.Vector3f; + import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.ApiStatus; -import org.lwjgl.util.vector.Matrix4f; -import org.lwjgl.util.vector.Vector3f; /** * Highly experimental diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index e418487f7..fffd79582 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -1,6 +1,5 @@ package com.cleanroommc.modularui.holoui; -import com.cleanroommc.modularui.ModularUI; import com.cleanroommc.modularui.screen.GuiContainerWrapper; import com.cleanroommc.modularui.utils.Animator; @@ -57,8 +56,8 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl plane3D.transform(); } var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); - screenWrapper.drawScreen(mouse.getX(), mouse.getY(), partialTicks); -// screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); +// screenWrapper.drawScreen(mouse.getX(), mouse.getY(), partialTicks); + screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); screen.onFrameUpdate(); UUID id = player.getUniqueID(); diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index 7cad866f3..86bccae65 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -225,8 +225,8 @@ private void drawSlot(Slot slotIn) { } float z = 100f; - // todo fix - ((GuiAccessor) guiScreen).setZLevel(z); + float zStart = ((GuiAccessor) guiScreen).getZLevel(); + ((GuiAccessor) guiScreen).setZLevel(zStart + z); renderItem.zLevel += z; if (!flag1) { @@ -239,7 +239,7 @@ private void drawSlot(Slot slotIn) { // render the item itself // renderItem.renderItemAndEffectIntoGUI(guiScreen.mc.player, itemstack, 1, 1); // guiScreen.getItemRenderer().renderItemAndEffectIntoGUI(guiScreen.mc.player, itemstack, 1, 1); - guiScreen.drawItem(itemstack, 1, 1); + renderItem.renderItemIntoGUI(itemstack, 1, 1); if (amount < 0) { amount = itemstack.getCount(); } @@ -280,8 +280,7 @@ private void drawSlot(Slot slotIn) { } } - // todo fix - ((GuiAccessor) guiScreen).setZLevel(0f); + ((GuiAccessor) guiScreen).setZLevel(zStart); renderItem.zLevel -= z; } From aa44802a663c134c79601ab3a7c07c3dfc906519 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:45:18 -0700 Subject: [PATCH 47/51] commit whatever this is --- .../modularui/factory/HoloGuiManager.java | 2 -- .../modularui/holoui/HoloScreenEntity.java | 25 ++++++++----------- .../cleanroommc/modularui/holoui/HoloUI.java | 23 ++++++++--------- .../cleanroommc/modularui/holoui/Plane3D.java | 7 ++++++ .../modularui/holoui/ScreenEntityRender.java | 8 +++--- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java index 059fd24f4..00e3eb102 100644 --- a/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java +++ b/src/main/java/com/cleanroommc/modularui/factory/HoloGuiManager.java @@ -59,7 +59,6 @@ public static void open(@NotNull UIFactory factory, @NotN .screenScale(0.5f) .inFrontOf(player, 5, true) .open(screen -> { - screen.setContainer(container); screen.setPanel(panel); //HoloUI.registerSyncedHoloUI(panel, screen); }, player.getEntityWorld()); @@ -97,7 +96,6 @@ public static void open(int windowId, @NotNull UIFactory .open(screen1 -> { screen1.setPanel(panel); screen1.setWrapper(guiScreenWrapper); - //HoloUI.registerSyncedHoloUI(panel, screen1); }, player.getEntityWorld()); } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 5b17efcc4..8f9faf43a 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -1,5 +1,7 @@ package com.cleanroommc.modularui.holoui; +import com.cleanroommc.modularui.api.IMuiScreen; +import com.cleanroommc.modularui.api.MCHelper; import com.cleanroommc.modularui.screen.*; import net.minecraft.block.Block; @@ -24,8 +26,7 @@ @ApiStatus.Experimental public class HoloScreenEntity extends Entity { - private GuiContainerWrapper wrapper; - private ModularContainer container; + private IMuiScreen wrapper; private ModularPanel panel; private final Plane3D plane3D; private static final DataParameter ORIENTATION = EntityDataManager.createKey(HoloScreenEntity.class, DataSerializers.BYTE); @@ -39,16 +40,11 @@ public HoloScreenEntity(World world) { this(world, new Plane3D()); } - public void setWrapper(GuiContainerWrapper wrapper) { + public void setWrapper(IMuiScreen wrapper) { this.wrapper = wrapper; - this.wrapper.setWorldAndResolution(Minecraft.getMinecraft(), (int) this.plane3D.getWidth(), (int) this.plane3D.getHeight()); - this.getScreen().getContext().holoScreen = this; - this.getScreen().getContext().isHoloScreen = true; - setContainer(wrapper.getScreen().getContainer()); - } - - public void setContainer(ModularContainer container) { - this.container = container; + this.wrapper.getGuiScreen().setWorldAndResolution(Minecraft.getMinecraft(), (int) this.plane3D.getWidth(), (int) this.plane3D.getHeight()); + this.wrapper.getScreen().getContext().holoScreen = this; + this.wrapper.getScreen().getContext().isHoloScreen = true; } public void setPanel(ModularPanel panel) { @@ -59,7 +55,7 @@ public ModularScreen getScreen() { return this.getWrapper().getScreen(); } - public GuiContainerWrapper getWrapper() { + public IMuiScreen getWrapper() { return this.wrapper; } @@ -110,8 +106,9 @@ public void onEntityUpdate() { this.getEntityWorld().removeEntity(this); return; } - if (w != this.wrapper.width || h != this.wrapper.height) { - this.wrapper.onResize(Minecraft.getMinecraft(), w, h); + var wrapper = this.wrapper.getGuiScreen(); + if (w != wrapper.width || h != wrapper.height) { + wrapper.onResize(Minecraft.getMinecraft(), w, h); } this.wrapper.getScreen().onUpdate(); } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 946a649d2..42bbf162c 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -1,5 +1,6 @@ package com.cleanroommc.modularui.holoui; +import net.minecraft.client.renderer.Vector3d; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -23,21 +24,25 @@ public static Builder builder() { public static class Builder { private double x, y, z; + private Vec3d from, to; private Plane3D plane3D = new Plane3D(); private ScreenOrientation orientation = ScreenOrientation.FIXED; + private Builder() { + from = to = Vec3d.ZERO; + } + public Builder at(double x, double y, double z) { this.x = x; this.y = y; this.z = z; + this.from = new Vec3d(this.x - 0.5D, this.y - 0.5D, this.z - 0.5D); + this.to = new Vec3d(this.x + 0.5D, this.y + 0.5D, this.z + 0.5D); return this; } public Builder at(BlockPos pos) { - this.x = pos.getX() + 0.5D; - this.y = pos.getY() + 0.5D; - this.z = pos.getZ() + 0.5D; - return this; + return at(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); } public Builder inFrontOf(EntityPlayer player, double distance, boolean fixed) { @@ -79,20 +84,12 @@ public Builder plane(Plane3D plane) { } public void open(Consumer entityConsumer, World world) { -// JeiSettingsImpl jeiSettings = new JeiSettingsImpl(); -// jeiSettings.disableJei(); -// screen.getContext().setJeiSettings(jeiSettings); - -// wrapper.getScreen().getContext().isHoloScreen = true; + this.plane3D.setBounds(this.from, this.to); HoloScreenEntity screen = new HoloScreenEntity(world, this.plane3D); screen.setPosition(this.x, this.y, this.z); screen.setOrientation(this.orientation); entityConsumer.accept(screen); screen.spawnInWorld(); -// holoScreenEntity.setPosition(this.x, this.y, this.z); -// holoScreenEntity.setWrapper(wrapper); -// holoScreenEntity.spawnInWorld(); -// holoScreenEntity.setOrientation(this.orientation); } public void reposition(EntityPlayer player, Collection screens) { diff --git a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java index f2a2ab416..d8eaecdae 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/Plane3D.java @@ -22,6 +22,8 @@ public class Plane3D { private float aX = 0.5f, aY = 0.5f; private Vec3d normal = Direction.NORTH.asVec3d(); private Vec3d rotation = this.normal; + private Vec3d from = Vec3d.ZERO; + private Vec3d to = new Vec3d(1, 1, 0); public void transform() { @@ -61,6 +63,11 @@ public void transform(Vec3d target, Vec3d orig) { GlStateManager.translate(-(this.w / 2f), -(this.h / 2f), 0); } + public void setBounds(Vec3d from, Vec3d to) { + this.from = from; + this.to = to; + } + public void setSize(float w, float h) { this.w = w; this.h = h; diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index fffd79582..51d64c2a6 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -1,9 +1,11 @@ package com.cleanroommc.modularui.holoui; +import com.cleanroommc.modularui.api.IMuiScreen; import com.cleanroommc.modularui.screen.GuiContainerWrapper; import com.cleanroommc.modularui.utils.Animator; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.culling.ICamera; import net.minecraft.client.renderer.entity.Render; @@ -28,7 +30,7 @@ */ @ApiStatus.Experimental public class ScreenEntityRender extends Render { - private static final Map lookingPlayers = new Object2ObjectOpenHashMap<>(); + private static final Map lookingPlayers = new Object2ObjectOpenHashMap<>(); public ScreenEntityRender(RenderManager renderManager) { super(renderManager); @@ -42,7 +44,7 @@ protected ResourceLocation getEntityTexture(@NotNull HoloScreenEntity entity) { @Override public void doRender(@NotNull HoloScreenEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { - GuiContainerWrapper screenWrapper = entity.getWrapper(); + var screenWrapper = entity.getWrapper(); if (screenWrapper == null) return; var screen = screenWrapper.getScreen(); @@ -73,7 +75,7 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl public static void clickScreen(EntityPlayer player) { if (lookingPlayers.containsKey(player.getUniqueID())) { try { - lookingPlayers.get(player.getUniqueID()).handleMouseInput(); + lookingPlayers.get(player.getUniqueID()).getGuiScreen().handleMouseInput(); } catch (Throwable throwable1) { CrashReport c = CrashReport.makeCrashReport(throwable1, "Updating screen events"); c.makeCategory("Affected screen") From 745afa76b79cd749517181f214a2219b10736473 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:31:57 -0700 Subject: [PATCH 48/51] screen actually renders now --- .../com/cleanroommc/modularui/holoui/HoloScreenEntity.java | 7 +++++++ src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java | 1 + .../cleanroommc/modularui/holoui/ScreenEntityRender.java | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java index 8f9faf43a..5971a231a 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloScreenEntity.java @@ -61,6 +61,13 @@ public IMuiScreen getWrapper() { public void spawnInWorld() { getEntityWorld().spawnEntity(this); + if (world.isRemote) + onResize(); + } + + @SideOnly(Side.CLIENT) + public void onResize() { + getScreen().onResize((int) plane3D.getWidth(), (int) plane3D.getHeight()); } public void setOrientation(ScreenOrientation orientation) { diff --git a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java index 42bbf162c..fdb281f5e 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/HoloUI.java @@ -99,6 +99,7 @@ public void reposition(EntityPlayer player, Collection screens if (player.world.isRemote) { var vec = screen.getPositionVector().subtract(player.getPositionVector()); screen.getPlane3D().setNormal((float) -vec.x, 0, (float) -vec.z); + screen.onResize(); } } } diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index 51d64c2a6..b29ba2168 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -1,6 +1,8 @@ package com.cleanroommc.modularui.holoui; import com.cleanroommc.modularui.api.IMuiScreen; +import com.cleanroommc.modularui.api.MCHelper; +import com.cleanroommc.modularui.screen.ClientScreenHandler; import com.cleanroommc.modularui.screen.GuiContainerWrapper; import com.cleanroommc.modularui.utils.Animator; @@ -58,7 +60,7 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl plane3D.transform(); } var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); -// screenWrapper.drawScreen(mouse.getX(), mouse.getY(), partialTicks); +// ClientScreenHandler.drawScreen(screen, screenWrapper.getGuiScreen(), mouse.getX(), mouse.getY(), partialTicks); screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); screen.onFrameUpdate(); @@ -89,7 +91,7 @@ public static void clickScreen(EntityPlayer player) { public boolean shouldRender(HoloScreenEntity screen, ICamera camera, double camX, double camY, double camZ) { boolean render = super.shouldRender(screen, camera, camX, camY, camZ); if (!render) { - lookingPlayers.remove(Minecraft.getMinecraft().player.getUniqueID()); + lookingPlayers.remove(MCHelper.getMc().player.getUniqueID()); } return render; } From b97f4054a1dd1ed70aa1af3d89a7585f9e0e9a88 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:16:35 -0700 Subject: [PATCH 49/51] fix item position --- .../com/cleanroommc/modularui/holoui/ScreenEntityRender.java | 1 - src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index b29ba2168..f03cab7e1 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -60,7 +60,6 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl plane3D.transform(); } var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); -// ClientScreenHandler.drawScreen(screen, screenWrapper.getGuiScreen(), mouse.getX(), mouse.getY(), partialTicks); screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); screen.onFrameUpdate(); diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index 86bccae65..92d464150 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -224,7 +224,7 @@ private void drawSlot(Slot slotIn) { } } - float z = 100f; + float z = getContext().isHoloScreen ? -100f : 100f; float zStart = ((GuiAccessor) guiScreen).getZLevel(); ((GuiAccessor) guiScreen).setZLevel(zStart + z); renderItem.zLevel += z; From e8393873af690fd0895e96859656904d1a9071fb Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:35:59 -0700 Subject: [PATCH 50/51] interaction kinda works --- .../cleanroommc/modularui/holoui/ScreenEntityRender.java | 4 +++- .../java/com/cleanroommc/modularui/widgets/ItemSlot.java | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index f03cab7e1..af6cff1e7 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -60,7 +60,9 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl plane3D.transform(); } var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); - screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); + screen.getContext().updateState(mouse.getX(), mouse.getY(), partialTicks); + ClientScreenHandler.drawScreenInternal(screen, screenWrapper.getGuiScreen(), mouse.getX(), mouse.getY(), partialTicks); +// screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); screen.onFrameUpdate(); UUID id = player.getUniqueID(); diff --git a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java index 92d464150..3c2bae702 100644 --- a/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java +++ b/src/main/java/com/cleanroommc/modularui/widgets/ItemSlot.java @@ -41,6 +41,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.IOException; + public class ItemSlot extends Widget implements IVanillaSlot, Interactable, JeiGhostIngredientSlot, JeiIngredientProvider { public static final int SIZE = 18; @@ -126,6 +128,13 @@ public int getSlotHoverColor() { if (this.syncHandler.isPhantom()) { MouseData mouseData = MouseData.create(mouseButton); this.syncHandler.syncToServer(2, mouseData::writeToPacket); + } else if (getContext().isHoloScreen) { + var holo = getContext().holoScreen.getScreen(); + if (holo.getScreenWrapper().getGuiScreen() instanceof GuiScreenAccessor acc) { + try { + acc.invokeMouseClicked(getContext().getMouseX(), getContext().getMouseY(), getContext().getMouseButton()); + } catch (IOException ignored) {} + } } else { ClientScreenHandler.clickSlot(); //getScreen().getScreenWrapper().clickSlot(); From 66680e86b4915ebc84b27633eeb8ea08280ff1c8 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:11:39 -0700 Subject: [PATCH 51/51] draw debug screen --- .../modularui/holoui/ScreenEntityRender.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java index af6cff1e7..2bd5a54c6 100644 --- a/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java +++ b/src/main/java/com/cleanroommc/modularui/holoui/ScreenEntityRender.java @@ -3,11 +3,9 @@ import com.cleanroommc.modularui.api.IMuiScreen; import com.cleanroommc.modularui.api.MCHelper; import com.cleanroommc.modularui.screen.ClientScreenHandler; -import com.cleanroommc.modularui.screen.GuiContainerWrapper; import com.cleanroommc.modularui.utils.Animator; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.culling.ICamera; import net.minecraft.client.renderer.entity.Render; @@ -48,7 +46,6 @@ protected ResourceLocation getEntityTexture(@NotNull HoloScreenEntity entity) { public void doRender(@NotNull HoloScreenEntity entity, double x, double y, double z, float entityYaw, float partialTicks) { var screenWrapper = entity.getWrapper(); if (screenWrapper == null) return; - var screen = screenWrapper.getScreen(); Plane3D plane3D = entity.getPlane3D(); GlStateManager.pushMatrix(); @@ -59,14 +56,11 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl } else { plane3D.transform(); } + var mouse = calculateMousePos(player.getPositionVector().add(0, player.getEyeHeight(), 0), entity, player.getLookVec()); - screen.getContext().updateState(mouse.getX(), mouse.getY(), partialTicks); - ClientScreenHandler.drawScreenInternal(screen, screenWrapper.getGuiScreen(), mouse.getX(), mouse.getY(), partialTicks); -// screen.drawScreen(mouse.getX(), mouse.getY(), partialTicks); - screen.onFrameUpdate(); + drawScreen(entity, mouse, partialTicks); UUID id = player.getUniqueID(); - Animator.advance(); if (withinScreen(mouse, entity.getPlane3D()) && !lookingPlayers.containsKey(id)) { lookingPlayers.put(id, screenWrapper); } else if (!withinScreen(mouse, entity.getPlane3D())) { @@ -75,6 +69,17 @@ public void doRender(@NotNull HoloScreenEntity entity, double x, double y, doubl GlStateManager.popMatrix(); } + private static void drawScreen(HoloScreenEntity entity, Vec3i mouse, float partialTicks) { + var screen = entity.getScreen(); + var mcScreen = screen.getScreenWrapper().getGuiScreen(); + + screen.getContext().updateState(mouse.getX(), mouse.getY(), partialTicks); + ClientScreenHandler.drawDebugScreen(screen, null); + ClientScreenHandler.drawScreenInternal(screen, mcScreen, mouse.getX(), mouse.getY(), partialTicks); + screen.onFrameUpdate(); + Animator.advance(); + } + public static void clickScreen(EntityPlayer player) { if (lookingPlayers.containsKey(player.getUniqueID())) { try {