mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-16 18:33:52 +01:00
Belt speed = item speed and secret wrench fix.
This commit is contained in:
parent
f14661fb6f
commit
a1e10a5c3c
6 changed files with 174 additions and 5 deletions
|
@ -110,7 +110,7 @@ public class BeltRenderer extends SafeTileEntityRenderer<BeltTileEntity> {
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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<WrenchMo
|
|||
IRenderTypeBuffer buffer, int light, int overlay) {
|
||||
renderer.render(model.getBakedModel(), light);
|
||||
|
||||
float worldTime = AnimationTickHolder.getRenderTime();
|
||||
float angle = worldTime * -.5f % 360;
|
||||
float xOffset = -1/16f;
|
||||
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);
|
||||
|
||||
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.filtering.FilteringRenderer;
|
||||
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.utility.AnimationTickHolder;
|
||||
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
||||
|
@ -84,6 +85,7 @@ public class ClientEvents {
|
|||
|
||||
AnimationTickHolder.tick();
|
||||
FastRenderDispatcher.tick();
|
||||
ScrollValueHandler.tick();
|
||||
|
||||
CreateClient.schematicSender.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.scrollvalue.ScrollValueBehaviour.StepContext;
|
||||
|
||||
import com.simibubi.create.foundation.utility.PhysicalFloat;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -20,6 +21,11 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|||
@EventBusSubscriber
|
||||
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)
|
||||
public static boolean onScroll(double delta) {
|
||||
RayTraceResult objectMouseOver = Minecraft.getInstance().objectMouseOver;
|
||||
|
@ -36,6 +42,10 @@ public class ScrollValueHandler {
|
|||
return false;
|
||||
if (!mc.player.isAllowEdit())
|
||||
return false;
|
||||
|
||||
passiveScrollDirection = (float) delta;
|
||||
wrenchCog.bump(3, delta * 10);
|
||||
|
||||
if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getHeldItemMainhand()))
|
||||
return false;
|
||||
if (scrolling.slotPositioning instanceof Sided)
|
||||
|
@ -57,6 +67,17 @@ public class ScrollValueHandler {
|
|||
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) {
|
||||
scrolling.ticksUntilScrollPacket = 10;
|
||||
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;
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue