Oops engine stuff is okay again.

This commit is contained in:
JozsefA 2021-03-10 16:09:17 -08:00
parent d0a6f4123b
commit b7f0fe9b10
5 changed files with 16 additions and 8 deletions

View file

@ -53,6 +53,8 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
protected float lastAngle = Float.NaN; protected float lastAngle = Float.NaN;
protected boolean firstFrame = true;
public FlyWheelInstance(InstancedTileRenderer<?> modelManager, FlywheelTileEntity tile) { public FlyWheelInstance(InstancedTileRenderer<?> modelManager, FlywheelTileEntity tile) {
super(modelManager, tile); super(modelManager, tile);
} }
@ -87,6 +89,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
} }
updateLight(); updateLight();
firstFrame = true;
} }
@Override @Override
@ -97,7 +100,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
float speed = tile.visualSpeed.get(partialTicks) * 3 / 10f; float speed = tile.visualSpeed.get(partialTicks) * 3 / 10f;
float angle = tile.angle + speed * partialTicks; 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(); MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms); MatrixStacker msr = MatrixStacker.of(ms);
@ -140,6 +143,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
wheel.getInstance().setTransformNoCopy(ms); wheel.getInstance().setTransformNoCopy(ms);
lastAngle = angle; lastAngle = angle;
firstFrame = false;
} }
@Override @Override

View file

@ -25,7 +25,6 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
InstancedTileRenderRegistry.instance.register(type, EngineInstance::new)); InstancedTileRenderRegistry.instance.register(type, EngineInstance::new));
} }
protected BlockPos baseBlockPos;
protected InstanceKey<ModelData> frame; protected InstanceKey<ModelData> frame;
public EngineInstance(InstancedTileRenderer<?> modelManager, EngineTileEntity tile) { public EngineInstance(InstancedTileRenderer<?> modelManager, EngineTileEntity tile) {
@ -44,8 +43,6 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
Direction facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING); Direction facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING);
baseBlockPos = EngineBlock.getBaseBlockPos(lastState, pos);
this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, lastState).createInstance(); this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, lastState).createInstance();
float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing)); float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing));
@ -54,6 +51,7 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
MatrixStacker msr = MatrixStacker.of(ms); MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos()) msr.translate(getFloatingPos())
.nudge(tile.hashCode())
.centre() .centre()
.rotate(Direction.UP, angle) .rotate(Direction.UP, angle)
.unCentre() .unCentre()
@ -72,8 +70,8 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
@Override @Override
public void updateLight() { public void updateLight() {
int block = world.getLightLevel(LightType.BLOCK, baseBlockPos); int block = world.getLightLevel(LightType.BLOCK, pos);
int sky = world.getLightLevel(LightType.SKY, baseBlockPos); int sky = world.getLightLevel(LightType.SKY, pos);
frame.getInstance().setBlockLight(block).setSkyLight(sky); frame.getInstance().setBlockLight(block).setSkyLight(sky);
} }

View file

@ -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.GlFogMode;
import com.simibubi.create.foundation.render.backend.gl.shader.*; 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.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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL;
@ -65,6 +67,10 @@ public class Backend {
return (P) programs.get(spec).get(GlFog.getFogMode()); 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() { public static boolean available() {
return canUseVBOs(); return canUseVBOs();
} }

View file

@ -57,7 +57,7 @@ public class FastRenderDispatcher {
} }
public static boolean available(World world) { public static boolean available(World world) {
return Backend.canUseInstancing() && !(world instanceof SchematicWorld); return Backend.canUseInstancing() && Backend.isFlywheelWorld(world);
} }
public static int getDebugMode() { public static int getDebugMode() {

View file

@ -84,7 +84,7 @@ public class MatrixStacker {
} }
public MatrixStacker nudge(int id) { public MatrixStacker nudge(int id) {
long randomBits = (long) id * 493286711L; long randomBits = (long) id * 31L * 493286711L;
randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L; randomBits = randomBits * randomBits * 4392167121L + randomBits * 98761L;
float xNudge = (((float) (randomBits >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F; 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; float yNudge = (((float) (randomBits >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;