Ticking things.

- Differentiate tickable and dynamic instances.
 - Instanced repeaters.
This commit is contained in:
JozsefA 2021-03-20 16:30:09 -07:00
parent 9df9a99185
commit f6cfd377a7
33 changed files with 221 additions and 242 deletions

View file

@ -97,6 +97,7 @@ import com.simibubi.create.content.logistics.block.chute.SmartChuteTileEntity;
import com.simibubi.create.content.logistics.block.depot.DepotRenderer;
import com.simibubi.create.content.logistics.block.depot.DepotTileEntity;
import com.simibubi.create.content.logistics.block.diodes.AdjustablePulseRepeaterTileEntity;
import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterInstance;
import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterRenderer;
import com.simibubi.create.content.logistics.block.diodes.AdjustableRepeaterTileEntity;
import com.simibubi.create.content.logistics.block.funnel.FunnelInstance;
@ -595,6 +596,7 @@ public class AllTileEntities {
public static final TileEntityEntry<AdjustableRepeaterTileEntity> ADJUSTABLE_REPEATER = Create.registrate()
.tileEntity("adjustable_repeater", AdjustableRepeaterTileEntity::new)
.instance(() -> AdjustableRepeaterInstance::new)
.validBlocks(AllBlocks.ADJUSTABLE_REPEATER)
.renderer(() -> AdjustableRepeaterRenderer::new)
.register();
@ -602,6 +604,7 @@ public class AllTileEntities {
public static final TileEntityEntry<AdjustablePulseRepeaterTileEntity> ADJUSTABLE_PULSE_REPEATER =
Create.registrate()
.tileEntity("adjustable_pulse_repeater", AdjustablePulseRepeaterTileEntity::new)
.instance(() -> AdjustableRepeaterInstance::new)
.validBlocks(AllBlocks.ADJUSTABLE_PULSE_REPEATER)
.renderer(() -> AdjustableRepeaterRenderer::new)
.register();

View file

@ -2,14 +2,10 @@ package com.simibubi.create.content.contraptions.base;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class HalfShaftInstance extends SingleRotatingInstance {
public HalfShaftInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
@ -19,10 +15,10 @@ public class HalfShaftInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
Direction dir = getShaftDirection();
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir);
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir);
}
protected Direction getShaftDirection() {
return lastState.get(BlockStateProperties.FACING);
return blockState.get(BlockStateProperties.FACING);
}
}

View file

@ -1,13 +1,9 @@
package com.simibubi.create.content.contraptions.base;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class HorizontalHalfShaftInstance extends HalfShaftInstance {
@ -17,6 +13,6 @@ public class HorizontalHalfShaftInstance extends HalfShaftInstance {
@Override
protected Direction getShaftDirection() {
return lastState.get(BlockStateProperties.HORIZONTAL_FACING).getOpposite();
return blockState.get(BlockStateProperties.HORIZONTAL_FACING).getOpposite();
}
}

View file

@ -37,7 +37,7 @@ public abstract class KineticTileInstance<T extends KineticTileEntity> extends T
}
protected float getRotationOffset(final Direction.Axis axis) {
float offset = CogWheelBlock.isLargeCog(lastState) ? 11.25f : 0;
float offset = CogWheelBlock.isLargeCog(blockState) ? 11.25f : 0;
double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY())
+ ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2;
if (d == 0) {
@ -52,7 +52,7 @@ public abstract class KineticTileInstance<T extends KineticTileEntity> extends T
}
public Direction.Axis getRotationAxis() {
return ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
return ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
}
protected final RenderMaterial<?, InstancedModel<RotatingData>> rotatingMaterial() {

View file

@ -19,13 +19,13 @@ public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntit
@Override
protected void init() {
Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
rotatingModelKey = setup(getModel().createInstance(), tile.getSpeed(), axis);
}
@Override
public void onUpdate() {
Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
updateRotation(rotatingModelKey, axis);
}
@ -40,7 +40,7 @@ public class SingleRotatingInstance extends KineticTileInstance<KineticTileEntit
}
protected BlockState getRenderedBlockState() {
return lastState;
return blockState;
}
protected InstancedModel<RotatingData> getModel() {

View file

@ -8,14 +8,10 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class MechanicalCrafterInstance extends SingleRotatingInstance {
@ -25,7 +21,7 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
Direction facing = lastState.get(MechanicalCrafterBlock.HORIZONTAL_FACING);
Direction facing = blockState.get(MechanicalCrafterBlock.HORIZONTAL_FACING);
Supplier<MatrixStack> ms = () -> {
MatrixStack stack = new MatrixStack();
@ -39,6 +35,6 @@ public class MechanicalCrafterInstance extends SingleRotatingInstance {
stacker.unCentre();
return stack;
};
return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, lastState, facing, ms);
return rotatingMaterial().getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState, facing, ms);
}
}

View file

