Time well spent

- Fixed shaft models misaligning near large cogwheels
This commit is contained in:
simibubi 2021-11-10 17:27:03 +01:00
parent 70803db5c6
commit 6224a3e444
6 changed files with 192 additions and 6 deletions

View file

@ -18,7 +18,7 @@ public class AllBlockPartials {
SCHEMATICANNON_PIPE = get("schematicannon/pipe"), SCHEMATICANNON_PIPE = get("schematicannon/pipe"),
SHAFTLESS_COGWHEEL = get("cogwheel_shaftless"), SHAFTLESS_LARGE_COGWHEEL = get("large_cogwheel_shaftless"), SHAFTLESS_COGWHEEL = get("cogwheel_shaftless"), SHAFTLESS_LARGE_COGWHEEL = get("large_cogwheel_shaftless"),
SHAFT_HALF = get("shaft_half"), COGWHEEL_SHAFT = get("cogwheel_shaft"), SHAFT_HALF = get("shaft_half"),
BELT_PULLEY = get("belt_pulley"), BELT_START = get("belt/start"), BELT_MIDDLE = get("belt/middle"), BELT_PULLEY = get("belt_pulley"), BELT_START = get("belt/start"), BELT_MIDDLE = get("belt/middle"),
BELT_END = get("belt/end"), BELT_START_BOTTOM = get("belt/start_bottom"), BELT_END = get("belt/end"), BELT_START_BOTTOM = get("belt/start_bottom"),

View file

@ -104,6 +104,8 @@ import com.simibubi.create.content.contraptions.relays.belt.BeltInstance;
import com.simibubi.create.content.contraptions.relays.belt.BeltRenderer; import com.simibubi.create.content.contraptions.relays.belt.BeltRenderer;
import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity; import com.simibubi.create.content.contraptions.relays.belt.BeltTileEntity;
import com.simibubi.create.content.contraptions.relays.elementary.BracketedKineticTileEntity; import com.simibubi.create.content.contraptions.relays.elementary.BracketedKineticTileEntity;
import com.simibubi.create.content.contraptions.relays.elementary.BracketedKineticTileInstance;
import com.simibubi.create.content.contraptions.relays.elementary.BracketedKineticTileRenderer;
import com.simibubi.create.content.contraptions.relays.elementary.SimpleKineticTileEntity; import com.simibubi.create.content.contraptions.relays.elementary.SimpleKineticTileEntity;
import com.simibubi.create.content.contraptions.relays.encased.AdjustablePulleyTileEntity; import com.simibubi.create.content.contraptions.relays.encased.AdjustablePulleyTileEntity;
import com.simibubi.create.content.contraptions.relays.encased.ClutchTileEntity; import com.simibubi.create.content.contraptions.relays.encased.ClutchTileEntity;
@ -188,11 +190,11 @@ public class AllTileEntities {
// Kinetics // Kinetics
public static final TileEntityEntry<BracketedKineticTileEntity> BRACKETED_KINETIC = Create.registrate() public static final TileEntityEntry<BracketedKineticTileEntity> BRACKETED_KINETIC = Create.registrate()
.tileEntity("simple_kinetic", BracketedKineticTileEntity::new) .tileEntity("simple_kinetic", BracketedKineticTileEntity::new)
.instance(() -> SingleRotatingInstance::new) .instance(() -> BracketedKineticTileInstance::new)
.validBlocks(AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL) .validBlocks(AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL)
.renderer(() -> KineticTileEntityRenderer::new) .renderer(() -> BracketedKineticTileRenderer::new)
.register(); .register();
public static final TileEntityEntry<CreativeMotorTileEntity> MOTOR = Create.registrate() public static final TileEntityEntry<CreativeMotorTileEntity> MOTOR = Create.registrate()
.tileEntity("motor", CreativeMotorTileEntity::new) .tileEntity("motor", CreativeMotorTileEntity::new)
.instance(() -> HalfShaftInstance::new) .instance(() -> HalfShaftInstance::new)

View file

@ -97,9 +97,8 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
float offset = ICogWheel.isLargeCog(te.getBlockState()) ? 11.25f : 0; float offset = ICogWheel.isLargeCog(te.getBlockState()) ? 11.25f : 0;
double d = (((axis == Axis.X) ? 0 : pos.getX()) + ((axis == Axis.Y) ? 0 : pos.getY()) double d = (((axis == Axis.X) ? 0 : pos.getX()) + ((axis == Axis.Y) ? 0 : pos.getY())
+ ((axis == Axis.Z) ? 0 : pos.getZ())) % 2; + ((axis == Axis.Z) ? 0 : pos.getZ())) % 2;
if (d == 0) { if (d == 0)
offset = 22.5f; offset = 22.5f;
}
return offset; return offset;
} }

View file

@ -0,0 +1,92 @@
package com.simibubi.create.content.contraptions.relays.elementary;
import com.jozufozu.flywheel.backend.instancing.Instancer;
import com.jozufozu.flywheel.backend.material.MaterialManager;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
public class BracketedKineticTileInstance extends SingleRotatingInstance {
protected RotatingData additionalShaft;
public BracketedKineticTileInstance(MaterialManager modelManager, KineticTileEntity tile) {
super(modelManager, tile);
}
@Override
public void init() {
super.init();
if (!ICogWheel.isLargeCog(tile.getBlockState()))
return;
// Large cogs sometimes have to offset their teeth by 11.25 degrees in order to
// mesh properly
float speed = tile.getSpeed();
Axis axis = KineticTileEntityRenderer.getRotationAxisOf(tile);
BlockPos pos = tile.getBlockPos();
float offset = BracketedKineticTileRenderer.getShaftAngleOffset(axis, pos);
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
Instancer<RotatingData> half = getRotatingMaterial().getModel(AllBlockPartials.COGWHEEL_SHAFT, blockState,
facing, () -> this.rotateToAxis(axis));
additionalShaft = setup(half.createInstance(), speed);
additionalShaft.setRotationOffset(offset);
}
@Override
protected Instancer<RotatingData> getModel() {
if (!ICogWheel.isLargeCog(tile.getBlockState()))
return super.getModel();
Axis axis = KineticTileEntityRenderer.getRotationAxisOf(tile);
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
return getRotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_LARGE_COGWHEEL, blockState, facing,
() -> this.rotateToAxis(axis));
}
private PoseStack rotateToAxis(Axis axis) {
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
PoseStack poseStack = new PoseStack();
new MatrixTransformStack(poseStack).centre()
.rotateToFace(facing)
.multiply(Vector3f.XN.rotationDegrees(-90))
.unCentre();
return poseStack;
}
@Override
public void update() {
super.update();
if (additionalShaft != null) {
updateRotation(additionalShaft);
additionalShaft.setRotationOffset(BracketedKineticTileRenderer.getShaftAngleOffset(axis, pos));
}
}
@Override
public void updateLight() {
super.updateLight();
if (additionalShaft != null)
relight(pos, additionalShaft);
}
@Override
public void remove() {
super.remove();
if (additionalShaft != null)
additionalShaft.delete();
}
}

View file

@ -0,0 +1,71 @@
package com.simibubi.create.content.contraptions.relays.elementary;
import com.jozufozu.flywheel.backend.Backend;
import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.foundation.render.PartialBufferer;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider.Context;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
public class BracketedKineticTileRenderer extends KineticTileEntityRenderer {
public BracketedKineticTileRenderer(Context context) {
super(context);
}
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer,
int light, int overlay) {
if (Backend.getInstance()
.canUseInstancing(te.getLevel()))
return;
if (!AllBlocks.LARGE_COGWHEEL.has(te.getBlockState())) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
return;
}
// Large cogs sometimes have to offset their teeth by 11.25 degrees in order to
// mesh properly
Axis axis = getRotationAxisOf(te);
BlockPos pos = te.getBlockPos();
Direction facing = Direction.fromAxisAndDirection(axis, AxisDirection.POSITIVE);
renderRotatingBuffer(te,
PartialBufferer.getFacingVertical(AllBlockPartials.SHAFTLESS_LARGE_COGWHEEL, te.getBlockState(), facing),
ms, buffer.getBuffer(RenderType.solid()), light);
float offset = getShaftAngleOffset(axis, pos);
float time = AnimationTickHolder.getRenderTime(te.getLevel());
float angle = ((time * te.getSpeed() * 3f / 10 + offset) % 360) / 180 * (float) Math.PI;
SuperByteBuffer shaft =
PartialBufferer.getFacingVertical(AllBlockPartials.COGWHEEL_SHAFT, te.getBlockState(), facing);
kineticRotationTransform(shaft, te, axis, angle, light);
shaft.renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
public static float getShaftAngleOffset(Axis axis, BlockPos pos) {
float offset = 0;
double d = (((axis == Axis.X) ? 0 : pos.getX()) + ((axis == Axis.Y) ? 0 : pos.getY())
+ ((axis == Axis.Z) ? 0 : pos.getZ())) % 2;
if (d == 0)
offset = 22.5f;
return offset;
}
}

View file

@ -0,0 +1,22 @@
{
"credit": "Made with Blockbench",
"textures": {
"0": "create:block/axis_top",
"1": "create:block/cogwheel_axis",
"particle": "create:block/axis_top"
},
"elements": [
{
"from": [6, 0, 6],
"to": [10, 16, 10],
"faces": {
"north": {"uv": [6, 0, 10, 16], "texture": "#1"},
"east": {"uv": [6, 0, 10, 16], "texture": "#1"},
"south": {"uv": [6, 0, 10, 16], "texture": "#1"},
"west": {"uv": [6, 0, 10, 16], "texture": "#1"},
"up": {"uv": [6, 6, 10, 10], "texture": "#0"},
"down": {"uv": [6, 6, 10, 10], "texture": "#0"}
}
}
]
}