diff --git a/gradle.properties b/gradle.properties index 5a937b953..03ccbd79c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ cursegradle_version = 1.4.0 # dependency versions registrate_version = 1.0.4 -flywheel_version = 1.16-0.2.0.32 +flywheel_version = 1.16-0.2.0.33 jei_version = 7.7.1.110 # curseforge information diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java index 19c17b07c..751fe2236 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java @@ -164,11 +164,5 @@ public class GlueInstance extends EntityInstance implements ITi public VertexFormat format() { return Formats.UNLIT_MODEL; } - - @Override - public ElementBuffer createEBO() { - return QuadConverter.getInstance() - .quads2Tris(2); - } } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 830335441..2d98ca770 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -1,12 +1,11 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import static org.lwjgl.opengl.GL11.GL_QUADS; - -import java.util.Random; +import java.util.Collection; import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.core.model.ModelUtil; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.GatherContextEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent; @@ -24,36 +23,24 @@ import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.TileEntityRenderHelper; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; -import net.minecraft.block.BlockRenderType; -import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockModelRenderer; -import net.minecraft.client.renderer.BlockModelShapes; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.client.model.data.EmptyModelData; -import net.minecraftforge.common.util.Lazy; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @OnlyIn(Dist.CLIENT) @Mod.EventBusSubscriber(Dist.CLIENT) public class ContraptionRenderDispatcher { - private static final Lazy MODEL_RENDERER = Lazy.of(() -> new BlockModelRenderer(Minecraft.getInstance().getBlockColors())); - private static final Lazy BLOCK_MODELS = Lazy.of(() -> Minecraft.getInstance().getModelManager().getBlockModelShaper()); private static WorldAttached> WORLDS = new WorldAttached<>(SBBContraptionManager::new); @@ -147,42 +134,12 @@ public class ContraptionRenderDispatcher { } public static SuperByteBuffer buildStructureBuffer(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { - BufferBuilder builder = buildStructure(renderWorld, c, layer); + Collection values = c.getBlocks() + .values(); + BufferBuilder builder = ModelUtil.getBufferBuilderFromTemplate(renderWorld, layer, values); return new SuperByteBuffer(builder); } - public static BufferBuilder buildStructure(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { - MatrixStack ms = new MatrixStack(); - Random random = new Random(); - BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); - builder.begin(GL_QUADS, DefaultVertexFormats.BLOCK); - - ForgeHooksClient.setRenderLayer(layer); - BlockModelRenderer.enableCaching(); - for (Template.BlockInfo info : c.getBlocks() - .values()) { - BlockState state = info.state; - - if (state.getRenderShape() != BlockRenderType.MODEL) - continue; - if (!RenderTypeLookup.canRenderInLayer(state, layer)) - continue; - - BlockPos pos = info.pos; - - ms.pushPose(); - ms.translate(pos.getX(), pos.getY(), pos.getZ()); - MODEL_RENDERER.get().renderModel(renderWorld, BLOCK_MODELS.get().getBlockModel(state), state, pos, ms, builder, true, - random, 42, OverlayTexture.NO_OVERLAY, EmptyModelData.INSTANCE); - ms.popPose(); - } - BlockModelRenderer.clearCache(); - ForgeHooksClient.setRenderLayer(null); - - builder.end(); - return builder; - } - public static int getLight(World world, float lx, float ly, float lz) { BlockPos.Mutable pos = new BlockPos.Mutable(); float block = 0, sky = 0; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java index 1d4d3309b..6dc366b95 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/RenderedContraption.java @@ -1,26 +1,20 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; - -import javax.annotation.Nullable; +import java.util.function.Supplier; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes; -import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.jozufozu.flywheel.backend.material.MaterialManager; import com.jozufozu.flywheel.backend.model.ArrayModelRenderer; -import com.jozufozu.flywheel.backend.model.BufferedModel; -import com.jozufozu.flywheel.backend.model.IndexedModel; import com.jozufozu.flywheel.backend.model.ModelRenderer; +import com.jozufozu.flywheel.core.model.IModel; +import com.jozufozu.flywheel.core.model.WorldModel; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.light.GridAlignedBB; -import com.jozufozu.flywheel.util.BufferBuilderReader; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionLighter; @@ -28,7 +22,6 @@ import com.simibubi.create.foundation.render.CreateContexts; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; -import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.AxisAlignedBB; @@ -39,13 +32,6 @@ import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; public class RenderedContraption extends ContraptionRenderInfo { - public static final VertexFormat FORMAT = VertexFormat.builder() - .addAttributes(CommonAttributes.VEC3, - CommonAttributes.NORMAL, - CommonAttributes.UV, - CommonAttributes.RGBA, - CommonAttributes.LIGHT) - .build(); private final ContraptionLighter lighter; @@ -137,14 +123,12 @@ public class RenderedContraption extends ContraptionRenderInfo { List blockLayers = RenderType.chunkBufferLayers(); for (RenderType layer : blockLayers) { - BufferedModel layerModel = buildStructureModel(renderWorld, contraption, layer); + Supplier layerModel = () -> new WorldModel(renderWorld, layer, contraption.getBlocks().values()); - if (layerModel != null) { - if (Backend.getInstance().compat.vertexArrayObjectsSupported()) - renderLayers.put(layer, new ArrayModelRenderer(layerModel)); - else - renderLayers.put(layer, new ModelRenderer(layerModel)); - } + if (Backend.getInstance().compat.vertexArrayObjectsSupported()) + renderLayers.put(layer, new ArrayModelRenderer(layerModel)); + else + renderLayers.put(layer, new ModelRenderer(layerModel)); } } @@ -167,47 +151,4 @@ public class RenderedContraption extends ContraptionRenderInfo { private void buildActors() { contraption.getActors().forEach(kinetics::createActor); } - - @Nullable - private static BufferedModel buildStructureModel(PlacementSimulationWorld renderWorld, Contraption c, RenderType layer) { - BufferBuilderReader reader = new BufferBuilderReader(ContraptionRenderDispatcher.buildStructure(renderWorld, c, layer)); - - int vertexCount = reader.getVertexCount(); - if (vertexCount == 0) return null; - - VertexFormat format = FORMAT; - - ByteBuffer vertices = ByteBuffer.allocate(format.getStride() * vertexCount); - vertices.order(ByteOrder.nativeOrder()); - - for (int i = 0; i < vertexCount; i++) { - vertices.putFloat(reader.getX(i)); - vertices.putFloat(reader.getY(i)); - vertices.putFloat(reader.getZ(i)); - - vertices.put(reader.getNX(i)); - vertices.put(reader.getNY(i)); - vertices.put(reader.getNZ(i)); - - vertices.putFloat(reader.getU(i)); - vertices.putFloat(reader.getV(i)); - - vertices.put(reader.getR(i)); - vertices.put(reader.getG(i)); - vertices.put(reader.getB(i)); - vertices.put(reader.getA(i)); - - int light = reader.getLight(i); - - byte block = (byte) (LightTexture.block(light) << 4); - byte sky = (byte) (LightTexture.sky(light) << 4); - - vertices.put(block); - vertices.put(sky); - } - - vertices.rewind(); - - return IndexedModel.fromSequentialQuads(format, vertices, vertexCount); - } } diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert index a42245c1d..02e90fb66 100644 --- a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert +++ b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert @@ -30,7 +30,7 @@ BlockFrag FLWMain(Vertex v) { #if defined(DEBUG_NORMAL) b.color = vec4(norm, 1.); #else - b.color = v.color / diffuse(v.normal); + b.color = vec4(v.color.rgb / diffuse(v.normal), v.color.a); #endif return b;