From 130d91cb6ddc0cfb1072c5fafd844f98cd8f9d17 Mon Sep 17 00:00:00 2001 From: Srendi Date: Tue, 5 Nov 2024 22:53:40 +0100 Subject: [PATCH] Torus Object implemented, clean up some inconsistencies, clean up RenderUtil.java, support for rotation and floating number coordinates --- .../client/RenderUtil.java | 248 +++++++++--------- .../OverlayModuleLevelRenderer.java | 21 +- .../smartglasses/OverlayObjectHolder.java | 2 + .../objects/threedim/BlockRenderer.java | 25 +- .../objects/threedim/BoxRenderer.java | 21 +- .../objects/threedim/SphereRenderer.java | 20 +- .../objects/threedim/TorusRenderer.java | 47 ++++ .../objects/twodim/CircleRenderer.java | 13 +- .../objects/twodim/ItemRenderer.java | 6 +- .../objects/twodim/RectangleRenderer.java | 20 +- .../objects/twodim/TextRenderer.java | 4 +- .../overlay/OverlayGlassesFunctions.java | 9 + .../objects/three_dim/BlockObject.java | 20 +- .../overlay/objects/three_dim/BoxObject.java | 19 +- .../objects/three_dim/SphereObject.java | 60 ++++- .../three_dim/ThreeDimensionalObject.java | 46 ++++ .../objects/three_dim/TorusObject.java | 152 +++++++++++ .../overlay/objects/two_dim/CircleObject.java | 12 +- .../overlay/objects/two_dim/ItemObject.java | 12 +- .../objects/two_dim/RectangleObject.java | 13 +- .../objects/two_dim/RenderableObject.java | 58 ++-- .../overlay/objects/two_dim/TextObject.java | 12 +- 22 files changed, 569 insertions(+), 271 deletions(-) create mode 100644 src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/TorusRenderer.java create mode 100644 src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/TorusObject.java diff --git a/src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java b/src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java index 47333264a..68359833f 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java +++ b/src/main/java/de/srendi/advancedperipherals/client/RenderUtil.java @@ -4,33 +4,18 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Matrix4f; +import com.mojang.math.Quaternion; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Direction; -import net.minecraft.core.Vec3i; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.shapes.Shapes; -import net.minecraft.world.phys.shapes.VoxelShape; - -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; public class RenderUtil { - public static void drawBox(PoseStack stack, VertexConsumer buffer, float r, float g, float b, float a, float sX, float sY, float sZ) { - drawBox(stack, buffer, r, g, b, a, 0, 0, 0, sX, sY, sZ); - } - - public static void drawVoxelShape(PoseStack stack, VertexConsumer buffer, float r, float g, float b, float a, VoxelShape shape) { - drawVoxelShape(stack, buffer, shape, 0f, 0f, 0f, r, g, b, a); - } - - public static void drawBox(PoseStack stack, VertexConsumer buffer, float r, float g, float b, float a, float pX, float pY, float pZ, float sX, float sY, float sZ) { - stack.pushPose(); + public static void drawBox(PoseStack poseStack, VertexConsumer buffer, float r, float g, float b, float a, float pX, float pY, float pZ, float xRot, float yRot, float zRot, float sX, float sY, float sZ) { + poseStack.pushPose(); sX = sX / 16; //Sizes in pixels please sY = sY / 16; sZ = sZ / 16; @@ -38,25 +23,27 @@ public static void drawBox(PoseStack stack, VertexConsumer buffer, float r, floa pY = pY / 16; pZ = pZ / 16; - drawPlane(stack, buffer, r, g, b, a, Direction.UP, pX, pY, pZ, sX, sY, sZ); - drawPlane(stack, buffer, r, g, b, a, Direction.DOWN, pX, pY, pZ, sX, sY, sZ); - drawPlane(stack, buffer, r, g, b, a, Direction.EAST, pX, pY, pZ, sX, sY, sZ); - drawPlane(stack, buffer, r, g, b, a, Direction.WEST, pX, pY, pZ, sX, sY, sZ); - drawPlane(stack, buffer, r, g, b, a, Direction.NORTH, pX, pY, pZ, sX, sY, sZ); - drawPlane(stack, buffer, r, g, b, a, Direction.SOUTH, pX, pY, pZ, sX, sY, sZ); - stack.popPose(); + poseStack.mulPose(new Quaternion(xRot, yRot, zRot, true)); + + drawPlane(poseStack, buffer, r, g, b, a, Direction.UP, pX, pY, pZ, sX, sY, sZ); + drawPlane(poseStack, buffer, r, g, b, a, Direction.DOWN, pX, pY, pZ, sX, sY, sZ); + drawPlane(poseStack, buffer, r, g, b, a, Direction.EAST, pX, pY, pZ, sX, sY, sZ); + drawPlane(poseStack, buffer, r, g, b, a, Direction.WEST, pX, pY, pZ, sX, sY, sZ); + drawPlane(poseStack, buffer, r, g, b, a, Direction.NORTH, pX, pY, pZ, sX, sY, sZ); + drawPlane(poseStack, buffer, r, g, b, a, Direction.SOUTH, pX, pY, pZ, sX, sY, sZ); + poseStack.popPose(); } - public static void drawPlane(PoseStack stack, VertexConsumer buffer, float r, float g, float b, float a, Direction perspective, float pX, float pY, float pZ, float sX, float sY, float sZ) { - stack.pushPose(); + public static void drawPlane(PoseStack posestack, VertexConsumer buffer, float r, float g, float b, float a, Direction perspective, float pX, float pY, float pZ, float sX, float sY, float sZ) { + posestack.pushPose(); pX = pX + 0.5f; pY = pY + 0.5f; pZ = pZ + 0.5f; - stack.translate(pX, pY, pZ); - - Matrix4f matrix4f = stack.last().pose(); + posestack.translate(pX, pY, pZ); + + Matrix4f matrix4f = posestack.last().pose(); sX = sX / 2; sY = sY / 2; @@ -99,14 +86,96 @@ public static void drawPlane(PoseStack stack, VertexConsumer buffer, float r, fl buffer.vertex(matrix4f, sX, sY, sZ).color(r, g, b, a).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(0xF000F0).normal(0f, 1f, 0f).endVertex(); buffer.vertex(matrix4f, -sX, sY, sZ).color(r, g, b, a).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(0xF000F0).normal(0f, 1f, 0f).endVertex(); } - stack.popPose(); + posestack.popPose(); } - public static void drawSphere(PoseStack poseStack, BufferBuilder consumer, float radius, double pX, double pY, double pZ, float r, float g, float b, float a, int sectors, int stacks) { + public static void drawTorus(PoseStack poseStack, BufferBuilder consumer, float majorRadius, float minorRadius, double pX, double pY, double pZ, float xRot, float yRot, float zRot, float r, float g, float b, float a, int sides, int rings) { poseStack.pushPose(); + poseStack.translate(pX, pY, pZ); + poseStack.mulPose(new Quaternion(xRot, yRot, zRot, true)); + + Matrix4f matrix4f = poseStack.last().pose(); + float x, y, z; + float nx, ny, nz; // vertex normal + + float ringStep = (float) (2 * Math.PI / rings); + float sideStep = (float) (2 * Math.PI / sides); + float ringAngle, sideAngle; + + // Start drawing quads + for (int i = 0; i < rings; ++i) { + ringAngle = i * ringStep; + float cosRingAngle = (float) Math.cos(ringAngle); + float sinRingAngle = (float) Math.sin(ringAngle); + + float nextRingAngle = (i + 1) * ringStep; + float nextCosRingAngle = (float) Math.cos(nextRingAngle); + float nextSinRingAngle = (float) Math.sin(nextRingAngle); + + // Calculate the center point of the minor circles + float centerX = majorRadius * cosRingAngle; + float centerY = majorRadius * sinRingAngle; + float nextCenterX = majorRadius * nextCosRingAngle; + float nextCenterY = majorRadius * nextSinRingAngle; + + for (int j = 0; j < sides; ++j) { + sideAngle = j * sideStep; + float cosSideAngle = (float) Math.cos(sideAngle); + float sinSideAngle = (float) Math.sin(sideAngle); + + float nextSideAngle = (j + 1) * sideStep; + float nextCosSideAngle = (float) Math.cos(nextSideAngle); + float nextSinSideAngle = (float) Math.sin(nextSideAngle); + + // Calculate vertex positions + x = centerX + minorRadius * cosSideAngle * cosRingAngle; + y = centerY + minorRadius * cosSideAngle * sinRingAngle; + z = minorRadius * sinSideAngle; + + // Calculate normal (simplified - for smooth shading, average normals of adjacent faces) + nx = x - centerX; + ny = y - centerY; + nz = z; + consumer.vertex(matrix4f, x, y, z).color(r, g, b, a).overlayCoords(OverlayTexture.WHITE_OVERLAY_V).uv(0, 0).uv2(0xFFFFFF).normal(nx, ny, nz).endVertex(); + + x = centerX + minorRadius * nextCosSideAngle * cosRingAngle; + y = centerY + minorRadius * nextCosSideAngle * sinRingAngle; + z = minorRadius * nextSinSideAngle; + + nx = x - centerX; + ny = y - centerY; + nz = z; + consumer.vertex(matrix4f, x, y, z).color(r, g, b, a).overlayCoords(OverlayTexture.WHITE_OVERLAY_V).uv(1, 0).uv2(0xFFF0F0).normal(nx, ny, nz).endVertex(); + + x = nextCenterX + minorRadius * nextCosSideAngle * nextCosRingAngle; + y = nextCenterY + minorRadius * nextCosSideAngle * nextSinRingAngle; + z = minorRadius * nextSinSideAngle; + + nx = x - nextCenterX; + ny = y - nextCenterY; + nz = z; + consumer.vertex(matrix4f, x, y, z).color(r, g, b, a).overlayCoords(OverlayTexture.WHITE_OVERLAY_V).uv(0, 1).uv2(0xFFFFFF).normal(nx, ny, nz).endVertex(); + + x = nextCenterX + minorRadius * cosSideAngle * nextCosRingAngle; + y = nextCenterY + minorRadius * cosSideAngle * nextSinRingAngle; + z = minorRadius * sinSideAngle; + + nx = x - nextCenterX; + ny = y - nextCenterY; + nz = z; + consumer.vertex(matrix4f, x, y, z).color(r, g, b, a).overlayCoords(OverlayTexture.RED_OVERLAY_V).uv(1, 1).uv2(0xF000F0).normal(nx, ny, nz).endVertex(); + } + } + + poseStack.popPose(); + } + + public static void drawSphere(PoseStack poseStack, BufferBuilder consumer, float radius, double pX, double pY, double pZ, float xRot, float yRot, float zRot, float r, float g, float b, float a, int sectors, int stacks) { + poseStack.pushPose(); poseStack.translate(pX, pY, pZ); - + poseStack.mulPose(new Quaternion(xRot, yRot, zRot, true)); + Matrix4f matrix4f = poseStack.last().pose(); float z, xy; @@ -172,61 +241,8 @@ public static void drawSphere(PoseStack poseStack, BufferBuilder consumer, float } - public static void drawVoxelShape(PoseStack pPoseStack, VertexConsumer pConsumer, VoxelShape pShape, double pX, double pY, double pZ, float r, float g, float b, float a) { - for (Direction direction : Direction.values()) { - pShape.calculateFace(direction).forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> { - // Get the vertices for the face - float x1 = (float) (minX); - float y1 = (float) (minY); - float z1 = (float) (minZ); - float x2 = (float) (maxX); - float y2 = (float) (maxY); - float z2 = (float) (maxZ); - - // Calculate the normal for the face - Vec3i normalVec = direction.getNormal(); - float nx = normalVec.getX(); - float ny = normalVec.getY(); - float nz = normalVec.getZ(); - - PoseStack.Pose pose = pPoseStack.last(); - - //drawPlane(pPoseStack, pConsumer, r,g,b,a, direction, x1, y1, z1, x2, y2, z2); - // Draw the quad (two triangles) - pConsumer.vertex(pose.pose(), x1, y1, z1).color(r, g, b, a).normal(pose.normal(), nx, ny, nz).endVertex(); - pConsumer.vertex(pose.pose(), x2, y1, z1).color(r, g, b, a).normal(pose.normal(), nx, ny, nz).endVertex(); - pConsumer.vertex(pose.pose(), x2, y2, z2).color(r, g, b, a).normal(pose.normal(), nx, ny, nz).endVertex(); - pConsumer.vertex(pose.pose(), x1, y2, z2).color(r, g, b, a).normal(pose.normal(), nx, ny, nz).endVertex(); - }); - } - - } - - public static void drawShape(PoseStack pPoseStack, VertexConsumer pConsumer, VoxelShape pShape, double pX, double pY, double pZ, float r, float g, float b, float a) { - PoseStack.Pose pose = pPoseStack.last(); - pShape.forAllEdges((minX, minY, minZ, maxX, maxY, maxZ) -> { - float f = (float) (maxX - minX); - float f1 = (float) (maxY - minY); - float f2 = (float) (maxZ - minZ); - float f3 = Mth.sqrt(f * f + f1 * f1 + f2 * f2); - f /= f3; - f1 /= f3; - f2 /= f3; - pConsumer.vertex(pose.pose(), (float) (minX), (float) (minY), (float) (minZ)).color(r, g, b, a).normal(pose.normal(), f, f1, f2).endVertex(); - pConsumer.vertex(pose.pose(), (float) (maxX), (float) (maxY), (float) (maxZ)).color(r, g, b, a).normal(pose.normal(), f, f1, f2).endVertex(); - }); - } - - public static void drawBox(PoseStack stack, VertexConsumer buffer, ResourceLocation texture, float sX, float sY, float sZ, float pUOffset, float pVOffset, float pWidth, float pHeight) { - drawBox(stack, buffer, texture, 0, 0, 0, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - } - - public static void drawVoxelShape(PoseStack stack, VertexConsumer buffer, ResourceLocation texture, VoxelShape shape, float pUOffset, float pVOffset, float pWidth, float pHeight) { - renderVoxelShape(stack, buffer, texture, shape, pUOffset, pVOffset, pWidth, pHeight); - } - - public static void drawBox(PoseStack stack, VertexConsumer buffer, ResourceLocation texture, float pX, float pY, float pZ, float sX, float sY, float sZ, float pUOffset, float pVOffset, float pWidth, float pHeight) { - stack.pushPose(); + public static void drawBox(PoseStack poseStack, VertexConsumer buffer, ResourceLocation texture, float pX, float pY, float pZ, float xRot, float yRot, float zRot, float sX, float sY, float sZ, float pUOffset, float pVOffset, float pWidth, float pHeight) { + poseStack.pushPose(); sX = sX / 16; //Sizes in pixels please sY = sY / 16; sZ = sZ / 16; @@ -234,25 +250,27 @@ public static void drawBox(PoseStack stack, VertexConsumer buffer, ResourceLocat pY = pY / 16; pZ = pZ / 16; - drawPlane(stack, buffer, texture, Direction.UP, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - drawPlane(stack, buffer, texture, Direction.DOWN, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - drawPlane(stack, buffer, texture, Direction.EAST, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - drawPlane(stack, buffer, texture, Direction.WEST, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - drawPlane(stack, buffer, texture, Direction.NORTH, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - drawPlane(stack, buffer, texture, Direction.SOUTH, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); - stack.popPose(); + poseStack.mulPose(new Quaternion(xRot, yRot, zRot, true)); + + drawPlane(poseStack, buffer, texture, Direction.UP, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); + drawPlane(poseStack, buffer, texture, Direction.DOWN, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); + drawPlane(poseStack, buffer, texture, Direction.EAST, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); + drawPlane(poseStack, buffer, texture, Direction.WEST, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); + drawPlane(poseStack, buffer, texture, Direction.NORTH, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); + drawPlane(poseStack, buffer, texture, Direction.SOUTH, pX, pY, pZ, sX, sY, sZ, pUOffset, pVOffset, pWidth, pHeight); + poseStack.popPose(); } - public static void drawPlane(PoseStack stack, VertexConsumer buffer, ResourceLocation texture, Direction perspective, float pX, float pY, float pZ, float sX, float sY, float sZ, float pUOffset, float pVOffset, float pWidth, float pHeight) { - stack.pushPose(); + public static void drawPlane(PoseStack poseStack, VertexConsumer buffer, ResourceLocation texture, Direction perspective, float pX, float pY, float pZ, float sX, float sY, float sZ, float pUOffset, float pVOffset, float pWidth, float pHeight) { + poseStack.pushPose(); pX = pX + 0.5f; pY = pY + 0.5f; pZ = pZ + 0.5f; - stack.translate(pX, pY, pZ); + poseStack.translate(pX, pY, pZ); - Matrix4f matrix4f = stack.last().pose(); + Matrix4f matrix4f = poseStack.last().pose(); TextureAtlasSprite stillTexture = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(texture); @@ -301,33 +319,7 @@ public static void drawPlane(PoseStack stack, VertexConsumer buffer, ResourceLoc buffer.vertex(matrix4f, sX, sY, sZ).color(1, 1, 1, 1f).uv(u2, v1).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(0xF000F0).normal(0f, 1f, 0f).endVertex(); buffer.vertex(matrix4f, -sX, sY, sZ).color(1, 1, 1, 1f).uv(u2, v2).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(0xF000F0).normal(0f, 1f, 0f).endVertex(); } - stack.popPose(); - } - - public static void renderVoxelShape(PoseStack poseStack, VertexConsumer consumer, ResourceLocation texture, VoxelShape shape, float pUOffset, float pVOffset, float pWidth, float pHeight) { - List list = shape.toAabbs(); - - for (AABB aabb : list) { - drawShape(poseStack, consumer, texture, Shapes.create(aabb), pUOffset, pVOffset, pWidth, pHeight); - } - } - - private static void drawShape(PoseStack poseStack, VertexConsumer consumer, ResourceLocation texture, VoxelShape shape, float pUOffset, float pVOffset, float pWidth, float pHeight) { - AtomicInteger perspective = new AtomicInteger(); - shape.forAllEdges((minX, minY, minZ, maxX, maxY, maxZ) -> { - - minX = minX / 16; - minY = minY / 16; - minZ = minZ / 16; - maxX = maxX / 16; - maxY = maxY / 16; - maxZ = maxZ / 16; - - if (perspective.get() > 5) - perspective.set(0); - drawPlane(poseStack, consumer, texture, Direction.values()[perspective.getAndIncrement()], (float) minX, (float) minY, (float) minZ, (float) maxX, (float) maxY, (float) maxZ, pUOffset, pVOffset, pWidth, pHeight); - }); - perspective.set(0); + poseStack.popPose(); } public static float getBlue(int hex) { @@ -342,8 +334,4 @@ public static float getRed(int hex) { return (hex >> 16 & 0xFF) / 255.0F; } - public static float getAlpha(int hex) { - return (hex >> 24 & 0xFF) / 255.0F; - } - } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayModuleLevelRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayModuleLevelRenderer.java index 8a0fbac98..cdadf3988 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayModuleLevelRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayModuleLevelRenderer.java @@ -18,9 +18,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderLevelStageEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -82,30 +80,25 @@ public static void renderLevelState(RenderLevelStageEvent event) { BufferUploader.drawWithShader(bufferbuilder.end()); posestack.popPose(); + bufferbuilder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_COLOR_NORMAL); posestack.pushPose(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_NORMAL); - colors = EnumColor.LIGHT_PURPLE.getRgb(); - blockPos = new BlockPos(0, 10, 2); + blockPos = new BlockPos(0, 10, 0); posestack.translate(-view.x + blockPos.getX(), -view.y + blockPos.getY(), -view.z + blockPos.getZ()); - VoxelShape shape = Block.box(0.0, 0.0, 0.0, 16.0, 18.0, 16.0); - RenderSystem.setShaderColor(colors[0], colors[1], colors[2], 0.6f); - - RenderUtil.drawVoxelShape(posestack, bufferbuilder, shape, 0f, 0f, 0f, colors[0], colors[1], colors[2], 0.6f); - RenderSystem.setShaderColor(1f, 1f, 1f, 1f); + RenderUtil.drawSphere(posestack, bufferbuilder, 0.5f, 0f, 0f, 0f, 90f, 0f, 0f, colors[0], colors[1], colors[2], 0.6f, 128, 48); BufferUploader.drawWithShader(bufferbuilder.end()); posestack.popPose(); - bufferbuilder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_COLOR_NORMAL); + bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_NORMAL); posestack.pushPose(); - blockPos = new BlockPos(0, 10, 0); + colors = EnumColor.DARK_BLUE.getRgb(); + blockPos = new BlockPos(6, 10, 0); posestack.translate(-view.x + blockPos.getX(), -view.y + blockPos.getY(), -view.z + blockPos.getZ()); - RenderUtil.drawSphere(posestack, bufferbuilder, 0.5f, 0f, 0f, 0f, colors[0], colors[1], colors[2], 0.6f, 128, 48); + RenderUtil.drawTorus(posestack, bufferbuilder, 0.5f, 0.09f, 0f, 0f, 0f, 0f, 0f, 0f, colors[0], colors[1], colors[2], 0.6f, 300, 32); BufferUploader.drawWithShader(bufferbuilder.end()); posestack.popPose(); diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayObjectHolder.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayObjectHolder.java index 54da6ea07..3dc4d94a0 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayObjectHolder.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/OverlayObjectHolder.java @@ -4,6 +4,7 @@ import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BlockObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BoxObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.SphereObject; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.TorusObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.CircleObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.ItemObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RectangleObject; @@ -52,5 +53,6 @@ public static void registerDecodeObjects() { ObjectDecodeRegistry.register(BoxObject.TYPE_ID, BoxObject::decode); ObjectDecodeRegistry.register(BlockObject.TYPE_ID, BlockObject::decode); ObjectDecodeRegistry.register(SphereObject.TYPE_ID, SphereObject::decode); + ObjectDecodeRegistry.register(TorusObject.TYPE_ID, TorusObject::decode); } } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BlockRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BlockRenderer.java index 4276c39c0..a295543b6 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BlockRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BlockRenderer.java @@ -5,6 +5,8 @@ import com.mojang.blaze3d.vertex.BufferUploader; import com.mojang.blaze3d.vertex.DefaultVertexFormat; import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Quaternion; +import de.srendi.advancedperipherals.client.RenderUtil; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BlockObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.ThreeDimensionalObject; import de.srendi.advancedperipherals.common.util.RegistryUtil; @@ -25,33 +27,34 @@ public class BlockRenderer implements IThreeDObjectRenderer { public void renderBatch(List batch, RenderLevelStageEvent event, PoseStack poseStack, Vec3 view, BufferBuilder bufferBuilder) { poseStack.pushPose(); - for (ThreeDimensionalObject renderableObject : batch) { + for (ThreeDimensionalObject obj : batch) { poseStack.pushPose(); - onPreRender(renderableObject); + onPreRender(obj); bufferBuilder.begin(RenderType.solid().mode(), DefaultVertexFormat.BLOCK); - BlockObject block = (BlockObject) renderableObject; + BlockObject block = (BlockObject) obj; - BlockPos blockPos = new BlockPos(renderableObject.getX(), renderableObject.getY(), renderableObject.getZ()); - - poseStack.translate(-view.x + blockPos.getX(), -view.y + blockPos.getY(), -view.z + blockPos.getZ()); - float alpha = renderableObject.opacity; - float red = (float) (renderableObject.color >> 16 & 255) / 255.0F; - float green = (float) (renderableObject.color >> 8 & 255) / 255.0F; - float blue = (float) (renderableObject.color & 255) / 255.0F; + poseStack.translate(-view.x + block.getX(), -view.y + block.getY(), -view.z + block.getZ()); + poseStack.mulPose(new Quaternion(block.xRot, block.yRot, block.zRot, true)); + poseStack.translate(-0.5f, -0.5f, -0.5f); + float alpha = block.opacity; + float red = RenderUtil.getRed(block.color); + float green = RenderUtil.getGreen(block.color); + float blue = RenderUtil.getBlue(block.color); RenderSystem.setShader(GameRenderer::getBlockShader); RenderSystem.setShaderColor(red, green, blue, alpha); Block blockToRender = RegistryUtil.getRegistryEntry(block.block, ForgeRegistries.BLOCKS); + BlockPos blockPos = new BlockPos(obj.getX(), obj.getY(), obj.getZ()); if (blockToRender != null) Minecraft.getInstance().getBlockRenderer().renderBatched(blockToRender.defaultBlockState(), blockPos, event.getCamera().getEntity().level, poseStack, bufferBuilder, false, event.getCamera().getEntity().level.random); poseStack.popPose(); BufferUploader.drawWithShader(bufferBuilder.end()); - onPostRender(renderableObject); + onPostRender(obj); RenderSystem.setShaderColor(1f, 1f, 1f, 1f); } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BoxRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BoxRenderer.java index 873c1e7ea..16b2ee29e 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BoxRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/BoxRenderer.java @@ -7,6 +7,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexFormat; import de.srendi.advancedperipherals.client.RenderUtil; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BoxObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.ThreeDimensionalObject; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.world.phys.Vec3; @@ -20,21 +21,23 @@ public class BoxRenderer implements IThreeDObjectRenderer { public void renderBatch(List batch, RenderLevelStageEvent event, PoseStack poseStack, Vec3 view, BufferBuilder bufferBuilder) { poseStack.pushPose(); - for (ThreeDimensionalObject renderableObject : batch) { + for (ThreeDimensionalObject obj : batch) { poseStack.pushPose(); - onPreRender(renderableObject); + onPreRender(obj); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_NORMAL); + BoxObject box = (BoxObject) obj; + RenderSystem.setShader(GameRenderer::getPositionColorShader); - float alpha = renderableObject.opacity; - float red = (float) (renderableObject.color >> 16 & 255) / 255.0F; - float green = (float) (renderableObject.color >> 8 & 255) / 255.0F; - float blue = (float) (renderableObject.color & 255) / 255.0F; + float alpha = box.opacity; + float red = RenderUtil.getRed(box.color); + float green = RenderUtil.getGreen(box.color); + float blue = RenderUtil.getBlue(box.color); - poseStack.translate(-view.x + renderableObject.getX(), -view.y + renderableObject.getY(), -view.z + renderableObject.getZ()); - RenderUtil.drawBox(poseStack, bufferBuilder, red, green, blue, alpha, renderableObject.getMaxX(), renderableObject.getMaxY(), renderableObject.getMaxX()); + poseStack.translate(-view.x + box.getX(), -view.y + box.getY(), -view.z + box.getZ()); + RenderUtil.drawBox(poseStack, bufferBuilder, red, green, blue, alpha, box.x, box.y, box.z, obj.xRot, obj.yRot, obj.zRot, obj.getMaxX(), obj.getMaxY(), obj.getMaxX()); BufferUploader.drawWithShader(bufferBuilder.end()); - onPostRender(renderableObject); + onPostRender(obj); poseStack.popPose(); } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/SphereRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/SphereRenderer.java index e94071302..ebea9bd70 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/SphereRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/SphereRenderer.java @@ -21,23 +21,23 @@ public class SphereRenderer implements IThreeDObjectRenderer { public void renderBatch(List batch, RenderLevelStageEvent event, PoseStack poseStack, Vec3 view, BufferBuilder bufferBuilder) { poseStack.pushPose(); - for (ThreeDimensionalObject renderableObject : batch) { + for (ThreeDimensionalObject obj : batch) { poseStack.pushPose(); - onPreRender(renderableObject); + onPreRender(obj); bufferBuilder.begin(VertexFormat.Mode.TRIANGLES, DefaultVertexFormat.POSITION_COLOR_NORMAL); - SphereObject sphere = (SphereObject) renderableObject; + SphereObject sphere = (SphereObject) obj; RenderSystem.setShader(GameRenderer::getPositionColorShader); - float alpha = renderableObject.opacity; - float red = (float) (renderableObject.color >> 16 & 255) / 255.0F; - float green = (float) (renderableObject.color >> 8 & 255) / 255.0F; - float blue = (float) (renderableObject.color & 255) / 255.0F; + float alpha = sphere.opacity; + float red = RenderUtil.getRed(sphere.color); + float green = RenderUtil.getRed(sphere.color); + float blue = RenderUtil.getRed(sphere.color); - poseStack.translate(-view.x + renderableObject.getX(), -view.y + renderableObject.getY(), -view.z + renderableObject.getZ()); - RenderUtil.drawSphere(poseStack, bufferBuilder, 1f, 0f, 0f, 0f, red, green, blue, alpha, sphere.sectors, sphere.stacks); + poseStack.translate(-view.x, -view.y, -view.z); + RenderUtil.drawSphere(poseStack, bufferBuilder, sphere.radius, sphere.x, sphere.y, sphere.z, sphere.xRot, sphere.yRot, sphere.zRot, red, green, blue, alpha, sphere.sectors, sphere.stacks); BufferUploader.drawWithShader(bufferBuilder.end()); - onPostRender(renderableObject); + onPostRender(obj); poseStack.popPose(); } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/TorusRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/TorusRenderer.java new file mode 100644 index 000000000..478f1e6cc --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/threedim/TorusRenderer.java @@ -0,0 +1,47 @@ +package de.srendi.advancedperipherals.client.smartglasses.objects.threedim; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.BufferUploader; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexFormat; +import de.srendi.advancedperipherals.client.RenderUtil; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.ThreeDimensionalObject; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.TorusObject; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.world.phys.Vec3; +import net.minecraftforge.client.event.RenderLevelStageEvent; + +import java.util.List; + +public class TorusRenderer implements IThreeDObjectRenderer { + + @Override + public void renderBatch(List batch, RenderLevelStageEvent event, PoseStack poseStack, Vec3 view, BufferBuilder bufferBuilder) { + poseStack.pushPose(); + + for (ThreeDimensionalObject obj : batch) { + poseStack.pushPose(); + onPreRender(obj); + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_NORMAL); + + TorusObject torus = (TorusObject) obj; + + RenderSystem.setShader(GameRenderer::getPositionColorShader); + float alpha = torus.opacity; + float red = RenderUtil.getRed(torus.color); + float green = RenderUtil.getGreen(torus.color); + float blue = RenderUtil.getBlue(torus.color); + + poseStack.translate(-view.x + torus.x, -view.y + torus.y, -view.z + torus.z); + RenderUtil.drawTorus(poseStack, bufferBuilder, torus.majorRadius, torus.minorRadius, 0, 0, 0, torus.xRot, torus.yRot, torus.zRot, red, green, blue, alpha, torus.rings, torus.sides); + BufferUploader.drawWithShader(bufferBuilder.end()); + onPostRender(obj); + + poseStack.popPose(); + } + + poseStack.popPose(); + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/CircleRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/CircleRenderer.java index 42f3d9839..2f64946bd 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/CircleRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/CircleRenderer.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.math.Matrix4f; +import de.srendi.advancedperipherals.client.RenderUtil; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.CircleObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject; import net.minecraft.client.renderer.GameRenderer; @@ -19,14 +20,14 @@ public class CircleRenderer implements ITwoDObjectRenderer { @Override public void renderBatch(List objects, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { - for (RenderableObject object : objects) { + for (RenderableObject obj : objects) { - CircleObject circle = (CircleObject) object; + CircleObject circle = (CircleObject) obj; - float alpha = object.opacity; - float red = (float) (object.color >> 16 & 255) / 255.0F; - float green = (float) (object.color >> 8 & 255) / 255.0F; - float blue = (float) (object.color & 255) / 255.0F; + float alpha = circle.opacity; + float red = RenderUtil.getRed(circle.color); + float green = RenderUtil.getGreen(circle.color); + float blue = RenderUtil.getBlue(circle.color); drawCircle(poseStack, circle.x, circle.y, circle.radius, 120, red, green, blue, alpha); } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/ItemRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/ItemRenderer.java index cf3913fbd..b7f4c2913 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/ItemRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/ItemRenderer.java @@ -18,11 +18,11 @@ public class ItemRenderer implements ITwoDObjectRenderer { public void renderBatch(List objects, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { Minecraft minecraft = Minecraft.getInstance(); - for (RenderableObject object : objects) { - Item renderItem = RegistryUtil.getRegistryEntry(((ItemObject) object).item, ForgeRegistries.ITEMS); + for (RenderableObject obj : objects) { + Item renderItem = RegistryUtil.getRegistryEntry(((ItemObject) obj).item, ForgeRegistries.ITEMS); if (renderItem == null) continue; - minecraft.getItemRenderer().renderGuiItem(new ItemStack(renderItem), object.x, object.y); + minecraft.getItemRenderer().renderGuiItem(new ItemStack(renderItem), (int) obj.x, (int) obj.y); } } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/RectangleRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/RectangleRenderer.java index d0521ede1..872a5b6ea 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/RectangleRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/RectangleRenderer.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.blaze3d.vertex.VertexFormat; import com.mojang.math.Matrix4f; +import de.srendi.advancedperipherals.client.RenderUtil; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject; import net.minecraft.client.renderer.GameRenderer; import net.minecraftforge.client.gui.overlay.ForgeGui; @@ -23,19 +24,18 @@ public void renderBatch(List objects, ForgeGui gui, PoseStack Matrix4f matrix = poseStack.last().pose(); bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - for (RenderableObject object : objects) { - float alpha = object.opacity; - float red = (float) (object.color >> 16 & 255) / 255.0F; - float green = (float) (object.color >> 8 & 255) / 255.0F; - float blue = (float) (object.color & 255) / 255.0F; + for (RenderableObject obj : objects) { + float alpha = obj.opacity; + float red = RenderUtil.getRed(obj.color); + float green = RenderUtil.getGreen(obj.color); + float blue = RenderUtil.getBlue(obj.color); - bufferbuilder.vertex(matrix, (float) object.x, (float) object.maxY, 0f).color(red, green, blue, alpha).endVertex(); - bufferbuilder.vertex(matrix, (float) object.maxX, (float) object.maxY, 0f).color(red, green, blue, alpha).endVertex(); - bufferbuilder.vertex(matrix, (float) object.maxX, (float) object.y, 0f).color(red, green, blue, alpha).endVertex(); - bufferbuilder.vertex(matrix, (float) object.x, (float) object.y, 0f).color(red, green, blue, alpha).endVertex(); + bufferbuilder.vertex(matrix, obj.x, obj.maxY, 0f).color(red, green, blue, alpha).endVertex(); + bufferbuilder.vertex(matrix, obj.maxX, obj.maxY, 0f).color(red, green, blue, alpha).endVertex(); + bufferbuilder.vertex(matrix, obj.maxX, obj.y, 0f).color(red, green, blue, alpha).endVertex(); + bufferbuilder.vertex(matrix, obj.x, obj.y, 0f).color(red, green, blue, alpha).endVertex(); } BufferUploader.drawWithShader(bufferbuilder.end()); - } } diff --git a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/TextRenderer.java b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/TextRenderer.java index fdd376415..b80aa6e77 100644 --- a/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/TextRenderer.java +++ b/src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/twodim/TextRenderer.java @@ -14,8 +14,8 @@ public class TextRenderer implements ITwoDObjectRenderer { public void renderBatch(List objects, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { Minecraft minecraft = Minecraft.getInstance(); - for (RenderableObject object : objects) { - TextObject text = (TextObject) object; + for (RenderableObject obj : objects) { + TextObject text = (TextObject) obj; poseStack.scale(text.fontSize, text.fontSize, 1); if (text.shadow) { minecraft.font.drawShadow(poseStack, text.content, text.x / text.fontSize, text.y / text.fontSize, text.color); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java index ccb6ecc75..bffed31cb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/OverlayGlassesFunctions.java @@ -9,6 +9,7 @@ import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BlockObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.BoxObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.SphereObject; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim.TorusObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.CircleObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.ItemObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RectangleObject; @@ -82,6 +83,14 @@ public final MethodResult createSphere(IArguments arguments) throws LuaException return MethodResult.of(object, "SUCCESS"); } + @LuaFunction + public final MethodResult createTorus(IArguments arguments) throws LuaException { + TorusObject block = new TorusObject(overlayModule, arguments); + RenderableObject object = overlayModule.addObject(block); + + return MethodResult.of(object, "SUCCESS"); + } + @LuaFunction public final MethodResult getObject(IArguments arguments) throws LuaException { int id = arguments.getInt(0); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BlockObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BlockObject.java index ba09b0cb5..b2718e4fb 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BlockObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BlockObject.java @@ -40,7 +40,6 @@ public final String getBlock() { return block; } - @Override public void encode(FriendlyByteBuf buffer) { buffer.writeInt(TYPE_ID); @@ -59,15 +58,17 @@ public static BlockObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); - + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); boolean disableDepthTest = buffer.readBoolean(); boolean disableCulling = buffer.readBoolean(); + float xRot = buffer.readFloat(); + float yRot = buffer.readFloat(); + float zRot = buffer.readFloat(); String block = buffer.readUtf(); @@ -83,6 +84,9 @@ public static BlockObject decode(FriendlyByteBuf buffer) { clientObject.maxZ = maxZ; clientObject.disableDepthTest = disableDepthTest; clientObject.disableCulling = disableCulling; + clientObject.xRot = xRot; + clientObject.yRot = yRot; + clientObject.zRot = zRot; clientObject.block = block; return clientObject; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BoxObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BoxObject.java index 796531ee1..0aeb1f3c5 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BoxObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/BoxObject.java @@ -41,15 +41,17 @@ public static BoxObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); - + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); boolean disableDepthTest = buffer.readBoolean(); boolean disableCulling = buffer.readBoolean(); + float xRot = buffer.readFloat(); + float yRot = buffer.readFloat(); + float zRot = buffer.readFloat(); BoxObject clientObject = new BoxObject(player); clientObject.setId(objectId); @@ -63,6 +65,9 @@ public static BoxObject decode(FriendlyByteBuf buffer) { clientObject.maxZ = maxZ; clientObject.disableDepthTest = disableDepthTest; clientObject.disableCulling = disableCulling; + clientObject.xRot = xRot; + clientObject.yRot = yRot; + clientObject.zRot = zRot; return clientObject; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/SphereObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/SphereObject.java index daa9f6bfe..781c600e7 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/SphereObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/SphereObject.java @@ -2,11 +2,13 @@ import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; import de.srendi.advancedperipherals.AdvancedPeripherals; import de.srendi.advancedperipherals.client.smartglasses.objects.IObjectRenderer; import de.srendi.advancedperipherals.client.smartglasses.objects.threedim.SphereRenderer; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FixedPointNumberProperty; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FloatingNumberProperty; import net.minecraft.network.FriendlyByteBuf; import java.util.UUID; @@ -22,6 +24,9 @@ public class SphereObject extends ThreeDimensionalObject { @FixedPointNumberProperty(min = 1, max = 1024) public int stacks = 16; + @FloatingNumberProperty(min = 0.001f, max = 128) + public float radius = 1; + public SphereObject(OverlayModule module, IArguments arguments) throws LuaException { super(module, arguments); reflectivelyMapProperties(arguments); @@ -31,12 +36,46 @@ public SphereObject(UUID player) { super(player); } + @LuaFunction + public final void setRadius(float radius) { + this.radius = radius; + getModule().update(this); + } + + @LuaFunction + public final float getRadius() { + return radius; + } + + @LuaFunction + public final void setSectors(int sectors) { + this.sectors = sectors; + getModule().update(this); + } + + @LuaFunction + public final int getSectors() { + return sectors; + } + + @LuaFunction + public final void setStacks(int stacks) { + this.stacks = stacks; + getModule().update(this); + } + + @LuaFunction + public final int getStacks() { + return stacks; + } + @Override public void encode(FriendlyByteBuf buffer) { buffer.writeInt(TYPE_ID); super.encode(buffer); buffer.writeInt(sectors); buffer.writeInt(stacks); + buffer.writeFloat(radius); } public static SphereObject decode(FriendlyByteBuf buffer) { @@ -50,18 +89,21 @@ public static SphereObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); - + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); boolean disableDepthTest = buffer.readBoolean(); boolean disableCulling = buffer.readBoolean(); + float xRot = buffer.readFloat(); + float yRot = buffer.readFloat(); + float zRot = buffer.readFloat(); int sectors = buffer.readInt(); int stacks = buffer.readInt(); + float radius = buffer.readFloat(); SphereObject clientObject = new SphereObject(player); clientObject.setId(objectId); @@ -75,8 +117,12 @@ public static SphereObject decode(FriendlyByteBuf buffer) { clientObject.maxZ = maxZ; clientObject.disableDepthTest = disableDepthTest; clientObject.disableCulling = disableCulling; + clientObject.xRot = xRot; + clientObject.yRot = yRot; + clientObject.zRot = zRot; clientObject.sectors = sectors; clientObject.stacks = stacks; + clientObject.radius = radius; return clientObject; } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/ThreeDimensionalObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/ThreeDimensionalObject.java index efdd161ce..2c219edbf 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/ThreeDimensionalObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/ThreeDimensionalObject.java @@ -6,6 +6,7 @@ import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.two_dim.RenderableObject; import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.BooleanProperty; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FloatingNumberProperty; import net.minecraft.network.FriendlyByteBuf; import java.util.UUID; @@ -18,6 +19,15 @@ public abstract class ThreeDimensionalObject extends RenderableObject { @BooleanProperty public boolean disableCulling = false; + @FloatingNumberProperty(min = 0, max = 360) + public float xRot = 0f; + + @FloatingNumberProperty(min = 0, max = 360) + public float yRot = 0f; + + @FloatingNumberProperty(min = 0, max = 360) + public float zRot = 0f; + public ThreeDimensionalObject(OverlayModule module, IArguments arguments) throws LuaException { super(module, arguments); } @@ -48,12 +58,48 @@ public final boolean getCulling() { return disableCulling; } + @LuaFunction + public final void setXRot(double xRot) { + this.xRot = (float) xRot; + getModule().update(this); + } + + @LuaFunction + public final double getXRot() { + return xRot; + } + + @LuaFunction + public final void setYRot(double yRot) { + this.yRot = (float) yRot; + getModule().update(this); + } + + @LuaFunction + public final double getYRot() { + return yRot; + } + + @LuaFunction + public final void setZRot(double zRot) { + this.zRot = (float) zRot; + getModule().update(this); + } + + @LuaFunction + public final double getZRot() { + return zRot; + } + @Override public void encode(FriendlyByteBuf buffer) { super.encode(buffer); buffer.writeBoolean(disableDepthTest); buffer.writeBoolean(disableCulling); + buffer.writeFloat(xRot); + buffer.writeFloat(yRot); + buffer.writeFloat(zRot); } } diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/TorusObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/TorusObject.java new file mode 100644 index 000000000..d47c300ee --- /dev/null +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/three_dim/TorusObject.java @@ -0,0 +1,152 @@ +package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.three_dim; + +import dan200.computercraft.api.lua.IArguments; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.lua.LuaFunction; +import de.srendi.advancedperipherals.AdvancedPeripherals; +import de.srendi.advancedperipherals.client.smartglasses.objects.IObjectRenderer; +import de.srendi.advancedperipherals.client.smartglasses.objects.threedim.TorusRenderer; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FixedPointNumberProperty; +import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.FloatingNumberProperty; +import net.minecraft.network.FriendlyByteBuf; + +import java.util.UUID; + +public class TorusObject extends ThreeDimensionalObject { + public static final int TYPE_ID = 7; + + private final IObjectRenderer renderer = new TorusRenderer(); + + @FixedPointNumberProperty(min = 1, max = 1024) + public int sides = 32; + + @FixedPointNumberProperty(min = 1, max = 1024) + public int rings = 16; + + @FloatingNumberProperty(min = 0.001f, max = 128) + public float minorRadius = 0.1f; + + @FloatingNumberProperty(min = 0.001f, max = 128) + public float majorRadius = 0.5f; + + public TorusObject(OverlayModule module, IArguments arguments) throws LuaException { + super(module, arguments); + reflectivelyMapProperties(arguments); + } + + public TorusObject(UUID player) { + super(player); + } + + @LuaFunction + public final void setMinorRadius(float radius) { + this.minorRadius = radius; + getModule().update(this); + } + + @LuaFunction + public final float getMinorRadius() { + return minorRadius; + } + + @LuaFunction + public final void setMajorRadius(float radius) { + this.majorRadius = radius; + getModule().update(this); + } + + @LuaFunction + public final float getMajorRadius() { + return majorRadius; + } + + @LuaFunction + public final void setSides(int sides) { + this.sides = sides; + getModule().update(this); + } + + @LuaFunction + public final int getSides() { + return sides; + } + + @LuaFunction + public final void setRings(int rings) { + this.rings = rings; + getModule().update(this); + } + + @LuaFunction + public final int getRings() { + return rings; + } + + @Override + public void encode(FriendlyByteBuf buffer) { + buffer.writeInt(TYPE_ID); + super.encode(buffer); + buffer.writeInt(sides); + buffer.writeInt(rings); + buffer.writeFloat(minorRadius); + buffer.writeFloat(majorRadius); + } + + public static TorusObject decode(FriendlyByteBuf buffer) { + int objectId = buffer.readInt(); + boolean hasValidUUID = buffer.readBoolean(); + if (!hasValidUUID) { + AdvancedPeripherals.exception("Tried to decode a buffer for an OverlayObject but without a valid player as target.", new IllegalArgumentException()); + return null; + } + UUID player = buffer.readUUID(); + int color = buffer.readInt(); + float opacity = buffer.readFloat(); + + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); + + boolean disableDepthTest = buffer.readBoolean(); + boolean disableCulling = buffer.readBoolean(); + float xRot = buffer.readFloat(); + float yRot = buffer.readFloat(); + float zRot = buffer.readFloat(); + + int sectors = buffer.readInt(); + int stacks = buffer.readInt(); + float minorRadius = buffer.readFloat(); + float majorRadius = buffer.readFloat(); + + TorusObject clientObject = new TorusObject(player); + clientObject.setId(objectId); + clientObject.color = color; + clientObject.opacity = opacity; + clientObject.x = x; + clientObject.y = y; + clientObject.z = z; + clientObject.maxX = maxX; + clientObject.maxY = maxY; + clientObject.maxZ = maxZ; + clientObject.disableDepthTest = disableDepthTest; + clientObject.disableCulling = disableCulling; + clientObject.xRot = xRot; + clientObject.yRot = yRot; + clientObject.zRot = zRot; + clientObject.sides = sectors; + clientObject.rings = stacks; + clientObject.minorRadius = minorRadius; + clientObject.majorRadius = majorRadius; + + return clientObject; + } + + @Override + public IObjectRenderer getRenderObject() { + return renderer; + } +} diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/CircleObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/CircleObject.java index 99600bd0c..8796fd0e6 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/CircleObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/CircleObject.java @@ -58,12 +58,12 @@ public static CircleObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); int radius = buffer.readInt(); CircleObject clientObject = new CircleObject(player); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/ItemObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/ItemObject.java index 85a576e0b..c463fe885 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/ItemObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/ItemObject.java @@ -54,12 +54,12 @@ public static ItemObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); String item = buffer.readUtf(); ItemObject clientObject = new ItemObject(player); diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RectangleObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RectangleObject.java index 6e13ae990..3f618b638 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RectangleObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RectangleObject.java @@ -48,13 +48,12 @@ public static RectangleObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); - + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); RectangleObject clientObject = new RectangleObject(player); clientObject.setId(objectId); clientObject.color = color; diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RenderableObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RenderableObject.java index ca2f6edbe..525dbcd4a 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RenderableObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/RenderableObject.java @@ -21,23 +21,23 @@ public class RenderableObject extends OverlayObject { @FixedPointNumberProperty(min = 0, max = 0xFFFFFF) public int color = 0xFFFFFF; - @FixedPointNumberProperty(min = -32767, max = 32767) - public int x = 0; + @FloatingNumberProperty(min = -32767, max = 32767) + public float x = 0; - @FixedPointNumberProperty(min = -32767, max = 32767) - public int y = 0; + @FloatingNumberProperty(min = -32767, max = 32767) + public float y = 0; - @FixedPointNumberProperty(min = -32767, max = 32767) - public int z = 0; + @FloatingNumberProperty(min = -32767, max = 32767) + public float z = 0; - @FixedPointNumberProperty(min = -32767, max = 32767) - public int maxX = 0; + @FloatingNumberProperty(min = -32767, max = 32767) + public float maxX = 0; - @FixedPointNumberProperty(min = -32767, max = 32767) - public int maxY = 0; + @FloatingNumberProperty(min = -32767, max = 32767) + public float maxY = 0; - @FixedPointNumberProperty(min = -32767, max = 32767) - public int maxZ = 0; + @FloatingNumberProperty(min = -32767, max = 32767) + public float maxZ = 0; public RenderableObject(OverlayModule module, IArguments arguments) throws LuaException { super(module, arguments); @@ -71,46 +71,46 @@ public final void setColor(int color) { } @LuaFunction - public final void setMaxX(int maxX) { + public final void setMaxX(float maxX) { this.maxX = maxX; getModule().update(this); } @LuaFunction - public final int getMaxX() { + public final float getMaxX() { return maxX; } @LuaFunction - public final void setMaxY(int maxY) { + public final void setMaxY(float maxY) { this.maxY = maxY; getModule().update(this); } @LuaFunction - public final int getMaxY() { + public final float getMaxY() { return maxY; } @LuaFunction - public final void setMaxZ(int maxZ) { + public final void setMaxZ(float maxZ) { this.maxZ = maxZ; getModule().update(this); } @LuaFunction - public final int getMaxZ() { + public final float getMaxZ() { return maxZ; } @LuaFunction - public final void setX(int x) { + public final void setX(float x) { this.x = x; getModule().update(this); } @LuaFunction - public final int getX() { + public final float getX() { return x; } @@ -121,18 +121,18 @@ public final void setY(int y) { } @LuaFunction - public final int getY() { + public final float getY() { return y; } @LuaFunction - public final void setZ(int z) { + public final void setZ(float z) { this.z = z; getModule().update(this); } @LuaFunction - public final int getZ() { + public final float getZ() { return z; } @@ -142,12 +142,12 @@ public void encode(FriendlyByteBuf buffer) { buffer.writeInt(color); buffer.writeFloat(opacity); - buffer.writeInt(x); - buffer.writeInt(y); - buffer.writeInt(z); - buffer.writeInt(maxX); - buffer.writeInt(maxY); - buffer.writeInt(maxZ); + buffer.writeFloat(x); + buffer.writeFloat(y); + buffer.writeFloat(z); + buffer.writeFloat(maxX); + buffer.writeFloat(maxY); + buffer.writeFloat(maxZ); } public IObjectRenderer getRenderObject() { diff --git a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/TextObject.java b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/TextObject.java index 7e50e1735..bf628ac41 100644 --- a/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/TextObject.java +++ b/src/main/java/de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/two_dim/TextObject.java @@ -95,12 +95,12 @@ public static TextObject decode(FriendlyByteBuf buffer) { int color = buffer.readInt(); float opacity = buffer.readFloat(); - int x = buffer.readInt(); - int y = buffer.readInt(); - int z = buffer.readInt(); - int maxX = buffer.readInt(); - int maxY = buffer.readInt(); - int maxZ = buffer.readInt(); + float x = buffer.readFloat(); + float y = buffer.readFloat(); + float z = buffer.readFloat(); + float maxX = buffer.readFloat(); + float maxY = buffer.readFloat(); + float maxZ = buffer.readFloat(); String content = buffer.readUtf(); float fontSize = buffer.readFloat(); boolean shadow = buffer.readBoolean();