mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-26 06:57:51 +01:00
Unbotch the batch
- Contraptions now render properly with batching - Belts can be placed sideways again
This commit is contained in:
parent
3517f04a70
commit
fa51b68709
12 changed files with 91 additions and 63 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -70,9 +71,9 @@ public class PortableStorageInterfaceMovement implements MovementBehaviour {
|
|||
|
||||
@Override
|
||||
public void tick(MovementContext context) {
|
||||
if (context.world.isClientSide)
|
||||
if (context.world.isClientSide)
|
||||
getAnimation(context).tickChaser();
|
||||
|
||||
|
||||
boolean onCarriage = context.contraption instanceof CarriageContraption;
|
||||
if (onCarriage && context.motion.length() > 1 / 4f)
|
||||
return;
|
||||
|
@ -152,7 +153,7 @@ public class PortableStorageInterfaceMovement implements MovementBehaviour {
|
|||
public void stopMoving(MovementContext context) {
|
||||
// reset(context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cancelStall(MovementContext context) {
|
||||
reset(context);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -849,35 +849,35 @@ public abstract class Contraption {
|
|||
|
||||
this.blocks.put(info.pos, info);
|
||||
|
||||
if (world.isClientSide) {
|
||||
Block block = info.state.getBlock();
|
||||
CompoundTag tag = info.nbt;
|
||||
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block);
|
||||
if (tag == null)
|
||||
return;
|
||||
if (!world.isClientSide)
|
||||
return;
|
||||
|
||||
tag.putInt("x", info.pos.getX());
|
||||
tag.putInt("y", info.pos.getY());
|
||||
tag.putInt("z", info.pos.getZ());
|
||||
Block block = info.state.getBlock();
|
||||
CompoundTag tag = info.nbt;
|
||||
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(block);
|
||||
if (tag == null)
|
||||
return;
|
||||
|
||||
BlockEntity te = BlockEntity.loadStatic(info.pos, info.state, tag);
|
||||
if (te == null)
|
||||
return;
|
||||
te.setLevel(world);
|
||||
if (te instanceof KineticTileEntity)
|
||||
((KineticTileEntity) te).setSpeed(0);
|
||||
te.getBlockState();
|
||||
tag.putInt("x", info.pos.getX());
|
||||
tag.putInt("y", info.pos.getY());
|
||||
tag.putInt("z", info.pos.getZ());
|
||||
|
||||
if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering())
|
||||
maybeInstancedTileEntities.add(te);
|
||||
BlockEntity te = BlockEntity.loadStatic(info.pos, info.state, tag);
|
||||
if (te == null)
|
||||
return;
|
||||
te.setLevel(world);
|
||||
if (te instanceof KineticTileEntity)
|
||||
((KineticTileEntity) te).setSpeed(0);
|
||||
te.getBlockState();
|
||||
|
||||
if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity())
|
||||
return;
|
||||
if (movementBehaviour == null || !movementBehaviour.hasSpecialInstancedRendering())
|
||||
maybeInstancedTileEntities.add(te);
|
||||
|
||||
presentTileEntities.put(info.pos, te);
|
||||
specialRenderedTileEntities.add(te);
|
||||
}
|
||||
if (movementBehaviour != null && !movementBehaviour.renderAsNormalTileEntity())
|
||||
return;
|
||||
|
||||
presentTileEntities.put(info.pos, te);
|
||||
specialRenderedTileEntities.add(te);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -48,7 +49,7 @@ public class ContraptionRenderDispatcher {
|
|||
|
||||
/**
|
||||
* Reset a contraption's renderer.
|
||||
*
|
||||
*
|
||||
* @param contraption The contraption to invalidate.
|
||||
* @return true if there was a renderer associated with the given contraption.
|
||||
*/
|
||||
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -139,7 +144,7 @@ public class FlwContraption extends ContraptionRenderInfo {
|
|||
|
||||
List<RenderType> blockLayers = RenderType.chunkBufferLayers();
|
||||
Collection<StructureBlockInfo> renderedBlocks = contraption.getRenderedBlocks();
|
||||
|
||||
|
||||
for (RenderType layer : blockLayers) {
|
||||
Model layerModel = new WorldModel(renderWorld, layer, renderedBlocks, layer + "_" + contraption.entity.getId());
|
||||
renderLayers.put(layer, new ArrayModelRenderer(layerModel));
|
||||
|
@ -147,16 +152,15 @@ 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())) {
|
||||
Level world = te.getLevel();
|
||||
te.setLevel(renderWorld);
|
||||
instanceWorld.tileInstanceManager.add(te);
|
||||
te.setLevel(world);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -142,10 +142,6 @@ public class BeltConnectorItem extends BlockItem {
|
|||
failed = true;
|
||||
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);
|
||||
|
@ -154,15 +150,20 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
if (!failed)
|
||||
return;
|
||||
|
||||
for (BlockPos pos : beltsToCreate)
|
||||
|
||||
for (BlockPos pos : beltsToCreate)
|
||||
if (AllBlocks.BELT.has(world.getBlockState(pos)))
|
||||
world.destroyBlock(pos, false);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
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 {
|
||||
lightPos = pos;
|
||||
renderer.render(tileEntity, pt, ms, buffer, worldLight, OverlayTexture.NO_OVERLAY);
|
||||
}
|
||||
int worldLight = getCombinedLight(world, lightPos, renderWorld, pos);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue