From b7f0fe9b10701339313b0a4f397e2d843a342225 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 10 Mar 2021 16:09:17 -0800 Subject: [PATCH] Oops engine stuff is okay again. --- .../components/flywheel/FlyWheelInstance.java | 6 +++++- .../components/flywheel/engine/EngineInstance.java | 8 +++----- .../create/foundation/render/backend/Backend.java | 6 ++++++ .../foundation/render/backend/FastRenderDispatcher.java | 2 +- .../simibubi/create/foundation/utility/MatrixStacker.java | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) 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 2bc3cb728..267e05572 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 @@ -53,6 +53,8 @@ public class FlyWheelInstance extends KineticTileInstance im protected float lastAngle = Float.NaN; + protected boolean firstFrame = true; + public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { super(modelManager, tile); } @@ -87,6 +89,7 @@ public class FlyWheelInstance extends KineticTileInstance im } updateLight(); + firstFrame = true; } @Override @@ -97,7 +100,7 @@ public class FlyWheelInstance extends KineticTileInstance im float speed = tile.visualSpeed.get(partialTicks) * 3 / 10f; float angle = tile.angle + speed * partialTicks; - if (Math.abs(angle - lastAngle) < 0.001) return; + if (!firstFrame && Math.abs(angle - lastAngle) < 0.001) return; MatrixStack ms = new MatrixStack(); MatrixStacker msr = MatrixStacker.of(ms); @@ -140,6 +143,7 @@ public class FlyWheelInstance extends KineticTileInstance im wheel.getInstance().setTransformNoCopy(ms); lastAngle = angle; + firstFrame = false; } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java index 2324e3a7d..dcffdd401 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java @@ -25,7 +25,6 @@ public class EngineInstance extends TileEntityInstance { InstancedTileRenderRegistry.instance.register(type, EngineInstance::new)); } - protected BlockPos baseBlockPos; protected InstanceKey frame; public EngineInstance(InstancedTileRenderer modelManager, EngineTileEntity tile) { @@ -44,8 +43,6 @@ public class EngineInstance extends TileEntityInstance { Direction facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); - baseBlockPos = EngineBlock.getBaseBlockPos(lastState, pos); - this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, lastState).createInstance(); float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing)); @@ -54,6 +51,7 @@ public class EngineInstance extends TileEntityInstance { MatrixStacker msr = MatrixStacker.of(ms); msr.translate(getFloatingPos()) + .nudge(tile.hashCode()) .centre() .rotate(Direction.UP, angle) .unCentre() @@ -72,8 +70,8 @@ public class EngineInstance extends TileEntityInstance { @Override public void updateLight() { - int block = world.getLightLevel(LightType.BLOCK, baseBlockPos); - int sky = world.getLightLevel(LightType.SKY, baseBlockPos); + int block = world.getLightLevel(LightType.BLOCK, pos); + int sky = world.getLightLevel(LightType.SKY, pos); frame.getInstance().setBlockLight(block).setSkyLight(sky); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java index 159122f24..b2a50382f 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java @@ -13,6 +13,8 @@ import com.simibubi.create.foundation.render.backend.gl.GlFog; import com.simibubi.create.foundation.render.backend.gl.GlFogMode; import com.simibubi.create.foundation.render.backend.gl.shader.*; import com.simibubi.create.foundation.render.backend.gl.versioned.GlFeatureCompat; +import com.simibubi.create.foundation.render.backend.instancing.IFlywheelWorld; +import net.minecraft.world.World; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.GL; @@ -65,6 +67,10 @@ public class Backend { return (P) programs.get(spec).get(GlFog.getFogMode()); } + public static boolean isFlywheelWorld(World world) { + return world == Minecraft.getInstance().world || (world instanceof IFlywheelWorld && ((IFlywheelWorld) world).supportsFlywheel()); + } + public static boolean available() { return canUseVBOs(); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java index 7038c4a78..6f096d888 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/FastRenderDispatcher.java @@ -57,7 +57,7 @@ public class FastRenderDispatcher { } public static boolean available(World world) { - return Backend.canUseInstancing() && !(world instanceof SchematicWorld); + return Backend.canUseInstancing() && Backend.isFlywheelWorld(world); } public static int getDebugMode() { diff --git a/src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java b/src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java index 9b41a4ed2..0323a1ebb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java +++ b/src/main/java/com/simibubi/create/foundation/utility/MatrixStacker.java @@ -84,7 +84,7 @@ public class MatrixStacker { } public MatrixStacker nudge(int id) { - long randomBits = (long) id * 493286711L; + long randomBits = (long) id * 31L * 493286711L; randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L; float xNudge = (((float) (randomBits >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F; float yNudge = (((float) (randomBits >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;