Instanced mixers and presses.

This commit is contained in:
JozsefA 2021-03-09 15:46:15 -08:00
parent dcea504184
commit 2ddf57cd76
11 changed files with 225 additions and 20 deletions

View file

@ -39,10 +39,12 @@ import com.simibubi.create.content.contraptions.components.millstone.MillstoneRe
import com.simibubi.create.content.contraptions.components.millstone.MillstoneTileEntity;
import com.simibubi.create.content.contraptions.components.mixer.MechanicalMixerRenderer;
import com.simibubi.create.content.contraptions.components.mixer.MechanicalMixerTileEntity;
import com.simibubi.create.content.contraptions.components.mixer.MixerInstance;
import com.simibubi.create.content.contraptions.components.motor.CreativeMotorRenderer;
import com.simibubi.create.content.contraptions.components.motor.CreativeMotorTileEntity;
import com.simibubi.create.content.contraptions.components.press.MechanicalPressRenderer;
import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity;
import com.simibubi.create.content.contraptions.components.press.PressInstance;
import com.simibubi.create.content.contraptions.components.saw.SawInstance;
import com.simibubi.create.content.contraptions.components.saw.SawRenderer;
import com.simibubi.create.content.contraptions.components.saw.SawTileEntity;
@ -488,14 +490,14 @@ public class AllTileEntities {
.tileEntity("mechanical_press", MechanicalPressTileEntity::new)
.validBlocks(AllBlocks.MECHANICAL_PRESS)
.renderer(() -> MechanicalPressRenderer::new)
.onRegister(ShaftInstance::register)
.onRegister(PressInstance::register)
.register();
public static final TileEntityEntry<MechanicalMixerTileEntity> MECHANICAL_MIXER = Create.registrate()
.tileEntity("mechanical_mixer", MechanicalMixerTileEntity::new)
.validBlocks(AllBlocks.MECHANICAL_MIXER)
.renderer(() -> MechanicalMixerRenderer::new)
.onRegister(ShaftlessCogInstance::register)
.onRegister(MixerInstance::register)
.register();
public static final TileEntityEntry<DeployerTileEntity> DEPLOYER = Create.registrate()

View file

@ -31,22 +31,23 @@ public class MechanicalMixerRenderer extends KineticTileEntityRenderer {
@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
if (FastRenderDispatcher.available(te.getWorld())) return;
BlockState blockState = te.getBlockState();
MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te;
BlockPos pos = te.getPos();
IVertexBuilder vb = buffer.getBuffer(RenderType.getSolid());
if (!FastRenderDispatcher.available(te.getWorld())) {
SuperByteBuffer superBuffer = AllBlockPartials.SHAFTLESS_COGWHEEL.renderOn(blockState);
standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb);
}
int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos);
float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks);
float speed = mixer.getRenderedHeadRotationSpeed(partialTicks);
float time = AnimationTickHolder.getRenderTime();
float angle = (float) (((time * speed * 6 / 10f) % 360) / 180 * (float) Math.PI);
float angle = ((time * speed * 6 / 10f) % 360) / 180 * (float) Math.PI;
SuperByteBuffer poleRender = AllBlockPartials.MECHANICAL_MIXER_POLE.renderOn(blockState);
poleRender.translate(0, -renderedHeadOffset, 0)

View file

@ -0,0 +1,112 @@
package com.simibubi.create.content.contraptions.components.mixer;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.ShaftlessCogInstance;
import com.simibubi.create.content.contraptions.components.press.MechanicalPressTileEntity;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.client.renderer.Vector3d;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class MixerInstance extends ShaftlessCogInstance implements ITickableInstance {
public static void register(TileEntityType<? extends KineticTileEntity> type) {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
InstancedTileRenderRegistry.instance.register(type, MixerInstance::new));
}
private InstanceKey<RotatingData> mixerHead;
private InstanceKey<ModelData> mixerPole;
public MixerInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
super(dispatcher, tile);
}
@Override
protected void init() {
super.init();
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, lastState)
.createInstance();
mixerHead.getInstance()
.setRotationAxis(Direction.Axis.Y);
mixerPole = modelManager.getMaterial(RenderMaterials.MODELS)
.getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, lastState)
.createInstance();
updateLight();
MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) tile;
transformPole(getRenderedHeadOffset(mixer));
}
@Override
public void tick() {
MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) tile;
float renderedHeadOffset = getRenderedHeadOffset(mixer);
if (mixer.running) {
transformPole(renderedHeadOffset);
}
transformHead(mixer, renderedHeadOffset);
}
private void transformHead(MechanicalMixerTileEntity mixer, float renderedHeadOffset) {
float speed = mixer.getRenderedHeadRotationSpeed(AnimationTickHolder.getPartialTicks());
mixerHead.getInstance()
.setPosition(pos)
.nudge(0, -renderedHeadOffset, 0)
.setRotationalSpeed(speed * 2);
}
private void transformPole(float renderedHeadOffset) {
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(0, -renderedHeadOffset, 0);
mixerPole.getInstance().setTransformNoCopy(ms);
}
private float getRenderedHeadOffset(MechanicalMixerTileEntity mixer) {
return mixer.getRenderedHeadOffset(AnimationTickHolder.getPartialTicks());
}
@Override
public void updateLight() {
super.updateLight();
BlockPos down = pos.down();
mixerHead.getInstance()
.setBlockLight(world.getLightLevel(LightType.BLOCK, down))
.setSkyLight(world.getLightLevel(LightType.SKY, down));
mixerPole.getInstance()
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos));
}
@Override
public void remove() {
super.remove();
mixerHead.delete();
mixerPole.delete();
}
}

