Method to invalidate contraption renderers
- Call ContraptionRenderDispatcher#invalidate, at some point during a tick, and the structure will be reset. - Move contraption compartment to SBBContraptionManager - Contraption compartment uses custom pair with better hash function instead of apache commons pair
This commit is contained in:
parent
322902d056
commit
5cb2eef157
7 changed files with 46 additions and 14 deletions
|
@ -7,6 +7,7 @@ import java.util.function.Function;
|
|||
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.render.SBBContraptionManager;
|
||||
import com.simibubi.create.content.contraptions.relays.encased.CasingConnectivity;
|
||||
import com.simibubi.create.content.curiosities.armor.CopperBacktankArmorLayer;
|
||||
import com.simibubi.create.content.curiosities.bell.SoulPulseEffectHandler;
|
||||
|
@ -94,7 +95,7 @@ public class CreateClient {
|
|||
|
||||
public static void clientInit(FMLClientSetupEvent event) {
|
||||
BUFFER_CACHE.registerCompartment(KineticTileEntityRenderer.KINETIC_TILE);
|
||||
BUFFER_CACHE.registerCompartment(ContraptionRenderDispatcher.CONTRAPTION, 20);
|
||||
BUFFER_CACHE.registerCompartment(SBBContraptionManager.CONTRAPTION, 20);
|
||||
BUFFER_CACHE.registerCompartment(WorldSectionElement.DOC_WORLD_SECTION, 20);
|
||||
|
||||
AllKeys.register();
|
||||
|
|
|
@ -44,7 +44,16 @@ public class ContraptionRenderDispatcher {
|
|||
|
||||
private static WorldAttached<ContraptionRenderManager<?>> WORLDS = new WorldAttached<>(SBBContraptionManager::new);
|
||||
|
||||
public static final Compartment<Pair<Contraption, RenderType>> CONTRAPTION = new Compartment<>();
|
||||
/**
|
||||
* Reset a contraption's renderer.
|
||||
* @param contraption The contraption to invalidate.
|
||||
* @return true if there was a renderer associated with the given contraption.
|
||||
*/
|
||||
public static boolean invalidate(Contraption contraption) {
|
||||
World level = contraption.entity.level;
|
||||
|
||||
return WORLDS.get(level).invalidate(contraption);
|
||||
}
|
||||
|
||||
public static void tick(World world) {
|
||||
if (Minecraft.getInstance().isPaused()) return;
|
||||
|
|
|
@ -68,4 +68,8 @@ public class ContraptionRenderInfo {
|
|||
public ContraptionMatrices getMatrices() {
|
||||
return matrices;
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,20 @@ public abstract class ContraptionRenderManager<C extends ContraptionRenderInfo>
|
|||
this.world = (World) world;
|
||||
}
|
||||
|
||||
public boolean invalidate(Contraption contraption) {
|
||||
int entityId = contraption.entity.getId();
|
||||
|
||||
C removed = renderInfos.remove(entityId);
|
||||
|
||||
if (removed != null) {
|
||||
removed.invalidate();
|
||||
visible.remove(removed);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void renderLayer(RenderLayerEvent event) {
|
||||
for (C c : visible) {
|
||||
c.setupMatrices(event.stack, event.camX, event.camY, event.camZ);
|
||||
|
@ -85,6 +99,9 @@ public abstract class ContraptionRenderManager<C extends ContraptionRenderInfo>
|
|||
}
|
||||
|
||||
public void delete() {
|
||||
for (C renderer : renderInfos.values()) {
|
||||
renderer.invalidate();
|
||||
}
|
||||
renderInfos.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -94,12 +94,4 @@ public class FlwContraptionManager extends ContraptionRenderManager<RenderedCont
|
|||
// we use visible in #tick() so we have to re-evaluate it if any were removed
|
||||
if (removed) collectVisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
for (RenderedContraption renderer : renderInfos.values()) {
|
||||
renderer.invalidate();
|
||||
}
|
||||
renderInfos.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ public class RenderedContraption extends ContraptionRenderInfo {
|
|||
lighter.lightVolume.bind();
|
||||
}
|
||||
|
||||
void invalidate() {
|
||||
public void invalidate() {
|
||||
for (ModelRenderer buffer : renderLayers.values()) {
|
||||
buffer.delete();
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.render;
|
||||
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher.CONTRAPTION;
|
||||
import static com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher.buildStructureBuffer;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
|
||||
import com.simibubi.create.foundation.render.Compartment;
|
||||
import com.simibubi.create.foundation.render.SuperByteBuffer;
|
||||
import com.simibubi.create.foundation.utility.Pair;
|
||||
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
|
||||
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.world.IWorld;
|
||||
|
||||
public class SBBContraptionManager extends ContraptionRenderManager<ContraptionRenderInfo> {
|
||||
public static final Compartment<Pair<Contraption, RenderType>> CONTRAPTION = new Compartment<>();
|
||||
|
||||
public SBBContraptionManager(IWorld world) {
|
||||
super(world);
|
||||
}
|
||||
|
@ -25,6 +26,14 @@ public class SBBContraptionManager extends ContraptionRenderManager<ContraptionR
|
|||
visible.forEach(info -> renderContraptionLayerSBB(event, info));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean invalidate(Contraption contraption) {
|
||||
for (RenderType chunkBufferLayer : RenderType.chunkBufferLayers()) {
|
||||
CreateClient.BUFFER_CACHE.invalidate(CONTRAPTION, Pair.of(contraption, chunkBufferLayer));
|
||||
}
|
||||
return super.invalidate(contraption);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContraptionRenderInfo create(Contraption c) {
|
||||
PlacementSimulationWorld renderWorld = ContraptionRenderDispatcher.setupRenderWorld(world, c);
|
||||
|
|
Loading…
Reference in a new issue