Unbotch the batch

- Contraptions now render properly with batching
 - Belts can be placed sideways again
This commit is contained in:
Jozufozu 2022-06-13 12:31:41 -07:00
parent 3517f04a70
commit fa51b68709
12 changed files with 91 additions and 63 deletions

View file

@ -9,6 +9,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices;
import com.simibubi.create.content.contraptions.components.structureMovement.render.FlwContraption;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.renderer.MultiBufferSource;
@ -38,7 +39,7 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour {
@OnlyIn(value = Dist.CLIENT)
public void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffer) {
if (!Backend.isOn())
if (!FlwContraption.canInstance())
DrillRenderer.renderInContraption(context, renderWorld, matrices, buffer);
}

View file

@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices;
import com.simibubi.create.content.contraptions.components.structureMovement.render.FlwContraption;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.BlockHelper;
import com.simibubi.create.foundation.utility.VecHelper;
@ -58,7 +59,7 @@ public class HarvesterMovementBehaviour implements MovementBehaviour {
@Override
public void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffers) {
if (!Backend.isOn())
if (!FlwContraption.canInstance())
HarvesterRenderer.renderInContraption(context, renderWorld, matrices, buffers);
}

View file

@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov
import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices;
import com.simibubi.create.content.contraptions.components.structureMovement.render.FlwContraption;
import com.simibubi.create.content.logistics.trains.entity.CarriageContraption;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
@ -55,7 +56,7 @@ public class PortableStorageInterfaceMovement implements MovementBehaviour {
@OnlyIn(Dist.CLIENT)
public void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffer) {
if (!Backend.isOn())
if (!FlwContraption.canInstance())
PortableStorageInterfaceRenderer.renderInContraption(context, renderWorld, matrices, buffer);
}

View file

@ -20,6 +20,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Mov
import com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices;
import com.simibubi.create.content.contraptions.components.structureMovement.render.FlwContraption;
import com.simibubi.create.content.logistics.item.filter.FilterItem;
import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntity;
import com.simibubi.create.content.schematics.ItemRequirement;
@ -290,7 +291,7 @@ public class DeployerMovementBehaviour implements MovementBehaviour {
@Override
public void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffers) {
if (!Backend.isOn())
if (!FlwContraption.canInstance())
DeployerRenderer.renderInContraption(context, renderWorld, matrices, buffers);
}

View file

@ -849,7 +849,9 @@ public abstract class Contraption {
this.blocks.put(info.pos, info);
if (world.isClientSide) {
if (!world.isClientSide)
return;
Block block = info.state.getBlock();
CompoundTag tag = info.nbt;
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block);
@ -876,8 +878,6 @@ public abstract class Contraption {
presentTileEntities.put(info.pos, te);
specialRenderedTileEntities.add(te);
}
});
}

View file