View file

@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
@ -29,13 +30,17 @@ public class MechanicalPressRenderer extends KineticTileEntityRenderer {
int light, int overlay) {
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
if (FastRenderDispatcher.available(te.getWorld())) return;
BlockPos pos = te.getPos();
BlockState blockState = te.getBlockState();
int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(te.getWorld(), blockState, pos);
float renderedHeadOffset = ((MechanicalPressTileEntity) te).getRenderedHeadOffset(partialTicks);
SuperByteBuffer headRender = AllBlockPartials.MECHANICAL_PRESS_HEAD.renderOnHorizontal(blockState);
headRender.translate(0, -renderedHeadOffset, 0).light(packedLightmapCoords).renderInto(ms, buffer.getBuffer(RenderType.getSolid()));
headRender.translate(0, -renderedHeadOffset, 0)
.light(packedLightmapCoords)
.renderInto(ms, buffer.getBuffer(RenderType.getSolid()));
}
@Override

View file

@ -0,0 +1,84 @@
package com.simibubi.create.content.contraptions.components.press;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.ITickableInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class PressInstance extends ShaftInstance implements ITickableInstance {
public static void register(TileEntityType<? extends KineticTileEntity> type) {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () ->
InstancedTileRenderRegistry.instance.register(type, PressInstance::new));
}
private InstanceKey<ModelData> pressHead;
public PressInstance(InstancedTileRenderer<?> dispatcher, KineticTileEntity tile) {
super(dispatcher, tile);
}
@Override
protected void init() {
super.init();
pressHead = modelManager.getMaterial(RenderMaterials.MODELS)
.getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, lastState)
.createInstance();
updateLight();
transformModels((MechanicalPressTileEntity) tile);
}
@Override
public void tick() {
MechanicalPressTileEntity press = (MechanicalPressTileEntity) tile;
if (!press.running)
return;
transformModels(press);
}
private void transformModels(MechanicalPressTileEntity press) {
float renderedHeadOffset = getRenderedHeadOffset(press);
MatrixStack ms = new MatrixStack();
MatrixStacker msr = MatrixStacker.of(ms);
msr.translate(getFloatingPos());
msr.translate(0, -renderedHeadOffset, 0);
pressHead.getInstance()
.setTransformNoCopy(ms);
}
private float getRenderedHeadOffset(MechanicalPressTileEntity press) {
return press.getRenderedHeadOffset(AnimationTickHolder.getPartialTicks());
}
@Override
public void updateLight() {
super.updateLight();
pressHead.getInstance()
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos));
}
@Override
public void remove() {
super.remove();
pressHead.delete();
}
}

View file

@ -68,8 +68,8 @@ public class StickerInstance extends TileEntityInstance<StickerTileEntity> imple
@Override
public void updateLight() {
head.getInstance()
.setBlockLight((byte) (world.getLightLevel(LightType.BLOCK, pos) << 4))
.setSkyLight((byte) (world.getLightLevel(LightType.SKY, pos) << 4));
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos));
}
@Override

View file

@ -86,8 +86,8 @@ public class GantryCarriageInstance extends ShaftInstance implements ITickableIn
@Override
public void updateLight() {
gantryCogs.getInstance()
.setBlockLight((byte) (world.getLightLevel(LightType.BLOCK, pos) << 4))
.setSkyLight((byte) (world.getLightLevel(LightType.SKY, pos) << 4));
.setBlockLight(world.getLightLevel(LightType.BLOCK, pos))
.setSkyLight(world.getLightLevel(LightType.SKY, pos));
}
@Override

View file

@ -156,8 +156,8 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst
@Override
public void updateLight() {
super.updateLight();
byte block = (byte) (world.getLightLevel(LightType.BLOCK, pos) << 4);
byte sky = (byte) (world.getLightLevel(LightType.SKY, pos) << 4);
int block = world.getLightLevel(LightType.BLOCK, pos);
int sky = world.getLightLevel(LightType.SKY, pos);
models.stream()

View file

@ -8,6 +8,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.logistics.block.mechanicalArm.ArmTileEntity.Phase;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.backend.Backend;
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.Iterate;
@ -41,7 +42,7 @@ public class ArmRenderer extends KineticTileEntityRenderer {
super.renderSafe(te, pt, ms, buffer, light, overlay);
ArmTileEntity arm = (ArmTileEntity) te;
boolean usingFlywheel = Backend.canUseInstancing();
boolean usingFlywheel = FastRenderDispatcher.available(te.getWorld());
ItemStack item = arm.heldItem;
boolean hasItem = !item.isEmpty();

View file

@ -54,13 +54,13 @@ public class ModelData extends InstanceData {
return this;
}
public ModelData setBlockLight(byte blockLight) {
this.blockLight = blockLight;
public ModelData setBlockLight(int blockLight) {
this.blockLight = (byte) (blockLight << 4);
return this;
}
public ModelData setSkyLight(byte skyLight) {
this.skyLight = skyLight;
public ModelData setSkyLight(int skyLight) {
this.skyLight = (byte) (skyLight << 4);
return this;
}

View file

@ -84,7 +84,7 @@ public class MatrixStacker {
return this;
}
private MatrixStacker multiply(Vector3f axis, double angle) {
public MatrixStacker multiply(Vector3f axis, double angle) {
if (angle == 0)
return this;
ms.multiply(axis.getDegreesQuaternion((float) angle));