mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-13 05:54:01 +01:00
Contraption renderer checks for flywheel worlds
- Should fix an issue with smaller units
This commit is contained in:
parent
ab6b18e42d
commit
81b0cf77e1
@ -44,7 +44,6 @@ import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.world.IBlockDisplayReader;
|
||||
import net.minecraft.world.LightType;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.template.Template;
|
||||
@ -56,24 +55,6 @@ public class ContraptionRenderDispatcher {
|
||||
public static final Compartment<Pair<Contraption, Integer>> CONTRAPTION = new Compartment<>();
|
||||
protected static PlacementSimulationWorld renderWorld;
|
||||
|
||||
public static void notifyLightPacket(IBlockDisplayReader world, int chunkX, int chunkZ) {
|
||||
for (RenderedContraption renderer : renderers.values()) {
|
||||
renderer.getLighter().lightVolume.notifyLightPacket(world, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
PlacementSimulationWorld renderWorld = null;
|
||||
if (Backend.canUseVBOs()) {
|
||||
RenderedContraption renderer = getRenderer(world, c);
|
||||
|
||||
renderWorld = renderer.renderWorld;
|
||||
}
|
||||
TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer);
|
||||
|
||||
}
|
||||
|
||||
public static void tick() {
|
||||
if (Minecraft.getInstance().isGamePaused()) return;
|
||||
|
||||
@ -84,18 +65,6 @@ public class ContraptionRenderDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
private static RenderedContraption getRenderer(World world, Contraption c) {
|
||||
int entityId = c.entity.getEntityId();
|
||||
RenderedContraption contraption = renderers.get(entityId);
|
||||
|
||||
if (contraption == null) {
|
||||
contraption = new RenderedContraption(world, c);
|
||||
renderers.put(entityId, contraption);
|
||||
}
|
||||
|
||||
return contraption;
|
||||
}
|
||||
|
||||
public static void beginFrame(ActiveRenderInfo info, double camX, double camY, double camZ) {
|
||||
for (RenderedContraption renderer : renderers.values()) {
|
||||
renderer.beginFrame(info, camX, camY, camZ);
|
||||
@ -131,27 +100,21 @@ public class ContraptionRenderDispatcher {
|
||||
GL13.glActiveTexture(GL40.GL_TEXTURE0);
|
||||
}
|
||||
|
||||
public static void removeDeadContraptions() {
|
||||
renderers.values().removeIf(renderer -> {
|
||||
if (renderer.isDead()) {
|
||||
renderer.invalidate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
private static RenderedContraption getRenderer(World world, Contraption c) {
|
||||
int entityId = c.entity.getEntityId();
|
||||
RenderedContraption contraption = renderers.get(entityId);
|
||||
|
||||
if (contraption == null) {
|
||||
contraption = new RenderedContraption(world, c);
|
||||
renderers.put(entityId, contraption);
|
||||
}
|
||||
|
||||
public static void invalidateAll() {
|
||||
for (RenderedContraption renderer : renderers.values()) {
|
||||
renderer.invalidate();
|
||||
}
|
||||
|
||||
renderers.clear();
|
||||
return contraption;
|
||||
}
|
||||
|
||||
public static void render(AbstractContraptionEntity entity, MatrixStack ms, IRenderTypeBuffer buffers,
|
||||
MatrixStack msLocal, Contraption contraption) {
|
||||
if (Backend.canUseVBOs()) {
|
||||
if (Backend.canUseVBOs() && Backend.isFlywheelWorld(entity.world)) {
|
||||
ContraptionRenderDispatcher.renderDynamic(entity.world, contraption, ms, msLocal, buffers);
|
||||
} else {
|
||||
ContraptionRenderDispatcher.renderDynamic(entity.world, contraption, ms, msLocal, buffers);
|
||||
@ -159,14 +122,6 @@ public class ContraptionRenderDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderDynamic(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
renderTileEntities(world, c, ms, msLocal, buffer);
|
||||
if (buffer instanceof IRenderTypeBuffer.Impl)
|
||||
((IRenderTypeBuffer.Impl) buffer).draw();
|
||||
renderActors(world, c, ms, msLocal, buffer);
|
||||
}
|
||||
|
||||
public static void renderStructure(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
SuperByteBufferCache bufferCache = CreateClient.bufferCache;
|
||||
@ -186,6 +141,51 @@ public class ContraptionRenderDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderDynamic(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
renderTileEntities(world, c, ms, msLocal, buffer);
|
||||
if (buffer instanceof IRenderTypeBuffer.Impl)
|
||||
((IRenderTypeBuffer.Impl) buffer).draw();
|
||||
renderActors(world, c, ms, msLocal, buffer);
|
||||
}
|
||||
|
||||
public static void renderTileEntities(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
PlacementSimulationWorld renderWorld = null;
|
||||
if (Backend.canUseVBOs() && Backend.isFlywheelWorld(world)) {
|
||||
RenderedContraption renderer = getRenderer(world, c);
|
||||
|
||||
renderWorld = renderer.renderWorld;
|
||||
}
|
||||
TileEntityRenderHelper.renderTileEntities(world, renderWorld, c.specialRenderedTileEntities, ms, msLocal, buffer);
|
||||
|
||||
}
|
||||
|
||||
protected static void renderActors(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
MatrixStack[] matrixStacks = new MatrixStack[]{ms, msLocal};
|
||||
for (Pair<Template.BlockInfo, MovementContext> actor : c.getActors()) {
|
||||
MovementContext context = actor.getRight();
|
||||
if (context == null)
|
||||
continue;
|
||||
if (context.world == null)
|
||||
context.world = world;
|
||||
Template.BlockInfo blockInfo = actor.getLeft();
|
||||
for (MatrixStack m : matrixStacks) {
|
||||
m.push();
|
||||
MatrixStacker.of(m)
|
||||
.translate(blockInfo.pos);
|
||||
}
|
||||
|
||||
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
|
||||
if (movementBehaviour != null)
|
||||
movementBehaviour.renderInContraption(context, ms, msLocal, buffer);
|
||||
|
||||
for (MatrixStack m : matrixStacks)
|
||||
m.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private static SuperByteBuffer buildStructureBuffer(Contraption c, RenderType layer) {
|
||||
BufferBuilder builder = buildStructure(c, layer);
|
||||
return new SuperByteBuffer(builder);
|
||||
@ -232,31 +232,6 @@ public class ContraptionRenderDispatcher {
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected static void renderActors(World world, Contraption c, MatrixStack ms, MatrixStack msLocal,
|
||||
IRenderTypeBuffer buffer) {
|
||||
MatrixStack[] matrixStacks = new MatrixStack[] { ms, msLocal };
|
||||
for (Pair<Template.BlockInfo, MovementContext> actor : c.getActors()) {
|
||||
MovementContext context = actor.getRight();
|
||||
if (context == null)
|
||||
continue;
|
||||
if (context.world == null)
|
||||
context.world = world;
|
||||
Template.BlockInfo blockInfo = actor.getLeft();
|
||||
for (MatrixStack m : matrixStacks) {
|
||||
m.push();
|
||||
MatrixStacker.of(m)
|
||||
.translate(blockInfo.pos);
|
||||
}
|
||||
|
||||
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
|
||||
if (movementBehaviour != null)
|
||||
movementBehaviour.renderInContraption(context, ms, msLocal, buffer);
|
||||
|
||||
for (MatrixStack m : matrixStacks)
|
||||
m.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLight(World world, float lx, float ly, float lz) {
|
||||
BlockPos.Mutable pos = new BlockPos.Mutable();
|
||||
float sky = 0, block = 0;
|
||||
@ -302,4 +277,22 @@ public class ContraptionRenderDispatcher {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void invalidateAll() {
|
||||
for (RenderedContraption renderer : renderers.values()) {
|
||||
renderer.invalidate();
|
||||
}
|
||||
|
||||
renderers.clear();
|
||||
}
|
||||
|
||||
public static void removeDeadContraptions() {
|
||||
renderers.values().removeIf(renderer -> {
|
||||
if (renderer.isDead()) {
|
||||
renderer.invalidate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user