@ -16,6 +16,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Ori
import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices;
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
import com.simibubi.create.content.contraptions.components.structureMovement.render.FlwContraption;
import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -34,7 +35,7 @@ public class StabilizedBearingMovementBehaviour implements MovementBehaviour {
@OnlyIn(Dist.CLIENT)
public void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld,
ContraptionMatrices matrices, MultiBufferSource buffer) {
if (Backend.isOn())
if (FlwContraption.canInstance())
return;
Direction facing = context.state.getValue(BlockStateProperties.FACING);

View file

@ -6,6 +6,7 @@ import org.apache.commons.lang3.tuple.Pair;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.error.GlError;
import com.jozufozu.flywheel.config.BackendType;
import com.jozufozu.flywheel.core.model.ModelUtil;
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
import com.jozufozu.flywheel.event.BeginFrameEvent;
@ -119,7 +120,12 @@ public class ContraptionRenderDispatcher {
BlockPos origin = c.anchor;
int height = contraptionWorld.getHeight();
int minBuildHeight = contraptionWorld.getMinBuildHeight();
VirtualRenderWorld renderWorld = new VirtualRenderWorld(world, origin, height, minBuildHeight);
VirtualRenderWorld renderWorld = new VirtualRenderWorld(world, origin, height, minBuildHeight) {
@Override
public boolean supportsFlywheel() {
return Backend.getBackendType() == BackendType.INSTANCING;
}
};
renderWorld.setBlockEntities(c.presentTileEntities.values());
for (StructureTemplate.StructureBlockInfo info : c.getBlocks()

View file

@ -13,6 +13,7 @@ import com.jozufozu.flywheel.backend.instancing.SerialTaskEngine;
import com.jozufozu.flywheel.backend.instancing.batching.BatchingEngine;
import com.jozufozu.flywheel.backend.instancing.instancing.InstancingEngine;
import com.jozufozu.flywheel.backend.model.ArrayModelRenderer;
import com.jozufozu.flywheel.config.BackendType;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.core.model.WorldModel;
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
@ -53,13 +54,17 @@ public class FlwContraption extends ContraptionRenderInfo {
var restoreState = GlStateTracker.getRestoreState();
buildLayers();
if (Backend.isOn()) {
if (canInstance()) {
buildInstancedTiles();
buildActors();
}
restoreState.restore();
}
public static boolean canInstance() {
return Backend.getBackendType() == BackendType.INSTANCING;
}
public ContraptionLighter<?> getLighter() {
return lighter;
}
@ -147,18 +152,17 @@ public class FlwContraption extends ContraptionRenderInfo {
}
private void buildInstancedTiles() {
Collection<BlockEntity> tileEntities = contraption.maybeInstancedTileEntities;
if (!tileEntities.isEmpty()) {
for (BlockEntity te : tileEntities) {
if (InstancedRenderRegistry.canInstance(te.getType())) {
for (BlockEntity te : contraption.maybeInstancedTileEntities) {
if (!InstancedRenderRegistry.canInstance(te.getType())) {
continue;
}
Level world = te.getLevel();
te.setLevel(renderWorld);
instanceWorld.tileInstanceManager.add(te);
te.setLevel(world);
}
}
}
}
private void buildActors() {
contraption.getActors().forEach(instanceWorld.tileInstanceManager::createActor);

View file

@ -43,11 +43,12 @@ public class FlwContraptionManager extends ContraptionRenderingWorld<FlwContrapt
GlStateTracker.State restoreState = GlStateTracker.getRestoreState();
GlTextureUnit active = GlTextureUnit.getActive();
if (Backend.getBackendType() != BackendType.BATCHING) {
var backendType = Backend.getBackendType();
if (backendType != BackendType.OFF) {
renderStructures(event);
}
if (event.getLayer() != null) {
if (backendType != BackendType.BATCHING && event.getLayer() != null) {
for (FlwContraption renderer : visible) {
renderer.renderInstanceLayer(event);
}

View file

@ -143,10 +143,6 @@ public class BeltConnectorItem extends BlockItem {
break;
}
if (!existingBlock.getMaterial()
.isReplaceable())
world.destroyBlock(pos, false);
BeltPart part = pos.equals(start) ? BeltPart.START : pos.equals(end) ? BeltPart.END : BeltPart.MIDDLE;
BlockState shaftState = world.getBlockState(pos);
boolean pulley = ShaftBlock.isShaft(shaftState);
@ -154,6 +150,11 @@ public class BeltConnectorItem extends BlockItem {
part = BeltPart.PULLEY;
if (pulley && shaftState.getValue(AbstractSimpleShaftBlock.AXIS) == Axis.Y)
slope = BeltSlope.SIDEWAYS;
if (!existingBlock.getMaterial()
.isReplaceable())
world.destroyBlock(pos, false);
KineticTileEntity.switchToBlockState(world, pos, beltBlock.setValue(BeltBlock.SLOPE, slope)
.setValue(BeltBlock.PART, part)
.setValue(BeltBlock.HORIZONTAL_FACING, facing));

View file

@ -55,7 +55,7 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
: BlockPos.ZERO.relative(entity.getInitialOrientation()
.getCounterClockWise(), bogeySpacing);
if (!Backend.isOn() && !entity.getContraption()
if (!Backend.canUseInstancing(entity.level) && !entity.getContraption()
.isHiddenInPortal(bogeyPos)) {
ms.pushPose();

View file

@ -6,6 +6,7 @@ import javax.annotation.Nullable;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import com.jozufozu.flywheel.config.BackendType;
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
@ -48,7 +49,7 @@ public class TileEntityRenderHelper {
Iterator<BlockEntity> iterator = customRenderTEs.iterator();
while (iterator.hasNext()) {
BlockEntity tileEntity = iterator.next();
if (Backend.canUseInstancing(renderWorld) && InstancedRenderRegistry.shouldSkipRender(tileEntity))
if (Backend.getBackendType() == BackendType.INSTANCING && Backend.isFlywheelWorld(renderWorld) && InstancedRenderRegistry.shouldSkipRender(tileEntity))
continue;
BlockEntityRenderer<BlockEntity> renderer = Minecraft.getInstance().getBlockEntityRenderDispatcher().getRenderer(tileEntity);
@ -63,16 +64,16 @@ public class TileEntityRenderHelper {
.translate(pos);
try {
BlockPos lightPos;
if (lightTransform != null) {
Vector4f lightVec = new Vector4f(pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, 1);
lightVec.transform(lightTransform);
lightPos = new BlockPos(lightVec.x(), lightVec.y(), lightVec.z());
} else {
lightPos = pos;
}
int worldLight = getCombinedLight(world, lightPos, renderWorld, pos);
int worldLight = getCombinedLight(world, getLightPos(lightTransform, pos), renderWorld, pos);
if (renderWorld != null) {
// Swap the real world for the render world so that the renderer gets contraption-local information
tileEntity.setLevel(renderWorld);
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
tileEntity.setLevel(world);
} else {
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
}
} catch (Exception e) {
iterator.remove();
@ -90,6 +91,16 @@ public class TileEntityRenderHelper {
}
}
private static BlockPos getLightPos(@Nullable Matrix4f lightTransform, BlockPos contraptionPos) {
if (lightTransform != null) {
Vector4f lightVec = new Vector4f(contraptionPos.getX() + .5f, contraptionPos.getY() + .5f, contraptionPos.getZ() + .5f, 1);
lightVec.transform(lightTransform);
return new BlockPos(lightVec.x(), lightVec.y(), lightVec.z());
} else {
return contraptionPos;
}
}
public static int getCombinedLight(Level world, BlockPos worldPos, @Nullable VirtualRenderWorld renderWorld,
BlockPos renderWorldPos) {
int worldLight = LevelRenderer.getLightColor(world, worldPos);