diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java index bc98f8f84..c8b4c582e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltRenderer.java @@ -110,7 +110,7 @@ public class BeltRenderer extends SafeTileEntityRenderer { float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV(); - double scroll = speed * time / (36 * 16) + (bottom ? 0.5 : 0.0); + double scroll = speed * time / (31.5 * 16) + (bottom ? 0.5 : 0.0); scroll = scroll - Math.floor(scroll); scroll = scroll * spriteSize * scrollMult; diff --git a/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java index 03cc04bdf..01f60ce81 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/wrench/WrenchItemRenderer.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.wrench; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.block.render.CustomRenderedItemModelRenderer; import com.simibubi.create.foundation.item.PartialItemModelRenderer; +import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueHandler; import com.simibubi.create.foundation.utility.AnimationTickHolder; import net.minecraft.client.renderer.IRenderTypeBuffer; @@ -16,11 +17,9 @@ public class WrenchItemRenderer extends CustomRenderedItemModelRenderer forces = new ArrayList<>(); + + public static PhysicalFloat create() { + return new PhysicalFloat(); + } + + public PhysicalFloat startAt(double value) { + previousValue = this.value = (float) value; + return this; + } + + public PhysicalFloat withDrag(double drag) { + return addForce(new DragForce((float) drag)); + } + + public PhysicalFloat zeroing(double g) { + return addForce(new ZeroingForce((float) g)); + } + + public void tick() { + previousValue = value; + + for (Force force : forces) + speed = force.apply(speed, value); + + forces.removeIf(Force::finished); + + value += speed; + } + + public PhysicalFloat addForce(Force f) { + forces.add(f); + return this; + } + + public PhysicalFloat bump(double force) { + return addForce(new Impulse((float) force)); + } + + public PhysicalFloat bump(int time, double force) { + return addForce(new ForceOverTime(time, (float) force)); + } + + public float getValue() { + return getValue(1); + } + + public float getValue(float partialTicks) { + return MathHelper.lerp(partialTicks, previousValue, value); + } + + public interface Force { + + float apply(float speed, float value); + + boolean finished(); + } + + public static class DragForce implements Force { + final float dragFactor; + + public DragForce(float dragFactor) { + this.dragFactor = dragFactor; + } + + @Override + public float apply(float speed, float value) { + return speed * dragFactor; + } + + @Override + public boolean finished() { + return false; + } + } + + public static class ZeroingForce implements Force { + final float g; + + public ZeroingForce(float g) { + this.g = g; + } + + @Override + public float apply(float speed, float value) { + return speed - MathHelper.clamp(g * Math.signum(value), -speed, speed); + } + + @Override + public boolean finished() { + return false; + } + } + + public static class Impulse implements Force { + + float force; + + public Impulse(float force) { + this.force = force; + } + + @Override + public float apply(float speed, float value) { + return speed + force; + } + + @Override + public boolean finished() { + return true; + } + } + + public static class ForceOverTime implements Force { + int timeRemaining; + float accel; + + public ForceOverTime(int time, float totalAcceleration) { + this.timeRemaining = time; + this.accel = totalAcceleration / (float) time; + } + + @Override + public float apply(float speed, float value) { + timeRemaining--; + return speed + accel; + } + + @Override + public boolean finished() { + return timeRemaining <= 0; + } + } +} diff --git a/src/main/resources/assets/create/shader/belt.vert b/src/main/resources/assets/create/shader/belt.vert index 14921cb7a..81f9054d5 100644 --- a/src/main/resources/assets/create/shader/belt.vert +++ b/src/main/resources/assets/create/shader/belt.vert @@ -88,7 +88,7 @@ void main() { vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz; float scrollSize = aScrollTexture.w - aScrollTexture.y; - float scroll = fract(aSpeed * uTime / (36. * 16.) + aOffset) * scrollSize * aScrollMult; + float scroll = fract(aSpeed * uTime / (31.5 * 16.) + aOffset) * scrollSize * aScrollMult; Diffuse = diffuse(norm); TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll);