From 90993ce8e1fd6a7082bf049c9f74a08dff6e39fc Mon Sep 17 00:00:00 2001 From: JozsefA Date: Fri, 5 Feb 2021 22:48:55 -0800 Subject: [PATCH] start working on schematic rendering --- .../com/simibubi/create/CreateClient.java | 2 ++ .../components/flywheel/FlyWheelInstance.java | 12 +++---- .../components/flywheel/FlywheelRenderer.java | 6 ++-- .../schematics/client/SchematicHandler.java | 2 +- .../schematics/client/SchematicRenderer.java | 4 +-- .../SchematicRendererWithInstancing.java | 36 +++++++++++++++++++ .../render/FastRenderDispatcher.java | 2 +- .../render/instancing/InstancedModel.java | 4 --- 8 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 143e5eec5..074e28b31 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -31,6 +31,8 @@ import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.ModLoader; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import java.util.ArrayList; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index c0b7405e8..d98cd513e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -24,7 +24,7 @@ public class FlyWheelInstance extends KineticTileInstance { protected Direction facing; protected InstanceKey shaft; - protected InstanceKey wheel; +// protected InstanceKey wheel; public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { super(modelManager, tile); @@ -37,28 +37,28 @@ public class FlyWheelInstance extends KineticTileInstance { Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); Consumer setup = setupFunc(tile.getSpeed(), axis); shaft = shaftModel().setupInstance(setup); - wheel = wheelModel().setupInstance(setup); +// wheel = wheelModel().setupInstance(setup); } @Override protected void onUpdate() { Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState); updateRotation(shaft, axis); - updateRotation(wheel, axis); +// updateRotation(wheel, axis); } @Override public void updateLight() { shaft.modifyInstance(this::relight); - wheel.modifyInstance(this::relight); +// wheel.modifyInstance(this::relight); } @Override public void remove() { shaft.delete(); - wheel.delete(); shaft = null; - wheel = null; +// wheel.delete(); +// wheel = null; } protected InstancedModel shaftModel() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java index 97a9828f0..9c4d6b6be 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelRenderer.java @@ -69,9 +69,9 @@ public class FlywheelRenderer extends KineticTileEntityRenderer { .renderInto(ms, vb); } -// kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) -// .getAxis(), AngleHelper.rad(angle), light); -// wheel.renderInto(ms, vb); + kineticRotationTransform(wheel, te, blockState.get(HORIZONTAL_FACING) + .getAxis(), AngleHelper.rad(angle), light); + wheel.renderInto(ms, vb); } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java index 87df3b517..87e69f75b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHandler.java @@ -56,7 +56,7 @@ public class SchematicHandler { public SchematicHandler() { renderers = new Vector<>(3); for (int i = 0; i < renderers.capacity(); i++) - renderers.add(new SchematicRenderer()); + renderers.add(new SchematicRendererWithInstancing()); overlay = new SchematicHotbarSlotOverlay(); currentTool = Tools.Deploy; diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java index 8796b451b..2f9159897 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRenderer.java @@ -34,7 +34,7 @@ public class SchematicRenderer { private final Set startedBufferBuilders = new HashSet<>(getLayerCount()); private boolean active; private boolean changed; - private SchematicWorld schematic; + protected SchematicWorld schematic; private BlockPos anchor; public SchematicRenderer() { @@ -81,7 +81,7 @@ public class SchematicRenderer { buffer); } - private void redraw(Minecraft minecraft) { + protected void redraw(Minecraft minecraft) { usedBlockRenderLayers.clear(); startedBufferBuilders.clear(); diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java new file mode 100644 index 000000000..504940a03 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicRendererWithInstancing.java @@ -0,0 +1,36 @@ +package com.simibubi.create.content.schematics.client; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.render.FastRenderDispatcher; +import com.simibubi.create.foundation.render.contraption.ContraptionKineticRenderer; +import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.loading.FMLClientLaunchProvider; + +public class SchematicRendererWithInstancing extends SchematicRenderer { + public final ContraptionKineticRenderer tiles; + + public SchematicRendererWithInstancing() { + this.tiles = new ContraptionKineticRenderer(); + } + + @Override + protected void redraw(Minecraft minecraft) { + super.redraw(minecraft); + + tiles.invalidate(); + + schematic.getRenderedTileEntities().forEach(tiles::add); + } + + @Override + public void render(MatrixStack ms, SuperRenderTypeBuffer buffer) { + super.render(ms, buffer); + + //tiles.render(RenderType.getCutoutMipped(), FastRenderDispatcher.getProjectionMatrix(), ); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java index 271b0accb..c704a15bd 100644 --- a/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/FastRenderDispatcher.java @@ -106,7 +106,7 @@ public class FastRenderDispatcher { } // copied from GameRenderer.renderWorld - private static Matrix4f getProjectionMatrix() { + public static Matrix4f getProjectionMatrix() { if (projectionMatrixThisFrame != null) return projectionMatrixThisFrame; float partialTicks = AnimationTickHolder.getPartialTicks(); diff --git a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java index 7253675dd..1163e0f4c 100644 --- a/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/instancing/InstancedModel.java @@ -68,10 +68,6 @@ public abstract class InstancedModel extends BufferedMod return instanceCount() == 0; } - public void clearInstanceData() { - - } - protected void deleteInternal() { super.deleteInternal(); instanceVBO.delete();