@ -4,21 +4,15 @@ 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.SingleRotatingInstance;
import com.simibubi.create.content.logistics.block.redstone.AnalogLeverInstance;
import com.simibubi.create.content.logistics.block.redstone.AnalogLeverTileEntity;
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.block.Block;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class HandCrankInstance extends SingleRotatingInstance implements ITickableInstance {
public class HandCrankInstance extends SingleRotatingInstance implements IDynamicInstance {
private InstanceKey<ModelData> crank;
private Direction facing;
@ -31,22 +25,22 @@ public class HandCrankInstance extends SingleRotatingInstance implements ITickab
protected void init() {
super.init();
Block block = lastState.getBlock();
Block block = blockState.getBlock();
AllBlockPartials renderedHandle = null;
if (block instanceof HandCrankBlock)
renderedHandle = ((HandCrankBlock) block).getRenderedHandle();
if (renderedHandle == null)
return;
facing = lastState.get(BlockStateProperties.FACING);
InstancedModel<ModelData> model = renderedHandle.renderOnDirectionalSouthModel(modelManager, lastState, facing.getOpposite());
facing = blockState.get(BlockStateProperties.FACING);
InstancedModel<ModelData> model = renderedHandle.renderOnDirectionalSouthModel(modelManager, blockState, facing.getOpposite());
crank = model.createInstance();
updateLight();
}
@Override
public void tick() {
public void beginFrame() {
if (crank == null) return;
HandCrankTileEntity crankTile = (HandCrankTileEntity) tile;

View file

@ -16,7 +16,7 @@ import net.minecraft.util.math.Vec3d;
import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE;
import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING;
public class DeployerInstance extends ShaftInstance implements ITickableInstance {
public class DeployerInstance extends ShaftInstance implements IDynamicInstance {
DeployerTileEntity tile;
@ -42,22 +42,22 @@ public class DeployerInstance extends ShaftInstance implements ITickableInstance
super.init();
this.tile = (DeployerTileEntity) super.tile;
facing = lastState.get(FACING);
facing = blockState.get(FACING);
boolean rotatePole = lastState.get(AXIS_ALONG_FIRST_COORDINATE) ^ facing.getAxis() == Direction.Axis.Z;
boolean rotatePole = blockState.get(AXIS_ALONG_FIRST_COORDINATE) ^ facing.getAxis() == Direction.Axis.Z;
yRot = AngleHelper.horizontalAngle(facing);
zRot = facing == Direction.UP ? 270 : facing == Direction.DOWN ? 90 : 0;
zRotPole = rotatePole ? 90 : 0;
pole = modelManager.getBasicMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, lastState).createInstance();
pole = modelManager.getBasicMaterial().getModel(AllBlockPartials.DEPLOYER_POLE, blockState).createInstance();
updateHandPose();
relight(pos, pole.getInstance());
}
@Override
public void tick() {
public void beginFrame() {
boolean newHand = updateHandPose();
@ -100,7 +100,7 @@ public class DeployerInstance extends ShaftInstance implements ITickableInstance
if (hand != null) hand.delete();
hand = modelManager.getBasicMaterial().getModel(currentHand, lastState).createInstance();
hand = modelManager.getBasicMaterial().getModel(currentHand, blockState).createInstance();
relight(pos, hand.getInstance());

View file

@ -8,16 +8,11 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
@ -30,13 +25,13 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
@Override
protected void init() {
final Direction direction = lastState.get(FACING);
final Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
final Direction direction = blockState.get(FACING);
final Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
InstancedModel<RotatingData> shaftHalf =
AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite());
AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite());
InstancedModel<RotatingData> fanInner =
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, lastState, direction.getOpposite());
AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite());
shaft = shaftHalf.createInstance();
shaft.getInstance()
@ -67,7 +62,7 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
@Override
protected void onUpdate() {
Direction.Axis axis = lastState.get(FACING).getAxis();
Direction.Axis axis = blockState.get(FACING).getAxis();
updateRotation(shaft, axis);
fan.getInstance()
@ -79,7 +74,7 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
@Override
public void updateLight() {
final Direction direction = lastState.get(FACING);
final Direction direction = blockState.get(FACING);
BlockPos behind = pos.offset(direction.getOpposite());
relight(behind, shaft.getInstance());

View file

@ -1,17 +1,14 @@
package com.simibubi.create.content.contraptions.components.flywheel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
@ -20,16 +17,11 @@ import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> implements ITickableInstance {
public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> implements IDynamicInstance {
protected Direction facing;
protected boolean connectedLeft;
@ -57,16 +49,16 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
@Override
protected void init() {
facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING);
facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
shaft = setup(shaftModel().createInstance(), tile.getSpeed(), axis);
wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, lastState.rotate(Rotation.CLOCKWISE_90)).createInstance();
wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, blockState.rotate(Rotation.CLOCKWISE_90)).createInstance();
connection = FlywheelBlock.getConnection(lastState);
connection = FlywheelBlock.getConnection(blockState);
if (connection != null) {
connectedLeft = lastState.get(FlywheelBlock.CONNECTION) == FlywheelBlock.ConnectionState.LEFT;
connectedLeft = blockState.get(FlywheelBlock.CONNECTION) == FlywheelBlock.ConnectionState.LEFT;
boolean flipAngle = connection.getAxis() == Direction.Axis.X ^ connection.getAxisDirection() == Direction.AxisDirection.NEGATIVE;
@ -74,10 +66,10 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, lastState).createInstance();
lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, lastState).createInstance();
upperSliding = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, lastState).createInstance();
lowerSliding = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, lastState).createInstance();
upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance();
lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance();
upperSliding = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_SLIDING, blockState).createInstance();
lowerSliding = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_SLIDING, blockState).createInstance();
connectors = Lists.newArrayList(upperRotating, lowerRotating, upperSliding, lowerSliding);
} else {
@ -89,7 +81,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
}
@Override
public void tick() {
public void beginFrame() {
float partialTicks = AnimationTickHolder.getPartialTicks();
@ -144,7 +136,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
@Override
protected void onUpdate() {
Direction.Axis axis = ((IRotate) lastState.getBlock()).getRotationAxis(lastState);
Direction.Axis axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState);
updateRotation(shaft, axis);
}
@ -167,7 +159,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
}
protected InstancedModel<RotatingData> shaftModel() {
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, facing.getOpposite());
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, facing.getOpposite());
}
protected void transformConnector(MatrixStacker ms, boolean upper, boolean rotating, float angle, boolean flip) {

View file

@ -4,7 +4,6 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
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.TileEntityInstance;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
@ -12,12 +11,7 @@ import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.block.Block;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
@ -29,7 +23,7 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
@Override
protected void init() {
Block block = lastState
Block block = blockState
.getBlock();
if (!(block instanceof EngineBlock))
return;
@ -37,9 +31,9 @@ public class EngineInstance extends TileEntityInstance<EngineTileEntity> {
EngineBlock engineBlock = (EngineBlock) block;
AllBlockPartials frame = engineBlock.getFrameModel();
Direction facing = lastState.get(BlockStateProperties.HORIZONTAL_FACING);
Direction facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, lastState).createInstance();
this.frame = modelManager.getMaterial(RenderMaterials.MODELS).getModel(frame, blockState).createInstance();
float angle = AngleHelper.rad(AngleHelper.horizontalAngle(facing));

View file

@ -5,22 +5,14 @@ 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 class MixerInstance extends ShaftlessCogInstance implements IDynamicInstance {
private InstanceKey<RotatingData> mixerHead;
private InstanceKey<ModelData> mixerPole;
@ -33,14 +25,14 @@ public class MixerInstance extends ShaftlessCogInstance implements ITickableInst
protected void init() {
super.init();
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, lastState)
mixerHead = rotatingMaterial().getModel(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState)
.createInstance();
mixerHead.getInstance()
.setRotationAxis(Direction.Axis.Y);
mixerPole = modelManager.getMaterial(RenderMaterials.MODELS)
.getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, lastState)
.getModel(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState)
.createInstance();
@ -53,7 +45,7 @@ public class MixerInstance extends ShaftlessCogInstance implements ITickableInst
}
@Override
public void tick() {
public void beginFrame() {
MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) tile;
float renderedHeadOffset = getRenderedHeadOffset(mixer);

View file

@ -5,19 +5,14 @@ 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.IDynamicInstance;
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 class PressInstance extends ShaftInstance implements IDynamicInstance {
private InstanceKey<ModelData> pressHead;
@ -30,7 +25,7 @@ public class PressInstance extends ShaftInstance implements ITickableInstance {
super.init();
pressHead = modelManager.getMaterial(RenderMaterials.MODELS)
.getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, lastState)
.getModel(AllBlockPartials.MECHANICAL_PRESS_HEAD, blockState)
.createInstance();
updateLight();
@ -38,7 +33,7 @@ public class PressInstance extends ShaftInstance implements ITickableInstance {
}
@Override
public void tick() {
public void beginFrame() {
MechanicalPressTileEntity press = (MechanicalPressTileEntity) tile;
if (!press.running)
return;

View file

@ -8,13 +8,9 @@ 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 com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Rotation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class SawInstance extends SingleRotatingInstance {
@ -24,8 +20,8 @@ public class SawInstance extends SingleRotatingInstance {
@Override
protected InstancedModel<RotatingData> getModel() {
if (lastState.get(FACING).getAxis().isHorizontal())
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180));
if (blockState.get(FACING).getAxis().isHorizontal())
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180));
else
return rotatingMaterial().getModel(KineticTileEntityRenderer.KINETIC_TILE, shaft(getRotationAxis()));
}

View file

@ -9,13 +9,9 @@ import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class StickerInstance extends TileEntityInstance<StickerTileEntity> implements ITickableInstance {
public class StickerInstance extends TileEntityInstance<StickerTileEntity> implements IDynamicInstance {
float lastOffset = Float.NaN;
@ -27,24 +23,24 @@ public class StickerInstance extends TileEntityInstance<StickerTileEntity> imple
@Override
protected void init() {
head = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.STICKER_HEAD, lastState).createInstance();
head = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance();
updateLight();
}
@Override
public void tick() {
lastState = world.getBlockState(pos);
public void beginFrame() {
blockState = world.getBlockState(pos);
float offset = tile.piston.getValue(AnimationTickHolder.getPartialTicks());
if (tile.getWorld() != Minecraft.getInstance().world)
offset = lastState.get(StickerBlock.EXTENDED) ? 1 : 0;
offset = blockState.get(StickerBlock.EXTENDED) ? 1 : 0;
if (Math.abs(offset - lastOffset) < 1e-4)
return;
Direction facing = lastState.get(StickerBlock.FACING);
Direction facing = blockState.get(StickerBlock.FACING);
MatrixStack stack = new MatrixStack();
MatrixStacker.of(stack)
.translate(getFloatingPos())

View file

@ -6,23 +6,18 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
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.IDynamicInstance;
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.AngleHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class GantryCarriageInstance extends ShaftInstance implements ITickableInstance {
public class GantryCarriageInstance extends ShaftInstance implements IDynamicInstance {
private InstanceKey<ModelData> gantryCogs;
@ -35,17 +30,17 @@ public class GantryCarriageInstance extends ShaftInstance implements ITickableIn
super.init();
gantryCogs = modelManager.getMaterial(RenderMaterials.MODELS)
.getModel(AllBlockPartials.GANTRY_COGS, lastState)
.getModel(AllBlockPartials.GANTRY_COGS, blockState)
.createInstance();
updateLight();
}
@Override
public void tick() {
lastState = tile.getBlockState();
Direction facing = lastState.get(GantryCarriageBlock.FACING);
Boolean alongFirst = lastState.get(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE);
public void beginFrame() {
blockState = tile.getBlockState();
Direction facing = blockState.get(GantryCarriageBlock.FACING);
Boolean alongFirst = blockState.get(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE);
Direction.Axis rotationAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
BlockPos visualPos = facing.getAxisDirection() == Direction.AxisDirection.POSITIVE ? tile.getPos()
: tile.getPos()

View file

@ -5,7 +5,7 @@ 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.relays.encased.ShaftInstance;
import com.simibubi.create.foundation.render.backend.instancing.ITickableInstance;
import com.simibubi.create.foundation.render.backend.instancing.IDynamicInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
@ -15,7 +15,7 @@ import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.util.Direction;
import net.minecraft.util.math.MathHelper;
public class FluidValveInstance extends ShaftInstance implements ITickableInstance {
public class FluidValveInstance extends ShaftInstance implements IDynamicInstance {
protected InstanceKey<ModelData> pointer;
@ -31,26 +31,26 @@ public class FluidValveInstance extends ShaftInstance implements ITickableInstan
protected void init() {
super.init();
Direction facing = lastState.get(FluidValveBlock.FACING);
Direction facing = blockState.get(FluidValveBlock.FACING);
yRot = AngleHelper.horizontalAngle(facing);
xRot = facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90;
Direction.Axis pipeAxis = FluidValveBlock.getPipeAxis(lastState);
Direction.Axis pipeAxis = FluidValveBlock.getPipeAxis(blockState);
Direction.Axis shaftAxis = KineticTileEntityRenderer.getRotationAxisOf(tile);
pointerRotationOffset = 0;
if (pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical())
pointerRotationOffset = 90;
pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, lastState).createInstance();
pointer = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance();
updateLight();
transformPointer((FluidValveTileEntity) tile);
}
@Override
public void tick() {
public void beginFrame() {
FluidValveTileEntity valve = (FluidValveTileEntity) tile;

View file

@ -6,14 +6,12 @@ import java.util.function.Supplier;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.KineticData;
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.foundation.block.render.SpriteShiftEntry;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.MatrixStacker;
@ -41,13 +39,13 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
@Override
protected void init() {
if (!AllBlocks.BELT.has(lastState))
if (!AllBlocks.BELT.has(blockState))
return;
keys = new ArrayList<>(2);
beltSlope = lastState.get(BeltBlock.SLOPE);
facing = lastState.get(BeltBlock.HORIZONTAL_FACING);
beltSlope = blockState.get(BeltBlock.SLOPE);
facing = blockState.get(BeltBlock.HORIZONTAL_FACING);
upward = beltSlope == BeltSlope.UPWARD;
diagonal = beltSlope.isDiagonal();
sideways = beltSlope == BeltSlope.SIDEWAYS;
@ -55,7 +53,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
alongX = facing.getAxis() == Direction.Axis.X;
alongZ = facing.getAxis() == Direction.Axis.Z;
BeltPart part = lastState.get(BeltBlock.PART);
BeltPart part = blockState.get(BeltBlock.PART);
boolean start = part == BeltPart.START;
boolean end = part == BeltPart.END;
DyeColor color = tile.color.orElse(null);
@ -64,7 +62,7 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
AllBlockPartials beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom);
SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
InstancedModel<BeltData> beltModel = beltPartial.renderOnBelt(modelManager, lastState);
InstancedModel<BeltData> beltModel = beltPartial.renderOnBelt(modelManager, blockState);
keys.add(setup(beltModel.createInstance(), bottom, spriteShift));
@ -144,11 +142,11 @@ public class BeltInstance extends KineticTileInstance<BeltTileEntity> {
return modelTransform;
};
return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, lastState, dir, ms);
return rotatingMaterial().getModel(AllBlockPartials.BELT_PULLEY, blockState, dir, ms);
}
private Direction getOrientation() {
Direction dir = lastState.get(BeltBlock.HORIZONTAL_FACING)
Direction dir = blockState.get(BeltBlock.HORIZONTAL_FACING)
.rotateY();
if (beltSlope == BeltSlope.SIDEWAYS)
dir = Direction.UP;

View file

@ -27,14 +27,14 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
protected void init() {
keys = new ArrayList<>(2);
Block block = lastState.getBlock();
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(lastState);
Block block = blockState.getBlock();
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
float speed = tile.getSpeed();
for (Direction dir : Iterate.directionsInAxis(boxAxis)) {
InstancedModel<RotatingData> half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, dir);
InstancedModel<RotatingData> half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir);
float splitSpeed = speed * tile.getRotationSpeedModifier(dir);
@ -44,8 +44,8 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
@Override
public void onUpdate() {
Block block = lastState.getBlock();
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(lastState);
Block block = blockState.getBlock();
final Direction.Axis boxAxis = ((IRotate) block).getRotationAxis(blockState);
Direction[] directions = Iterate.directionsInAxis(boxAxis);

View file

@ -5,7 +5,7 @@ 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.IDynamicInstance;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
@ -16,7 +16,7 @@ import net.minecraft.util.math.MathHelper;
import java.util.ArrayList;
public abstract class GaugeInstance extends ShaftInstance implements ITickableInstance {
public abstract class GaugeInstance extends ShaftInstance implements IDynamicInstance {
protected ArrayList<DialFace> faces;
@ -33,9 +33,9 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn
faces = new ArrayList<>(2);
GaugeTileEntity gaugeTile = (GaugeTileEntity) tile;
GaugeBlock gaugeBlock = (GaugeBlock) lastState.getBlock();
GaugeBlock gaugeBlock = (GaugeBlock) blockState.getBlock();
InstancedModel<ModelData> dialModel = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_DIAL, lastState);
InstancedModel<ModelData> dialModel = modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_DIAL, blockState);
InstancedModel<ModelData> headModel = getHeadModel();
ms = new MatrixStack();
@ -45,7 +45,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn
float progress = MathHelper.lerp(AnimationTickHolder.getPartialTicks(), gaugeTile.prevDialState, gaugeTile.dialState);
for (Direction facing : Iterate.directions) {
if (!gaugeBlock.shouldRenderHeadOnFace(world, pos, lastState, facing))
if (!gaugeBlock.shouldRenderHeadOnFace(world, pos, blockState, facing))
continue;
DialFace face = makeFace(facing, dialModel, headModel);
@ -63,7 +63,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn
}
@Override
public void tick() {
public void beginFrame() {
GaugeTileEntity gaugeTile = (GaugeTileEntity) tile;
if (MathHelper.epsilonEquals(gaugeTile.prevDialState, gaugeTile.dialState))
@ -156,7 +156,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn
@Override
protected InstancedModel<ModelData> getHeadModel() {
return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, lastState);
return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_SPEED, blockState);
}
}
@ -167,7 +167,7 @@ public abstract class GaugeInstance extends ShaftInstance implements ITickableIn
@Override
protected InstancedModel<ModelData> getHeadModel() {
return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, lastState);
return modelManager.getMaterial(RenderMaterials.MODELS).getModel(AllBlockPartials.GAUGE_HEAD_STRESS, blockState);
}
}
}

View file

@ -8,17 +8,13 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance;
import com.simibubi.create.content.contraptions.base.RotatingData;
import com.simibubi.create.foundation.render.backend.instancing.InstanceKey;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderRegistry;
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
@ -33,7 +29,7 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
protected void init() {
keys = new EnumMap<>(Direction.class);
final Direction.Axis boxAxis = lastState.get(BlockStateProperties.AXIS);
final Direction.Axis boxAxis = blockState.get(BlockStateProperties.AXIS);
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
int skyLight = world.getLightLevel(LightType.SKY, pos);
@ -44,7 +40,7 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
if (boxAxis == axis)
continue;
InstancedModel<RotatingData> shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, lastState, direction);
InstancedModel<RotatingData> shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction);
InstanceKey<RotatingData> key = shaft.createInstance();

View file

@ -6,18 +6,15 @@ import com.simibubi.create.content.logistics.block.FlapData;
import com.simibubi.create.foundation.gui.widgets.InterpolatedValue;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Map;
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> implements ITickableInstance {
public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity> implements IDynamicInstance {
private Map<Direction, ArrayList<InstanceKey<FlapData>>> tunnelFlaps;
@ -31,7 +28,7 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
tunnelFlaps = new EnumMap<>(Direction.class);
InstancedModel<FlapData> model = modelManager.getMaterial(KineticRenderMaterials.FLAPS)
.getModel(AllBlockPartials.BELT_TUNNEL_FLAP, lastState);
.getModel(AllBlockPartials.BELT_TUNNEL_FLAP, blockState);
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
int skyLight = world.getLightLevel(LightType.SKY, pos);
@ -71,7 +68,7 @@ public class BeltTunnelInstance extends TileEntityInstance<BeltTunnelTileEntity>
}
@Override
public void tick() {
public void beginFrame() {
tunnelFlaps.forEach((direction, keys) -> {
InterpolatedValue flapValue = tile.flaps.get(direction);
if (flapValue == null) {

View file

@ -0,0 +1,58 @@
package com.simibubi.create.content.logistics.block.diodes;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.MatrixStacker;
public class AdjustableRepeaterInstance extends TileEntityInstance<AdjustableRepeaterTileEntity> implements ITickableInstance {
protected InstanceKey<ModelData> indicator;
protected int previousState;
public AdjustableRepeaterInstance(InstancedTileRenderer<?> modelManager, AdjustableRepeaterTileEntity tile) {
super(modelManager, tile);
}
@Override
protected void init() {
indicator = modelManager.getBasicMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();
MatrixStack ms = new MatrixStack();
MatrixStacker.of(ms).translate(getFloatingPos());
indicator.getInstance()
.setTransform(ms)
.setColor(getColor());
previousState = tile.state;
updateLight();
}
@Override
public void tick() {
if (previousState == tile.state) return;
indicator.getInstance().setColor(getColor());
previousState = tile.state;
}
@Override
public void updateLight() {
relight(pos, indicator.getInstance());
}
@Override
public void remove() {
indicator.delete();
}
protected int getColor() {
return ColorHelper.mixColors(0x2C0300, 0xCD0000, tile.state / (float) tile.maxState.getValue());
}
}

View file

@ -5,6 +5,7 @@ import static net.minecraft.block.RedstoneDiodeBlock.POWERED;
import java.util.List;
import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendered;
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour;
@ -15,7 +16,7 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.math.MathHelper;
public class AdjustableRepeaterTileEntity extends SmartTileEntity {
public class AdjustableRepeaterTileEntity extends SmartTileEntity implements IInstanceRendered {
public int state;
public boolean charging;
@ -119,5 +120,4 @@ public class AdjustableRepeaterTileEntity extends SmartTileEntity {
state += charging ? 1 : -1;
}
}

View file

@ -5,15 +5,12 @@ import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
import com.simibubi.create.content.logistics.block.FlapData;
import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import java.util.ArrayList;
public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> implements ITickableInstance {
public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> implements IDynamicInstance {
private ArrayList<InstanceKey<FlapData>> flaps;
@ -27,15 +24,15 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
if (!tile.hasFlap()) return;
AllBlockPartials flapPartial = (lastState.getBlock() instanceof FunnelBlock ? AllBlockPartials.FUNNEL_FLAP
AllBlockPartials flapPartial = (blockState.getBlock() instanceof FunnelBlock ? AllBlockPartials.FUNNEL_FLAP
: AllBlockPartials.BELT_FUNNEL_FLAP);
InstancedModel<FlapData> model = modelManager.getMaterial(KineticRenderMaterials.FLAPS)
.getModel(flapPartial, lastState);
.getModel(flapPartial, blockState);
int blockLight = world.getLightLevel(LightType.BLOCK, pos);
int skyLight = world.getLightLevel(LightType.SKY, pos);
Direction direction = FunnelBlock.getFunnelFacing(lastState);
Direction direction = FunnelBlock.getFunnelFacing(blockState);
float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks());
float horizontalAngle = direction.getOpposite().getHorizontalAngle();
@ -62,7 +59,7 @@ public class FunnelInstance extends TileEntityInstance<FunnelTileEntity> impleme
}
@Override
public void tick() {
public void beginFrame() {
if (flaps == null) return;
float flapness = tile.flap.get(AnimationTickHolder.getPartialTicks());

View file

@ -6,7 +6,6 @@ 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.SingleRotatingInstance;
import com.simibubi.create.foundation.gui.widgets.InterpolatedValue;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.instancing.*;
@ -19,16 +18,11 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import java.util.ArrayList;
import java.util.stream.Stream;
public class ArmInstance extends SingleRotatingInstance implements ITickableInstance {
public class ArmInstance extends SingleRotatingInstance implements IDynamicInstance {
private InstanceKey<ModelData> base;
private InstanceKey<ModelData> lowerBody;
@ -51,13 +45,13 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
base = mat.getModel(AllBlockPartials.ARM_BASE, lastState).createInstance();
lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, lastState).createInstance();
upperBody = mat.getModel(AllBlockPartials.ARM_UPPER_BODY, lastState).createInstance();
head = mat.getModel(AllBlockPartials.ARM_HEAD, lastState).createInstance();
claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, lastState).createInstance();
base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance();
lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance();
upperBody = mat.getModel(AllBlockPartials.ARM_UPPER_BODY, blockState).createInstance();
head = mat.getModel(AllBlockPartials.ARM_HEAD, blockState).createInstance();
claw = mat.getModel(AllBlockPartials.ARM_CLAW_BASE, blockState).createInstance();
InstancedModel<ModelData> clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, lastState);
InstancedModel<ModelData> clawHalfModel = mat.getModel(AllBlockPartials.ARM_CLAW_GRIP, blockState);
InstanceKey<ModelData> clawGrip1 = clawHalfModel.createInstance();
InstanceKey<ModelData> clawGrip2 = clawHalfModel.createInstance();
@ -65,12 +59,12 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst
models = Lists.newArrayList(base, lowerBody, upperBody, head, claw, clawGrip1, clawGrip2);
firstTick = true;
tick();
beginFrame();
updateLight();
}
@Override
public void tick() {
public void beginFrame() {
ArmTileEntity arm = (ArmTileEntity) tile;
boolean settled = arm.baseAngle.settled() && arm.lowerArmAngle.settled() && arm.upperArmAngle.settled() && arm.headAngle.settled();
@ -107,7 +101,7 @@ public class ArmInstance extends SingleRotatingInstance implements ITickableInst
msr.translate(getFloatingPos());
msr.centre();
if (lastState.get(ArmBlock.CEILING))
if (blockState.get(ArmBlock.CEILING))
msr.rotateX(180);
ArmRenderer.transformBase(msr, baseAngle);

View file

@ -2,8 +2,6 @@ package com.simibubi.create.content.logistics.block.redstone;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.components.flywheel.FlyWheelInstance;
import com.simibubi.create.content.contraptions.components.flywheel.FlywheelTileEntity;
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;
@ -12,12 +10,9 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.MatrixStacker;
import net.minecraft.state.properties.AttachFace;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntity> implements ITickableInstance {
public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntity> implements IDynamicInstance {
protected InstanceKey<ModelData> handle;
protected InstanceKey<ModelData> indicator;
@ -33,19 +28,19 @@ public class AnalogLeverInstance extends TileEntityInstance<AnalogLeverTileEntit
protected void init() {
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, lastState).createInstance();
indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, lastState).createInstance();
handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance();
indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance();
AttachFace face = lastState.get(AnalogLeverBlock.FACE);
AttachFace face = blockState.get(AnalogLeverBlock.FACE);
rX = face == AttachFace.FLOOR ? 0 : face == AttachFace.WALL ? 90 : 180;
rY = AngleHelper.horizontalAngle(lastState.get(AnalogLeverBlock.HORIZONTAL_FACING));
rY = AngleHelper.horizontalAngle(blockState.get(AnalogLeverBlock.HORIZONTAL_FACING));
setupModel();
updateLight();
}
@Override
public void tick() {
public void beginFrame() {
if (!tile.clientState.settled())
setupModel();
}

View file

@ -1,27 +1,15 @@
package com.simibubi.create.content.schematics.block;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelInstance;
import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelTileEntity;
import com.simibubi.create.foundation.render.SuperByteBuffer;
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.block.BlockState;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.LightType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
public class SchematicannonInstance extends TileEntityInstance<SchematicannonTileEntity> implements ITickableInstance {
public class SchematicannonInstance extends TileEntityInstance<SchematicannonTileEntity> implements IDynamicInstance {
private InstanceKey<ModelData> connector;
private InstanceKey<ModelData> pipe;
@ -35,14 +23,14 @@ public class SchematicannonInstance extends TileEntityInstance<SchematicannonTil
RenderMaterial<?, InstancedModel<ModelData>> mat = modelManager.getMaterial(RenderMaterials.MODELS);
connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, lastState).createInstance();
pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, lastState).createInstance();
connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance();
pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance();
updateLight();
}
@Override
public void tick() {
public void beginFrame() {
float partialTicks = AnimationTickHolder.getPartialTicks();
double[] cannonAngles = SchematicannonRenderer.getCannonAngles(tile, pos, partialTicks);

View file

@ -0,0 +1,8 @@
package com.simibubi.create.foundation.render.backend.instancing;
public interface IDynamicInstance {
/**
* Called every frame, this can be used to make more dynamic animations.
*/
void beginFrame();
}

View file

@ -1,8 +1,6 @@
package com.simibubi.create.foundation.render.backend.instancing;
public interface ITickableInstance {
/**
* Called every frame, this can be used to make more dynamic animations.
*/
void tick();
}

View file

@ -4,7 +4,6 @@ import java.util.*;
import javax.annotation.Nullable;
import com.simibubi.create.foundation.ponder.PonderWorld;
import com.simibubi.create.foundation.render.backend.Backend;
import com.simibubi.create.foundation.render.backend.RenderMaterials;
import com.simibubi.create.foundation.render.backend.gl.BasicProgram;
@ -26,6 +25,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
protected Map<TileEntity, TileEntityInstance<?>> instances = new HashMap<>();
protected Map<TileEntity, ITickableInstance> tickableInstances = new HashMap<>();
protected Map<TileEntity, IDynamicInstance> dynamicInstances = new HashMap<>();
protected Map<MaterialType<?>, RenderMaterial<P, ?>> materials = new HashMap<>();
@ -45,12 +45,18 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
if (ticks % 10 == 0) {
clean();
}
if (tickableInstances.size() > 0)
tickableInstances.values().forEach(ITickableInstance::tick);
}
public void beginFrame(double cameraX, double cameraY, double cameraZ) {
if (queuedAdditions.size() > 0) {
queuedAdditions.forEach(this::add);
queuedAdditions.clear();
tickableInstances.values().forEach(ITickableInstance::tick);
}
if (dynamicInstances.size() > 0)
dynamicInstances.values().forEach(IDynamicInstance::beginFrame);
}
public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) {
@ -93,8 +99,11 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
if (renderer != null) {
instances.put(tile, renderer);
if (renderer instanceof IDynamicInstance)
dynamicInstances.put(tile, (IDynamicInstance) renderer);
if (renderer instanceof ITickableInstance)
tickableInstances.put(tile, (ITickableInstance) renderer);
tickableInstances.put(tile, ((ITickableInstance) renderer));
}
return renderer;
@ -148,6 +157,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
if (instance != null) {
instance.remove();
instances.remove(tile);
dynamicInstances.remove(tile);
tickableInstances.remove(tile);
}
}
@ -162,7 +172,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
material.delete();
}
instances.clear();
tickableInstances.clear();
dynamicInstances.clear();
}
public boolean canCreateInstance(TileEntity tile) {

View file

@ -1,7 +1,6 @@
package com.simibubi.create.foundation.render.backend.instancing;
import com.simibubi.create.foundation.render.backend.instancing.impl.IFlatLight;
import com.simibubi.create.foundation.render.backend.instancing.impl.ModelData;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -17,24 +16,24 @@ public abstract class TileEntityInstance<T extends TileEntity> {
protected final T tile;
protected final World world;
protected final BlockPos pos;
protected BlockState lastState;
protected BlockState blockState;
public TileEntityInstance(InstancedTileRenderer<?> modelManager, T tile) {
this.modelManager = modelManager;
this.tile = tile;
this.world = tile.getWorld();
this.pos = tile.getPos();
this.lastState = tile.getBlockState();
this.blockState = tile.getBlockState();
init();
}
public final void update() {
BlockState currentState = tile.getBlockState();
if (lastState == currentState) {
if (blockState == currentState) {
onUpdate();
} else {
remove();
lastState = currentState;
blockState = currentState;
init();
}
}

View file

@ -3,6 +3,7 @@ package com.simibubi.create.foundation.tileEntity.renderer;
import com.mojang.blaze3d.matrix.MatrixStack;
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;
@ -21,8 +22,10 @@ public abstract class ColoredOverlayTileEntityRenderer<T extends TileEntity> ext
@Override
protected void renderSafe(T te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
int light, int overlay) {
SuperByteBuffer render = render(te.getWorld(), te.getPos(), te.getBlockState(), getOverlayBuffer(te),
getColor(te, partialTicks));
if (FastRenderDispatcher.available(te.getWorld())) return;
SuperByteBuffer render = render(getOverlayBuffer(te), getColor(te, partialTicks), light);
render.renderInto(ms, buffer.getBuffer(RenderType.getSolid()));
}
@ -30,10 +33,8 @@ public abstract class ColoredOverlayTileEntityRenderer<T extends TileEntity> ext
protected abstract SuperByteBuffer getOverlayBuffer(T te);
public static SuperByteBuffer render(World world, BlockPos pos, BlockState state, SuperByteBuffer buffer,
int color) {
int packedLightmapCoords = WorldRenderer.getLightmapCoordinates(world, state, pos);
return buffer.color(color).light(packedLightmapCoords);
public static SuperByteBuffer render(SuperByteBuffer buffer, int color, int light) {
return buffer.color(color).light(light);
}
}