mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 23:47:38 +01:00
Instanced pulleys first pass
This commit is contained in:
parent
6c942be7f5
commit
5abc1e0fe7
24 changed files with 512 additions and 76 deletions
|
@ -16,10 +16,10 @@ import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.A
|
|||
import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock.HeatLevel;
|
||||
import com.simibubi.create.content.contraptions.relays.belt.BeltData;
|
||||
import com.simibubi.create.foundation.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.render.backend.MaterialTypes;
|
||||
import com.simibubi.create.foundation.render.backend.MaterialType;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
|
||||
import com.simibubi.create.foundation.render.backend.core.ModelData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.foundation.utility.Lang;
|
||||
|
@ -237,20 +237,7 @@ public class AllBlockPartials {
|
|||
return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms);
|
||||
}
|
||||
|
||||
public InstancedModel<RotatingData> renderOnRotating(InstancedTileRenderer<?> ctx, BlockState referenceState) {
|
||||
return ctx.getMaterial(KineticRenderMaterials.ROTATING).getModel(this, referenceState);
|
||||
}
|
||||
|
||||
public InstancedModel<BeltData> renderOnBelt(InstancedTileRenderer<?> ctx, BlockState referenceState) {
|
||||
return ctx.getMaterial(KineticRenderMaterials.BELTS).getModel(this, referenceState);
|
||||
}
|
||||
|
||||
public InstancedModel<RotatingData> renderOnDirectionalSouthRotating(InstancedTileRenderer<?> dispatcher, BlockState referenceState) {
|
||||
Direction facing = referenceState.get(FACING);
|
||||
return renderOnDirectionalSouthRotating(dispatcher, referenceState, facing);
|
||||
}
|
||||
|
||||
public InstancedModel<RotatingData> renderOnDirectionalSouthRotating(InstancedTileRenderer<?> dispatcher, BlockState referenceState, Direction facing) {
|
||||
public <M extends InstancedModel<?>> M getModel(RenderMaterial<?, M> mat, BlockState referenceState, Direction facing) {
|
||||
Supplier<MatrixStack> ms = () -> {
|
||||
MatrixStack stack = new MatrixStack();
|
||||
MatrixStacker.of(stack)
|
||||
|
@ -260,25 +247,7 @@ public class AllBlockPartials {
|
|||
.unCentre();
|
||||
return stack;
|
||||
};
|
||||
return dispatcher.getMaterial(KineticRenderMaterials.ROTATING).getModel(this, referenceState, facing, ms);
|
||||
}
|
||||
|
||||
public InstancedModel<ModelData> renderOnHorizontalModel(InstancedTileRenderer<?> dispatcher, BlockState referenceState) {
|
||||
Direction facing = referenceState.get(HORIZONTAL_FACING);
|
||||
return renderOnDirectionalSouthModel(dispatcher, referenceState, facing);
|
||||
}
|
||||
|
||||
public InstancedModel<ModelData> renderOnDirectionalSouthModel(InstancedTileRenderer<?> dispatcher, BlockState referenceState, Direction facing) {
|
||||
Supplier<MatrixStack> ms = () -> {
|
||||
MatrixStack stack = new MatrixStack();
|
||||
MatrixStacker.of(stack)
|
||||
.centre()
|
||||
.rotateY(AngleHelper.horizontalAngle(facing))
|
||||
.rotateX(AngleHelper.verticalAngle(facing))
|
||||
.unCentre();
|
||||
return stack;
|
||||
};
|
||||
return dispatcher.getMaterial(MaterialTypes.TRANSFORMED).getModel(this, referenceState, facing, ms);
|
||||
return mat.getModel(this, referenceState, facing, ms);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.gan
|
|||
import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonTileEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyInstance;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.pulley.PulleyTileEntity;
|
||||
import com.simibubi.create.content.contraptions.components.turntable.TurntableTileEntity;
|
||||
|
@ -398,7 +399,7 @@ public class AllTileEntities {
|
|||
|
||||
public static final TileEntityEntry<PulleyTileEntity> ROPE_PULLEY = Create.registrate()
|
||||
.tileEntity("rope_pulley", PulleyTileEntity::new)
|
||||
.instance(() -> ShaftInstance::new)
|
||||
.instance(() -> PulleyInstance::new)
|
||||
.validBlocks(AllBlocks.ROPE_PULLEY)
|
||||
.renderer(() -> PulleyRenderer::new)
|
||||
.register();
|
||||
|
|
|
@ -15,7 +15,7 @@ public class HalfShaftInstance extends SingleRotatingInstance {
|
|||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
Direction dir = getShaftDirection();
|
||||
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState, dir);
|
||||
return AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), blockState, dir);
|
||||
}
|
||||
|
||||
protected Direction getShaftDirection() {
|
||||
|
|
|
@ -12,6 +12,6 @@ public class ShaftlessCogInstance extends SingleRotatingInstance {
|
|||
|
||||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
return AllBlockPartials.SHAFTLESS_COGWHEEL.renderOnRotating(renderer, tile.getBlockState());
|
||||
}
|
||||
return renderer.getMaterial(KineticRenderMaterials.ROTATING).getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, tile.getBlockState());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package com.simibubi.create.content.contraptions.components.actors;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
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.*;
|
||||
|
||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
public class DrillInstance extends SingleRotatingInstance {
|
||||
|
||||
public DrillInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||
|
@ -14,6 +19,7 @@ public class DrillInstance extends SingleRotatingInstance {
|
|||
|
||||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
return AllBlockPartials.DRILL_HEAD.renderOnDirectionalSouthRotating(renderer, tile.getBlockState());
|
||||
}
|
||||
BlockState referenceState = tile.getBlockState();
|
||||
return AllBlockPartials.DRILL_HEAD.getModel(getRotatingMaterial(), referenceState, referenceState.get(FACING));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.crank;
|
|||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
|
||||
import com.simibubi.create.foundation.render.backend.MaterialTypes;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.*;
|
||||
import com.simibubi.create.foundation.render.backend.core.ModelData;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
|
@ -29,7 +30,7 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami
|
|||
return;
|
||||
|
||||
facing = blockState.get(BlockStateProperties.FACING);
|
||||
InstancedModel<ModelData> model = renderedHandle.renderOnDirectionalSouthModel(modelManager, blockState, facing.getOpposite());
|
||||
InstancedModel<ModelData> model = renderedHandle.getModel(getTransformMaterial(), blockState, facing.getOpposite());
|
||||
crank = model.createInstance();
|
||||
|
||||
rotateCrank();
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.fan;
|
|||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||
import com.simibubi.create.content.contraptions.base.RotatingData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
|
||||
|
@ -16,14 +17,16 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
|||
protected final RotatingData shaft;
|
||||
protected final RotatingData fan;
|
||||
final Direction direction;
|
||||
private final Direction opposite;
|
||||
|
||||
public FanInstance(InstancedTileRenderer<?> modelManager, EncasedFanTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
|
||||
direction = blockState.get(FACING);
|
||||
|
||||
shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
|
||||
fan = AllBlockPartials.ENCASED_FAN_INNER.renderOnDirectionalSouthRotating(modelManager, blockState, direction.getOpposite()).createInstance();
|
||||
opposite = direction.getOpposite();
|
||||
shaft = AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), blockState, opposite).createInstance();
|
||||
fan = AllBlockPartials.ENCASED_FAN_INNER.getModel(getRotatingMaterial(), blockState, opposite).createInstance();
|
||||
|
||||
setup(shaft);
|
||||
setup(fan, getFanSpeed());
|
||||
|
@ -46,7 +49,7 @@ public class FanInstance extends KineticTileInstance<EncasedFanTileEntity> {
|
|||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
BlockPos behind = pos.offset(direction.getOpposite());
|
||||
BlockPos behind = pos.offset(opposite);
|
||||
relight(behind, shaft);
|
||||
|
||||
BlockPos inFront = pos.offset(direction);
|
||||
|
|
|
@ -6,19 +6,25 @@ import java.util.List;
|
|||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||
import com.simibubi.create.content.contraptions.base.RotatingData;
|
||||
import com.simibubi.create.foundation.render.backend.MaterialTypes;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.*;
|
||||
|
||||
import com.simibubi.create.foundation.render.backend.core.ModelData;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
import com.simibubi.create.foundation.utility.MatrixStacker;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING;
|
||||
|
||||
public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> implements IDynamicInstance {
|
||||
|
||||
protected final Direction facing;
|
||||
|
@ -42,11 +48,12 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
|||
public FlyWheelInstance(InstancedTileRenderer<?> modelManager, FlywheelTileEntity tile) {
|
||||
super(modelManager, tile);
|
||||
|
||||
facing = blockState.get(BlockStateProperties.HORIZONTAL_FACING);
|
||||
facing = blockState.get(HORIZONTAL_FACING);
|
||||
|
||||
shaft = setup(shaftModel().createInstance());
|
||||
|
||||
wheel = AllBlockPartials.FLYWHEEL.renderOnHorizontalModel(modelManager, blockState.rotate(Rotation.CLOCKWISE_90)).createInstance();
|
||||
BlockState referenceState = blockState.rotate(Rotation.CLOCKWISE_90);
|
||||
wheel = AllBlockPartials.FLYWHEEL.getModel(getTransformMaterial(), referenceState, referenceState.get(HORIZONTAL_FACING)).createInstance();
|
||||
|
||||
connection = FlywheelBlock.getConnection(blockState);
|
||||
if (connection != null) {
|
||||
|
@ -152,7 +159,7 @@ public class FlyWheelInstance extends KineticTileInstance<FlywheelTileEntity> im
|
|||
}
|
||||
|
||||
protected InstancedModel<RotatingData> shaftModel() {
|
||||
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState, facing.getOpposite());
|
||||
return AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), blockState, facing.getOpposite());
|
||||
}
|
||||
|
||||
protected void transformConnector(MatrixStacker ms, boolean upper, boolean rotating, float angle, boolean flip) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simibubi.create.content.contraptions.components.millstone;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.base.RotatingData;
|
||||
import com.simibubi.create.content.contraptions.base.SingleRotatingInstance;
|
||||
|
@ -15,6 +16,6 @@ public class MillStoneCogInstance extends SingleRotatingInstance {
|
|||
|
||||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
return AllBlockPartials.MILLSTONE_COG.renderOnRotating(renderer, tile.getBlockState());
|
||||
return getRotatingMaterial().getModel(AllBlockPartials.MILLSTONE_COG, tile.getBlockState());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,14 @@ package com.simibubi.create.content.contraptions.components.saw;
|
|||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
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.InstancedTileRenderer;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.Rotation;
|
||||
|
||||
public class SawInstance extends SingleRotatingInstance {
|
||||
|
@ -19,9 +21,11 @@ public class SawInstance extends SingleRotatingInstance {
|
|||
|
||||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
if (blockState.get(FACING).getAxis().isHorizontal())
|
||||
return AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(renderer, blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180));
|
||||
else
|
||||
return getRotatingMaterial().getModel(shaft());
|
||||
if (blockState.get(FACING).getAxis().isHorizontal()) {
|
||||
BlockState referenceState = blockState.rotate(tile.getWorld(), tile.getPos(), Rotation.CLOCKWISE_180);
|
||||
return AllBlockPartials.SHAFT_HALF.getModel(getRotatingMaterial(), referenceState, referenceState.get(FACING));
|
||||
} else {
|
||||
return getRotatingMaterial().getModel(shaft());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.base.IRotate;
|
|||
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 com.simibubi.create.foundation.utility.AngleHelper;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -41,6 +42,9 @@ public abstract class AbstractPulleyRenderer extends KineticTileEntityRenderer {
|
|||
@Override
|
||||
protected void renderSafe(KineticTileEntity te, float partialTicks, MatrixStack ms, IRenderTypeBuffer buffer,
|
||||
int light, int overlay) {
|
||||
|
||||
if (FastRenderDispatcher.available(te.getWorld())) return;
|
||||
|
||||
super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
|
||||
float offset = getOffset(te, partialTicks);
|
||||
boolean running = isRunning(te);
|
||||
|
|
|
@ -0,0 +1,209 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.pulley;
|
||||
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.ILightReader;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance;
|
||||
import com.simibubi.create.foundation.render.backend.core.OrientedData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.*;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.util.ConditionalInstance;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.util.InstanceGroup;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.util.SelectInstance;
|
||||
import com.simibubi.create.foundation.render.backend.light.GridAlignedBB;
|
||||
import com.simibubi.create.foundation.render.backend.light.LightUpdateListener;
|
||||
import com.simibubi.create.foundation.render.backend.light.LightUpdater;
|
||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||
|
||||
public class PulleyInstance extends ShaftInstance implements IDynamicInstance, LightUpdateListener {
|
||||
|
||||
final PulleyTileEntity tile = (PulleyTileEntity) super.tile;
|
||||
final OrientedData coil;
|
||||
final SelectInstance<OrientedData> magnet;
|
||||
final InstanceGroup<OrientedData> rope;
|
||||
final ConditionalInstance<OrientedData> halfRope;
|
||||
|
||||
private float offset;
|
||||
private final Direction rotatingAbout;
|
||||
private final Vector3f rotationAxis;
|
||||
|
||||
private byte[] bLight = new byte[1];
|
||||
private byte[] sLight = new byte[1];
|
||||
private GridAlignedBB volume;
|
||||
|
||||
public PulleyInstance(InstancedTileRenderer<?> dispatcher, PulleyTileEntity tile) {
|
||||
super(dispatcher, tile);
|
||||
|
||||
rotatingAbout = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis);
|
||||
rotationAxis = rotatingAbout.getUnitVector();
|
||||
updateOffset();
|
||||
|
||||
coil = getCoilModel()
|
||||
.createInstance()
|
||||
.setPosition(getInstancePosition());
|
||||
|
||||
magnet = new SelectInstance<>(this::getMagnetModelIndex);
|
||||
magnet.addModel(getMagnetModel())
|
||||
.addModel(getHalfMagnetModel());
|
||||
|
||||
rope = new InstanceGroup<>(getRopeModel());
|
||||
resizeRope();
|
||||
|
||||
halfRope = new ConditionalInstance<>(getHalfRopeModel(), this::shouldRenderHalfRope);
|
||||
|
||||
beginFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginFrame() {
|
||||
updateOffset();
|
||||
|
||||
coil.setRotation(rotationAxis.getDegreesQuaternion(offset * 180));
|
||||
magnet.update().get().ifPresent(data ->
|
||||
data.setPosition(getInstancePosition())
|
||||
.nudge(0, -offset, 0)
|
||||
.setBlockLight(bLight[bLight.length - 1])
|
||||
.setSkyLight(sLight[sLight.length - 1])
|
||||
);
|
||||
|
||||
halfRope.check().get().ifPresent(rope -> {
|
||||
float f = offset % 1;
|
||||
float halfRopeNudge = f > .75f ? f - 1 : f;
|
||||
|
||||
rope.setPosition(getInstancePosition())
|
||||
.nudge(0, -halfRopeNudge, 0)
|
||||
.setBlockLight(bLight[0])
|
||||
.setSkyLight(sLight[0]);
|
||||
});
|
||||
|
||||
if (isRunning()) {
|
||||
resizeRope();
|
||||
int size = rope.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
rope.get(i)
|
||||
.setPosition(getInstancePosition())
|
||||
.nudge(0, -offset + i + 1, 0)
|
||||
.setBlockLight(bLight[size - i])
|
||||
.setSkyLight(sLight[size - i]);
|
||||
}
|
||||
} else {
|
||||
rope.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLight() {
|
||||
super.updateLight();
|
||||
relight(pos, coil);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
coil.delete();
|
||||
magnet.delete();
|
||||
rope.clear();
|
||||
halfRope.delete();
|
||||
}
|
||||
|
||||
protected InstancedModel<OrientedData> getRopeModel() {
|
||||
return getOrientedMaterial().getModel(AllBlocks.ROPE.getDefaultState());
|
||||
}
|
||||
|
||||
protected InstancedModel<OrientedData> getMagnetModel() {
|
||||
return getOrientedMaterial().getModel(AllBlocks.PULLEY_MAGNET.getDefaultState());
|
||||
}
|
||||
|
||||
protected InstancedModel<OrientedData> getHalfMagnetModel() {
|
||||
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF_MAGNET, blockState);
|
||||
}
|
||||
|
||||
protected InstancedModel<OrientedData> getCoilModel() {
|
||||
return AllBlockPartials.ROPE_COIL.getModel(getOrientedMaterial(), blockState, rotatingAbout);
|
||||
}
|
||||
|
||||
protected InstancedModel<OrientedData> getHalfRopeModel() {
|
||||
return getOrientedMaterial().getModel(AllBlockPartials.ROPE_HALF, blockState);
|
||||
}
|
||||
|
||||
protected float getOffset() {
|
||||
float partialTicks = AnimationTickHolder.getPartialTicks();
|
||||
return PulleyRenderer.getTileOffset(partialTicks, tile);
|
||||
}
|
||||
|
||||
protected boolean isRunning() {
|
||||
return tile.running || tile.isVirtual();
|
||||
}
|
||||
|
||||
protected void resizeRope() {
|
||||
if (rope.resize(getNeededRopeCount())) {
|
||||
|
||||
int length = MathHelper.ceil(offset);
|
||||
volume = GridAlignedBB.from(pos.down(length), pos);
|
||||
volume.fixMinMax();
|
||||
|
||||
bLight = Arrays.copyOf(bLight, length + 1);
|
||||
sLight = Arrays.copyOf(sLight, length + 1);
|
||||
|
||||
initLight(world, volume);
|
||||
|
||||
LightUpdater.getInstance().startListening(volume, this);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateOffset() {
|
||||
offset = getOffset();
|
||||
}
|
||||
|
||||
private int getNeededRopeCount() {
|
||||
return Math.max(0, MathHelper.ceil(offset - 1.25f));
|
||||
}
|
||||
|
||||
private boolean shouldRenderHalfRope() {
|
||||
float f = offset % 1;
|
||||
return offset > .75f && (f < .25f || f > .75f);
|
||||
}
|
||||
|
||||
private int getMagnetModelIndex() {
|
||||
if (isRunning() || offset == 0) {
|
||||
return offset > .25f ? 0 : 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decreaseFramerateWithDistance() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLightUpdate(ILightReader world, LightType type, GridAlignedBB changed) {
|
||||
changed.intersectAssign(volume);
|
||||
|
||||
initLight(world, changed);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initLight(ILightReader world, GridAlignedBB changed) {
|
||||
int top = this.pos.getY();
|
||||
BlockPos.Mutable pos = new BlockPos.Mutable();
|
||||
changed.forEachContained((x, y, z) -> {
|
||||
pos.setPos(x, y, z);
|
||||
byte block = (byte) world.getLightLevel(LightType.BLOCK, pos);
|
||||
byte sky = (byte) world.getLightLevel(LightType.SKY, pos);
|
||||
|
||||
int i = top - y;
|
||||
|
||||
bLight[i] = block;
|
||||
sLight[i] = sky;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -41,16 +41,7 @@ public class PulleyRenderer extends AbstractPulleyRenderer {
|
|||
@Override
|
||||
protected float getOffset(KineticTileEntity te, float partialTicks) {
|
||||
PulleyTileEntity pulley = (PulleyTileEntity) te;
|
||||
float offset = pulley.getInterpolatedOffset(partialTicks);
|
||||
|
||||
if (pulley.movedContraption != null) {
|
||||
AbstractContraptionEntity e = pulley.movedContraption;
|
||||
PulleyContraption c = (PulleyContraption) pulley.movedContraption.getContraption();
|
||||
double entityPos = MathHelper.lerp(partialTicks, e.lastTickPosY, e.getY());
|
||||
offset = (float) -(entityPos - c.anchor.getY() - c.initialOffset);
|
||||
}
|
||||
|
||||
return offset;
|
||||
return getTileOffset(partialTicks, pulley);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,4 +49,17 @@ public class PulleyRenderer extends AbstractPulleyRenderer {
|
|||
return ((PulleyTileEntity) te).running || te.isVirtual();
|
||||
}
|
||||
|
||||
|
||||
static float getTileOffset(float partialTicks, PulleyTileEntity tile) {
|
||||
float offset = tile.getInterpolatedOffset(partialTicks);
|
||||
|
||||
if (tile.movedContraption != null) {
|
||||
AbstractContraptionEntity e = tile.movedContraption;
|
||||
PulleyContraption c = (PulleyContraption) tile.movedContraption.getContraption();
|
||||
double entityPos = MathHelper.lerp(partialTicks, e.lastTickPosY, e.getY());
|
||||
offset = (float) -(entityPos - c.anchor.getY() - c.initialOffset);
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,6 +241,6 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
|
|||
|
||||
@Override
|
||||
public boolean shouldRenderAsTE() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package com.simibubi.create.content.contraptions.fluids;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
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.InstancedTileRenderer;
|
||||
|
||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
public class PumpCogInstance extends SingleRotatingInstance {
|
||||
|
||||
public PumpCogInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
|
||||
|
@ -15,6 +20,7 @@ public class PumpCogInstance extends SingleRotatingInstance {
|
|||
|
||||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
return AllBlockPartials.MECHANICAL_PUMP_COG.renderOnDirectionalSouthRotating(renderer, tile.getBlockState());
|
||||
BlockState referenceState = tile.getBlockState();
|
||||
return AllBlockPartials.MECHANICAL_PUMP_COG.getModel(getRotatingMaterial(), referenceState, referenceState.get(FACING));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ 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.KineticRenderMaterials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||
import com.simibubi.create.content.contraptions.base.RotatingData;
|
||||
import com.simibubi.create.foundation.block.render.SpriteShiftEntry;
|
||||
|
@ -59,7 +60,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, blockState);
|
||||
InstancedModel<BeltData> beltModel = modelManager.getMaterial(KineticRenderMaterials.BELTS).getModel(beltPartial, blockState);
|
||||
|
||||
keys.add(setup(beltModel.createInstance(), bottom, spriteShift));
|
||||
|
||||
|
|
|
@ -4,11 +4,13 @@ import java.util.ArrayList;
|
|||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||
import com.simibubi.create.content.contraptions.base.RotatingData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -25,9 +27,11 @@ public class SplitShaftInstance extends KineticTileInstance<SplitShaftTileEntity
|
|||
|
||||
float speed = tile.getSpeed();
|
||||
|
||||
RenderMaterial<?, InstancedModel<RotatingData>> rotatingMaterial = getRotatingMaterial();
|
||||
|
||||
for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) {
|
||||
|
||||
InstancedModel<RotatingData> half = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, dir);
|
||||
InstancedModel<RotatingData> half = AllBlockPartials.SHAFT_HALF.getModel(rotatingMaterial, blockState, dir);
|
||||
|
||||
float splitSpeed = speed * tile.getRotationSpeedModifier(dir);
|
||||
|
||||
|
|
|
@ -4,11 +4,13 @@ import java.util.EnumMap;
|
|||
import java.util.Map;
|
||||
|
||||
import com.simibubi.create.AllBlockPartials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticRenderMaterials;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||
import com.simibubi.create.content.contraptions.base.RotatingData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedTileRenderer;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.RenderMaterial;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
|
@ -32,12 +34,14 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
|||
int skyLight = world.getLightLevel(LightType.SKY, pos);
|
||||
updateSourceFacing();
|
||||
|
||||
RenderMaterial<?, InstancedModel<RotatingData>> rotatingMaterial = getRotatingMaterial();
|
||||
|
||||
for (Direction direction : Iterate.directions) {
|
||||
final Direction.Axis axis = direction.getAxis();
|
||||
if (boxAxis == axis)
|
||||
continue;
|
||||
|
||||
InstancedModel<RotatingData> shaft = AllBlockPartials.SHAFT_HALF.renderOnDirectionalSouthRotating(modelManager, blockState, direction);
|
||||
InstancedModel<RotatingData> shaft = AllBlockPartials.SHAFT_HALF.getModel(rotatingMaterial, blockState, direction);
|
||||
|
||||
RotatingData key = shaft.createInstance();
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta
|
|||
|
||||
@Override
|
||||
protected InstancedModel<RotatingData> getModel() {
|
||||
return AllBlockPartials.ARM_COG.renderOnRotating(renderer, tile.getBlockState());
|
||||
return getRotatingMaterial().getModel(AllBlockPartials.ARM_COG, tile.getBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package com.simibubi.create.foundation;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class OptionalUtil {
|
||||
|
||||
public static <T> Optional<T> thenTry(Optional<T> first, Optional<T> thenTry) {
|
||||
if (first.isPresent()) {
|
||||
return first;
|
||||
} else {
|
||||
return thenTry;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Optional<T> thenTryLazy(Supplier<Optional<T>> first, Supplier<Optional<T>> thenTry) {
|
||||
Optional<T> one = first.get();
|
||||
if (one.isPresent()) {
|
||||
return one;
|
||||
} else {
|
||||
return thenTry.get();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -85,13 +85,7 @@ public class RenderMaterial<P extends BasicProgram, MODEL extends InstancedModel
|
|||
}
|
||||
|
||||
protected void makeRenderCalls() {
|
||||
for (Cache<Object, MODEL> cache : models.values()) {
|
||||
for (MODEL model : cache.asMap().values()) {
|
||||
if (!model.isEmpty()) {
|
||||
model.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
runOnAll(InstancedModel::render);
|
||||
}
|
||||
|
||||
public void runOnAll(Consumer<MODEL> f) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.simibubi.create.foundation.render.backend.instancing.util;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||
|
||||
public class ConditionalInstance<D extends InstanceData> {
|
||||
|
||||
final InstancedModel<D> model;
|
||||
Condition condition;
|
||||
|
||||
@Nullable
|
||||
private D instance;
|
||||
|
||||
public ConditionalInstance(InstancedModel<D> model, Condition condition) {
|
||||
this.model = model;
|
||||
this.condition = condition;
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
public ConditionalInstance<D> setCondition(Condition condition) {
|
||||
this.condition = condition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConditionalInstance<D> check() {
|
||||
boolean shouldShow = condition.shouldShow();
|
||||
if (shouldShow && instance == null) {
|
||||
instance = model.createInstance();
|
||||
} else if (!shouldShow && instance != null) {
|
||||
instance.delete();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Optional<D> get() {
|
||||
return Optional.ofNullable(instance);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (instance != null) instance.delete();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Condition {
|
||||
boolean shouldShow();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.simibubi.create.foundation.render.backend.instancing.util;
|
||||
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import java.util.*;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||
|
||||
public class InstanceGroup<D extends InstanceData> extends AbstractCollection<D> {
|
||||
|
||||
final InstancedModel<D> model;
|
||||
final List<D> backing;
|
||||
|
||||
public InstanceGroup(InstancedModel<D> model) {
|
||||
this.model = model;
|
||||
|
||||
this.backing = new ArrayList<>();
|
||||
}
|
||||
|
||||
public InstanceGroup(InstancedModel<D> model, int size) {
|
||||
this.model = model;
|
||||
|
||||
this.backing = new ArrayList<>(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
addInstance();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param count
|
||||
* @return True if the number of elements changed.
|
||||
*/
|
||||
public boolean resize(int count) {
|
||||
int size = size();
|
||||
if (count == size) return false;
|
||||
|
||||
if (count <= 0) {
|
||||
clear();
|
||||
return size > 0;
|
||||
}
|
||||
|
||||
if (count > size) {
|
||||
for (int i = size; i < count; i++) {
|
||||
addInstance();
|
||||
}
|
||||
} else {
|
||||
List<D> unnecessary = backing.subList(count, size);
|
||||
unnecessary.forEach(InstanceData::delete);
|
||||
unnecessary.clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public InstanceData addInstance() {
|
||||
D instance = model.createInstance();
|
||||
backing.add(instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public D get(int index) {
|
||||
return backing.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<D> iterator() {
|
||||
return backing.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return backing.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
backing.forEach(InstanceData::delete);
|
||||
backing.clear();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package com.simibubi.create.foundation.render.backend.instancing.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstanceData;
|
||||
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
|
||||
|
||||
public class SelectInstance<D extends InstanceData> {
|
||||
|
||||
final List<InstancedModel<D>> models;
|
||||
|
||||
ModelSelector selector;
|
||||
|
||||
private int last = -1;
|
||||
@Nullable
|
||||
private D current;
|
||||
|
||||
public SelectInstance(ModelSelector selector) {
|
||||
this.models = new ArrayList<>();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
public SelectInstance<D> addModel(InstancedModel<D> model) {
|
||||
models.add(model);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SelectInstance<D> update() {
|
||||
int i = selector.modelIndexToShow();
|
||||
|
||||
if (i < 0 || i >= models.size()) {
|
||||
if (current != null) {
|
||||
current.delete();
|
||||
current = null;
|
||||
}
|
||||
} else if (i != last) {
|
||||
if (current != null) current.delete();
|
||||
|
||||
current = models.get(i).createInstance();
|
||||
}
|
||||
|
||||
last = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Optional<D> get() {
|
||||
return Optional.ofNullable(current);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (current != null) current.delete();
|
||||
}
|
||||
|
||||
public interface ModelSelector {
|
||||
int modelIndexToShow();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue