mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-11 04:54:12 +01:00
Belt speed = item speed and secret wrench fix.
This commit is contained in:
parent
f14661fb6f
commit
a1e10a5c3c
@ -110,7 +110,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||||||
|
|
||||||
float spriteSize = spriteShift.getTarget().getMaxV() - spriteShift.getTarget().getMinV();
|
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 - Math.floor(scroll);
|
||||||
scroll = scroll * spriteSize * scrollMult;
|
scroll = scroll * spriteSize * scrollMult;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.wrench;
|
|||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.simibubi.create.foundation.block.render.CustomRenderedItemModelRenderer;
|
import com.simibubi.create.foundation.block.render.CustomRenderedItemModelRenderer;
|
||||||
import com.simibubi.create.foundation.item.PartialItemModelRenderer;
|
import com.simibubi.create.foundation.item.PartialItemModelRenderer;
|
||||||
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueHandler;
|
||||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||||
@ -16,11 +17,9 @@ public class WrenchItemRenderer extends CustomRenderedItemModelRenderer<WrenchMo
|
|||||||
IRenderTypeBuffer buffer, int light, int overlay) {
|
IRenderTypeBuffer buffer, int light, int overlay) {
|
||||||
renderer.render(model.getBakedModel(), light);
|
renderer.render(model.getBakedModel(), light);
|
||||||
|
|
||||||
float worldTime = AnimationTickHolder.getRenderTime();
|
|
||||||
float angle = worldTime * -.5f % 360;
|
|
||||||
float xOffset = -1/16f;
|
float xOffset = -1/16f;
|
||||||
ms.translate(-xOffset, 0, 0);
|
ms.translate(-xOffset, 0, 0);
|
||||||
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle));
|
ms.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(ScrollValueHandler.getScroll(AnimationTickHolder.getPartialTicks())));
|
||||||
ms.translate(xOffset, 0, 0);
|
ms.translate(xOffset, 0, 0);
|
||||||
|
|
||||||
renderer.render(model.getPartial("gear"), light);
|
renderer.render(model.getPartial("gear"), light);
|
||||||
|
@ -33,6 +33,7 @@ import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
|
|||||||
import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer;
|
import com.simibubi.create.foundation.tileEntity.behaviour.edgeInteraction.EdgeInteractionRenderer;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer;
|
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringRenderer;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkRenderer;
|
import com.simibubi.create.foundation.tileEntity.behaviour.linked.LinkRenderer;
|
||||||
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueHandler;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueRenderer;
|
||||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||||
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
||||||
@ -84,6 +85,7 @@ public class ClientEvents {
|
|||||||
|
|
||||||
AnimationTickHolder.tick();
|
AnimationTickHolder.tick();
|
||||||
FastRenderDispatcher.tick();
|
FastRenderDispatcher.tick();
|
||||||
|
ScrollValueHandler.tick();
|
||||||
|
|
||||||
CreateClient.schematicSender.tick();
|
CreateClient.schematicSender.tick();
|
||||||
CreateClient.schematicAndQuillHandler.tick();
|
CreateClient.schematicAndQuillHandler.tick();
|
||||||
|
@ -7,6 +7,7 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
|||||||
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided;
|
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour.StepContext;
|
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour.StepContext;
|
||||||
|
|
||||||
|
import com.simibubi.create.foundation.utility.PhysicalFloat;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.world.ClientWorld;
|
import net.minecraft.client.world.ClientWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@ -20,6 +21,11 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|||||||
@EventBusSubscriber
|
@EventBusSubscriber
|
||||||
public class ScrollValueHandler {
|
public class ScrollValueHandler {
|
||||||
|
|
||||||
|
private static float lastPassiveScroll = 0.0f;
|
||||||
|
private static float passiveScroll = 0.0f;
|
||||||
|
private static float passiveScrollDirection = 1f;
|
||||||
|
private static final PhysicalFloat wrenchCog = PhysicalFloat.create().withDrag(0.7);
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static boolean onScroll(double delta) {
|
public static boolean onScroll(double delta) {
|
||||||
RayTraceResult objectMouseOver = Minecraft.getInstance().objectMouseOver;
|
RayTraceResult objectMouseOver = Minecraft.getInstance().objectMouseOver;
|
||||||
@ -36,6 +42,10 @@ public class ScrollValueHandler {
|
|||||||
return false;
|
return false;
|
||||||
if (!mc.player.isAllowEdit())
|
if (!mc.player.isAllowEdit())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
passiveScrollDirection = (float) delta;
|
||||||
|
wrenchCog.bump(3, delta * 10);
|
||||||
|
|
||||||
if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getHeldItemMainhand()))
|
if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getHeldItemMainhand()))
|
||||||
return false;
|
return false;
|
||||||
if (scrolling.slotPositioning instanceof Sided)
|
if (scrolling.slotPositioning instanceof Sided)
|
||||||
@ -57,6 +67,17 @@ public class ScrollValueHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float getScroll(float partialTicks) {
|
||||||
|
return wrenchCog.getValue(partialTicks) + MathHelper.lerp(partialTicks, lastPassiveScroll, passiveScroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public static void tick() {
|
||||||
|
lastPassiveScroll = passiveScroll;
|
||||||
|
wrenchCog.tick();
|
||||||
|
passiveScroll += passiveScrollDirection * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
protected static void applyTo(double delta, ScrollValueBehaviour scrolling) {
|
protected static void applyTo(double delta, ScrollValueBehaviour scrolling) {
|
||||||
scrolling.ticksUntilScrollPacket = 10;
|
scrolling.ticksUntilScrollPacket = 10;
|
||||||
int valueBefore = scrolling.scrollableValue;
|
int valueBefore = scrolling.scrollableValue;
|
||||||
|
@ -0,0 +1,147 @@
|
|||||||
|
package com.simibubi.create.foundation.utility;
|
||||||
|
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class PhysicalFloat {
|
||||||
|
|
||||||
|
float previousValue;
|
||||||
|
float value;
|
||||||
|
|
||||||
|
float speed;
|
||||||
|
|
||||||
|
private final ArrayList<Force> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -88,7 +88,7 @@ void main() {
|
|||||||
vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz;
|
vec3 norm = normalize(normalMat * vec4(aNormal, 0.)).xyz;
|
||||||
|
|
||||||
float scrollSize = aScrollTexture.w - aScrollTexture.y;
|
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);
|
Diffuse = diffuse(norm);
|
||||||
TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll);
|
TexCoords = aTexCoords - aSourceTexture + aScrollTexture.xy + vec2(0, scroll);
|
||||||
|
Loading…
Reference in New Issue
Block a user