diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java index 81f8b85c4..3fffa70c8 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java @@ -5,18 +5,17 @@ import com.mojang.blaze3d.vertex.VertexFormat.Mode; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.CoreShaders; -import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.item.ItemStackRenderState; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.TextureAtlas; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; -import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.item.ItemDisplayContext; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec3; import org.joml.Matrix3f; import org.joml.Matrix4fStack; @@ -34,6 +33,8 @@ public class VRWidgetHelper { private static final RandomSource random = RandomSource.create(); + private static final ItemStackRenderState ITEM_STATE = new ItemStackRenderState(); + public static boolean debug = false; public static void renderVRThirdPersonCamWidget() { @@ -94,8 +95,7 @@ public static void renderVRHandheldCameraWidget() { } public static void renderVRCameraWidget(float offsetX, float offsetY, float offsetZ, float scale, RenderPass renderPass, ResourceLocation model, ResourceLocation displayModel, Runnable displayBindFunc, Function displayFaceFunc) { - // TODO 1.21.4 make models work - /*Minecraft minecraft = Minecraft.getInstance(); + Minecraft minecraft = Minecraft.getInstance(); ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); Matrix4fStack poseStack = RenderSystem.getModelViewStack(); poseStack.pushMatrix(); @@ -130,73 +130,85 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs } minecraft.gameRenderer.lightTexture().turnOnLightLayer(); - BufferBuilder bufferbuilder = Tesselator.getInstance().begin(Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); + BufferBuilder bufferbuilder; PoseStack poseStack2 = new PoseStack(); RenderHelper.applyVRModelView(dataholder.currentPass, poseStack2); poseStack2.last().pose().identity(); poseStack2.last().normal().mul(new Matrix3f(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getMatrix().toMCMatrix())); - minecraft.getBlockRenderer().getModelRenderer().renderModel(poseStack2.last(), bufferbuilder, null, minecraft.getModelManager().getModel(model), 1.0F, 1.0F, 1.0F, i, OverlayTexture.NO_OVERLAY); - BufferUploader.drawWithShader(bufferbuilder.buildOrThrow()); + ITEM_STATE.clear(); + minecraft.getModelManager().getItemModel(model).update(ITEM_STATE, ItemStack.EMPTY, minecraft.getItemModelResolver(), ItemDisplayContext.GROUND, null, null, 0); + + if (!ITEM_STATE.isEmpty() && ITEM_STATE.layers[0].model != null) { + bufferbuilder = Tesselator.getInstance().begin(Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); + minecraft.getBlockRenderer().getModelRenderer().renderModel(poseStack2.last(), bufferbuilder, null, ITEM_STATE.layers[0].model, 1.0F, 1.0F, 1.0F, i, OverlayTexture.NO_OVERLAY); + + BufferUploader.drawWithShader(bufferbuilder.buildOrThrow()); + } RenderSystem.disableBlend(); displayBindFunc.run(); RenderSystem.setShader(CoreShaders.RENDERTYPE_ENTITY_SOLID); - bufferbuilder = Tesselator.getInstance().begin(Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); - - for (BakedQuad bakedquad : minecraft.getModelManager().getModel(displayModel).getQuads(null, null, random)) { - if (displayFaceFunc.apply(bakedquad.getDirection()) != DisplayFace.NONE && bakedquad.getSprite().contents().name().equals(ResourceLocation.parse("vivecraft:transparent"))) { - int[] vertexList = bakedquad.getVertices(); - boolean flag = displayFaceFunc.apply(bakedquad.getDirection()) == DisplayFace.MIRROR; - // make normals point up, so they are always bright - // TODO: might break with shaders? - Vector3f normal = new Matrix3f(poseStack).transform(new Vector3f(0.0F, 1.0F, 0.0F)); - int j = LightTexture.pack(15, 15); - int step = vertexList.length / 4; - bufferbuilder.addVertex( - Float.intBitsToFloat(vertexList[0]), - Float.intBitsToFloat(vertexList[1]), - Float.intBitsToFloat(vertexList[2])) - .setColor(1.0F, 1.0F, 1.0F, 1.0F) - .setUv(flag ? 1.0F : 0.0F, 1.0F) - .setOverlay(OverlayTexture.NO_OVERLAY) - .setLight(j) - .setNormal(normal.x, normal.y, normal.z); - bufferbuilder.addVertex( - Float.intBitsToFloat(vertexList[step]), - Float.intBitsToFloat(vertexList[step + 1]), - Float.intBitsToFloat(vertexList[step + 2])) - .setColor(1.0F, 1.0F, 1.0F, 1.0F) - .setUv(flag ? 1.0F : 0.0F, 0.0F) - .setOverlay(OverlayTexture.NO_OVERLAY) - .setLight(j) - .setNormal(normal.x, normal.y, normal.z); - bufferbuilder.addVertex( - Float.intBitsToFloat(vertexList[step * 2]), - Float.intBitsToFloat(vertexList[step * 2 + 1]), - Float.intBitsToFloat(vertexList[step * 2 + 2])) - .setColor(1.0F, 1.0F, 1.0F, 1.0F) - .setUv(flag ? 0.0F : 1.0F, 0.0F) - .setOverlay(OverlayTexture.NO_OVERLAY) - .setLight(j) - .setNormal(normal.x, normal.y, normal.z); - bufferbuilder.addVertex( - Float.intBitsToFloat(vertexList[step * 3]), - Float.intBitsToFloat(vertexList[step * 3 + 1]), - Float.intBitsToFloat(vertexList[step * 3 + 2])) - .setColor(1.0F, 1.0F, 1.0F, 1.0F) - .setUv(flag ? 0.0F : 1.0F, 1.0F) - .setOverlay(OverlayTexture.NO_OVERLAY) - .setLight(j) - .setNormal(normal.x, normal.y, normal.z); + ITEM_STATE.clear(); + minecraft.getModelManager().getItemModel(displayModel).update(ITEM_STATE, ItemStack.EMPTY, minecraft.getItemModelResolver(), ItemDisplayContext.GROUND, null, null, 0); + + if (!ITEM_STATE.isEmpty() && ITEM_STATE.layers[0].model != null) { + bufferbuilder = Tesselator.getInstance().begin(Mode.QUADS, DefaultVertexFormat.NEW_ENTITY); + + for (BakedQuad bakedquad : ITEM_STATE.layers[0].model.getQuads(null, null, random)) { + if (displayFaceFunc.apply(bakedquad.getDirection()) != DisplayFace.NONE && bakedquad.getSprite().contents().name().equals(ResourceLocation.parse("vivecraft:transparent"))) { + int[] vertexList = bakedquad.getVertices(); + boolean flag = displayFaceFunc.apply(bakedquad.getDirection()) == DisplayFace.MIRROR; + // make normals point up, so they are always bright + // TODO: might break with shaders? + Vector3f normal = new Matrix3f(poseStack).transform(new Vector3f(0.0F, 1.0F, 0.0F)); + int j = LightTexture.pack(15, 15); + int step = vertexList.length / 4; + bufferbuilder.addVertex( + Float.intBitsToFloat(vertexList[0]), + Float.intBitsToFloat(vertexList[1]), + Float.intBitsToFloat(vertexList[2])) + .setColor(1.0F, 1.0F, 1.0F, 1.0F) + .setUv(flag ? 1.0F : 0.0F, 1.0F) + .setOverlay(OverlayTexture.NO_OVERLAY) + .setLight(j) + .setNormal(normal.x, normal.y, normal.z); + bufferbuilder.addVertex( + Float.intBitsToFloat(vertexList[step]), + Float.intBitsToFloat(vertexList[step + 1]), + Float.intBitsToFloat(vertexList[step + 2])) + .setColor(1.0F, 1.0F, 1.0F, 1.0F) + .setUv(flag ? 1.0F : 0.0F, 0.0F) + .setOverlay(OverlayTexture.NO_OVERLAY) + .setLight(j) + .setNormal(normal.x, normal.y, normal.z); + bufferbuilder.addVertex( + Float.intBitsToFloat(vertexList[step * 2]), + Float.intBitsToFloat(vertexList[step * 2 + 1]), + Float.intBitsToFloat(vertexList[step * 2 + 2])) + .setColor(1.0F, 1.0F, 1.0F, 1.0F) + .setUv(flag ? 0.0F : 1.0F, 0.0F) + .setOverlay(OverlayTexture.NO_OVERLAY) + .setLight(j) + .setNormal(normal.x, normal.y, normal.z); + bufferbuilder.addVertex( + Float.intBitsToFloat(vertexList[step * 3]), + Float.intBitsToFloat(vertexList[step * 3 + 1]), + Float.intBitsToFloat(vertexList[step * 3 + 2])) + .setColor(1.0F, 1.0F, 1.0F, 1.0F) + .setUv(flag ? 0.0F : 1.0F, 1.0F) + .setOverlay(OverlayTexture.NO_OVERLAY) + .setLight(j) + .setNormal(normal.x, normal.y, normal.z); + } } + BufferUploader.drawWithShader(bufferbuilder.buildOrThrow()); } - BufferUploader.drawWithShader(bufferbuilder.buildOrThrow()); minecraft.gameRenderer.lightTexture().turnOffLightLayer(); RenderSystem.enableBlend(); - poseStack.popMatrix();*/ + poseStack.popMatrix(); } public enum DisplayFace { diff --git a/common/src/main/resources/assets/vivecraft/items/camcorder.json b/common/src/main/resources/assets/vivecraft/items/camcorder.json new file mode 100644 index 000000000..5ff283e08 --- /dev/null +++ b/common/src/main/resources/assets/vivecraft/items/camcorder.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "vivecraft:item/camcorder" + } +} diff --git a/common/src/main/resources/assets/vivecraft/items/camcorder_display.json b/common/src/main/resources/assets/vivecraft/items/camcorder_display.json new file mode 100644 index 000000000..b2c6b1fcf --- /dev/null +++ b/common/src/main/resources/assets/vivecraft/items/camcorder_display.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "vivecraft:item/camcorder_display" + } +} diff --git a/common/src/main/resources/assets/vivecraft/items/camera.json b/common/src/main/resources/assets/vivecraft/items/camera.json new file mode 100644 index 000000000..f52d4c00b --- /dev/null +++ b/common/src/main/resources/assets/vivecraft/items/camera.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "vivecraft:item/camera" + } +} diff --git a/common/src/main/resources/assets/vivecraft/items/camera_display.json b/common/src/main/resources/assets/vivecraft/items/camera_display.json new file mode 100644 index 000000000..15023119f --- /dev/null +++ b/common/src/main/resources/assets/vivecraft/items/camera_display.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "vivecraft:item/camera_display" + } +} diff --git a/common/src/main/resources/vivecraft.accesswidener b/common/src/main/resources/vivecraft.accesswidener index 1b77ea4ee..0c18a385e 100644 --- a/common/src/main/resources/vivecraft.accesswidener +++ b/common/src/main/resources/vivecraft.accesswidener @@ -96,3 +96,7 @@ accessible method net/minecraft/world/item/BrushItem spawnDustParticles (Lnet/mi # do not kick climbing players accessible field net/minecraft/server/network/ServerGamePacketListenerImpl aboveGroundTickCount I + +# to render the camera widget with dispaly +accessible field net/minecraft/client/renderer/item/ItemStackRenderState layers [Lnet/minecraft/client/renderer/item/ItemStackRenderState$LayerRenderState; +accessible field net/minecraft/client/renderer/item/ItemStackRenderState$LayerRenderState model Lnet/minecraft/client/resources/model/BakedModel; diff --git a/gradle.properties b/gradle.properties index 669b7a0c6..add4182ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ minecraft_version=1.21.4 enabled_platforms=fabric,forge,neoforge archives_base_name=vivecraft -mod_version=1.1.14-a1 +mod_version=1.1.14-b1 maven_group=org.vivecraft architectury_version=15.0.1