diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 7317f62a9..64cebacd5 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -23,11 +23,12 @@ import org.lwjgl.opengl.GLCapabilities; import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.jozufozu.flywheel.backend.instancing.InstanceData; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; -import com.jozufozu.flywheel.core.CrumblingRenderer; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; +import com.jozufozu.flywheel.core.CrumblingInstanceManager; import com.jozufozu.flywheel.core.QuadConverter; import com.jozufozu.flywheel.core.WorldContext; -import com.jozufozu.flywheel.core.WorldTileRenderer; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; import com.jozufozu.flywheel.util.WorldAttached; @@ -53,7 +54,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.world.World; -import net.minecraftforge.resource.ISelectiveResourceReloadListener; public class Backend { public static final Logger log = LogManager.getLogger(Backend.class); @@ -64,11 +64,11 @@ public class Backend { public static GLCapabilities capabilities; public static GlCompat compat; - public static WorldAttached> tileRenderer = new WorldAttached<>(() -> new WorldTileRenderer<>(WorldContext.INSTANCE)); - public static LazyValue> blockBreaking = new LazyValue<>(() -> { - Vector renderers = new Vector<>(10); + public static WorldAttached tileInstanceManager = new WorldAttached<>(world -> new TileInstanceManager(WorldContext.INSTANCE.getMaterialManager(world))); + public static LazyValue> blockBreaking = new LazyValue<>(() -> { + Vector renderers = new Vector<>(10); for (int i = 0; i < 10; i++) { - renderers.add(new CrumblingRenderer()); + renderers.add(new CrumblingInstanceManager()); } return renderers; }); @@ -87,7 +87,7 @@ public class Backend { listeners.refreshListener(world -> { if (canUseInstancing() && world != null) { - WorldTileRenderer tileRenderer = Backend.tileRenderer.get(world); + TileInstanceManager tileRenderer = Backend.tileInstanceManager.get(world); tileRenderer.invalidate(); world.loadedTileEntityList.forEach(tileRenderer::add); } @@ -97,7 +97,9 @@ public class Backend { }); listeners.setupFrameListener((world, stack, info, gameRenderer, lightTexture) -> { - Backend.tileRenderer.get(world) + WorldContext.INSTANCE.materialManager.get(world) + .checkAndShiftOrigin(info); + Backend.tileInstanceManager.get(world) .beginFrame(info); }); @@ -108,6 +110,10 @@ public class Backend { throw new IllegalStateException(); } + /** + * Get a string describing the Flywheel backend. When there are eventually multiple backends + * (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use. + */ public static String getBackendDescriptor() { if (canUseInstancing()) { return "GL33 Instanced Arrays"; @@ -191,8 +197,7 @@ public class Backend { IResourceManager manager = mc.getResourceManager(); if (manager instanceof IReloadableResourceManager) { - ISelectiveResourceReloadListener listener = shaderLoader::onResourceManagerReload; - ((IReloadableResourceManager) manager).addReloadListener(listener); + ((IReloadableResourceManager) manager).addReloadListener(shaderLoader); } } @@ -212,7 +217,7 @@ public class Backend { Minecraft mc = Minecraft.getInstance(); ClientWorld world = mc.world; - WorldTileRenderer instancer = tileRenderer.get(world); + TileInstanceManager instancer = tileInstanceManager.get(world); Entity renderViewEntity = mc.renderViewEntity; instancer.tick(renderViewEntity.getX(), renderViewEntity.getY(), renderViewEntity.getZ()); @@ -220,11 +225,11 @@ public class Backend { public static void renderLayer(ClientWorld world, RenderType layer, Matrix4f viewProjection, double cameraX, double cameraY, double cameraZ) { if (!canUseInstancing(world)) return; - WorldTileRenderer renderer = tileRenderer.get(world); + MaterialManager materialManager = WorldContext.INSTANCE.getMaterialManager(world); layer.startDrawing(); - renderer.render(layer, viewProjection, cameraX, cameraY, cameraZ); + materialManager.render(layer, viewProjection, cameraX, cameraY, cameraZ); layer.endDrawing(); } @@ -238,7 +243,7 @@ public class Backend { Long2ObjectMap> breakingProgressions = worldRenderer.blockBreakingProgressions; if (breakingProgressions.isEmpty()) return; - Vector renderers = blockBreaking.getValue(); + Vector renderers = blockBreaking.getValue(); BitSet bitSet = new BitSet(10); @@ -264,12 +269,12 @@ public class Backend { CRUMBLING.startDrawing(); bitSet.stream().forEach(i -> { Texture breaking = textureManager.getTexture(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(i)); - CrumblingRenderer renderer = renderers.get(i); + CrumblingInstanceManager renderer = renderers.get(i); renderer.beginFrame(info); if (breaking != null) { glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); - renderer.render(RenderType.getCutoutMipped(), viewProjection, cameraX, cameraY, cameraZ, program -> program.setTextureScale(64, 64)); + renderer.materialManager.render(RenderType.getCutoutMipped(), viewProjection, cameraX, cameraY, cameraZ); } renderer.invalidate(); @@ -283,7 +288,7 @@ public class Backend { } public static void enqueueUpdate(TileEntity te) { - tileRenderer.get(te.getWorld()).queueUpdate(te); + tileInstanceManager.get(te.getWorld()).queueUpdate(te); } public static void reloadWorldRenderers() { diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java index 068c8ecb1..5bab05133 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java +++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java @@ -23,6 +23,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import org.lwjgl.system.MemoryUtil; @@ -47,23 +48,25 @@ import net.minecraft.resources.IResource; import net.minecraft.resources.IResourceManager; import net.minecraft.util.ResourceLocation; import net.minecraftforge.resource.IResourceType; +import net.minecraftforge.resource.ISelectiveResourceReloadListener; import net.minecraftforge.resource.VanillaResourceType; -public class ShaderLoader { +@ParametersAreNonnullByDefault +public class ShaderLoader implements ISelectiveResourceReloadListener { public static final String SHADER_DIR = "flywheel/shaders/"; public static final String PROGRAM_DIR = "flywheel/programs/"; public static final ArrayList EXTENSIONS = Lists.newArrayList(".vert", ".vsh", ".frag", ".fsh", ".glsl"); // #flwinclude <"valid_namespace:valid/path_to_file.glsl"> private static final Pattern includePattern = Pattern.compile("#flwinclude <\"([\\w\\d_]+:[\\w\\d_./]+)\">"); - private static boolean debugDumpFile = true; private final Map shaderSource = new HashMap<>(); private boolean shouldCrash; private final Gson gson = new GsonBuilder().create(); - void onResourceManagerReload(IResourceManager manager, Predicate predicate) { + @Override + public void onResourceManagerReload(IResourceManager manager, Predicate predicate) { if (predicate.test(VanillaResourceType.SHADERS)) { OptifineHandler.refresh(); Backend.refresh(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java index 8030ef77d..3b3c6d304 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstance.java @@ -4,7 +4,7 @@ import net.minecraft.util.math.BlockPos; /** * A general interface providing information about any type of thing that could use Flywheel's instanced rendering. - * Right now, that's only {@link InstancedTileRenderer}, but there could be an entity equivalent in the future. + * Right now, that's only {@link TileInstanceManager}, but there could be an entity equivalent in the future. */ public interface IInstance { diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java index bf5382e34..71d9a13af 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/IInstanceRendered.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.backend.instancing; +import net.minecraft.world.World; + /** * Something (a TileEntity or Entity) that can be rendered using the instancing API. */ @@ -11,4 +13,6 @@ public interface IInstanceRendered { default boolean shouldRenderNormally() { return false; } + + World getWorld(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/IRendererFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/IRendererFactory.java deleted file mode 100644 index 7a00d4276..000000000 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/IRendererFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.jozufozu.flywheel.backend.instancing; - -import net.minecraft.tileentity.TileEntity; - -@FunctionalInterface -public interface IRendererFactory { - TileEntityInstance create(InstancedTileRenderer manager, T te); -} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/ITileInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/ITileInstanceFactory.java new file mode 100644 index 000000000..8c4936203 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/ITileInstanceFactory.java @@ -0,0 +1,8 @@ +package com.jozufozu.flywheel.backend.instancing; + +import net.minecraft.tileentity.TileEntity; + +@FunctionalInterface +public interface ITileInstanceFactory { + TileEntityInstance create(MaterialManager manager, T te); +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java similarity index 69% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java index 8c87729fb..5f9671fc0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/RenderMaterial.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceMaterial.java @@ -19,8 +19,6 @@ import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.backend.model.IndexedModel; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.QuadConverter; -import com.jozufozu.flywheel.core.shader.IProgramCallback; -import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.util.BufferBuilderReader; import com.jozufozu.flywheel.util.RenderUtil; import com.jozufozu.flywheel.util.VirtualEmptyModelData; @@ -31,22 +29,22 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BlockModelRenderer; import net.minecraft.client.renderer.BlockRendererDispatcher; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3i; -public class RenderMaterial

{ +public class InstanceMaterial { - protected final InstancedTileRenderer

renderer; + protected final Supplier originCoordinate; protected final Cache> models; protected final MaterialSpec spec; + private final VertexFormat modelFormat; - public RenderMaterial(InstancedTileRenderer

renderer, MaterialSpec spec) { - this.renderer = renderer; + public InstanceMaterial(Supplier renderer, MaterialSpec spec) { + this.originCoordinate = renderer; this.spec = spec; this.models = CacheBuilder.newBuilder() @@ -55,35 +53,21 @@ public class RenderMaterial

{ RenderWork.enqueue(model::delete); }) .build(); - } - - public void render(RenderType layer, Matrix4f projection, double camX, double camY, double camZ) { - render(layer, projection, camX, camY, camZ, null); - } - - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

setup) { - if (!(layer == RenderType.getCutoutMipped())) return; - - P program = renderer.context.getProgram(this.spec.getProgramSpec()); - program.bind(); - program.uploadViewProjection(viewProjection); - program.uploadCameraPos(camX, camY, camZ); - - if (setup != null) setup.call(program); - - makeRenderCalls(); + modelFormat = this.spec.getModelFormat(); } public void delete() { - //runOnAll(InstancedModel::delete); models.invalidateAll(); } - protected void makeRenderCalls() { - runOnAll(Instancer::render); + /** + * Clear all instance data without freeing resources. + */ + public void clear() { + models.asMap().values().forEach(Instancer::clear); } - public void runOnAll(Consumer> f) { + public void forEachInstancer(Consumer> f) { for (Instancer model : models.asMap().values()) { f.accept(model); } @@ -106,31 +90,30 @@ public class RenderMaterial

{ return get(toRender, () -> buildModel(toRender)); } - public Instancer get(Object key, Supplier> supplier) { + public Instancer get(Object key, Supplier supplier) { try { - return models.get(key, supplier::get); + return models.get(key, () -> new Instancer<>(supplier.get(), originCoordinate, spec)); } catch (ExecutionException e) { e.printStackTrace(); return null; } } - private Instancer buildModel(BlockState renderedState) { + private BufferedModel buildModel(BlockState renderedState) { BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher(); return buildModel(dispatcher.getModelForState(renderedState), renderedState); } - private Instancer buildModel(IBakedModel model, BlockState renderedState) { + private BufferedModel buildModel(IBakedModel model, BlockState renderedState) { return buildModel(model, renderedState, new MatrixStack()); } - private Instancer buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) { + private BufferedModel buildModel(IBakedModel model, BlockState referenceState, MatrixStack ms) { BufferBuilderReader reader = new BufferBuilderReader(getBufferBuilder(model, referenceState, ms)); - VertexFormat format = spec.getModelFormat(); int vertexCount = reader.getVertexCount(); - ByteBuffer vertices = ByteBuffer.allocate(vertexCount * format.getStride()); + ByteBuffer vertices = ByteBuffer.allocate(vertexCount * modelFormat.getStride()); vertices.order(ByteOrder.nativeOrder()); for (int i = 0; i < vertexCount; i++) { @@ -148,10 +131,9 @@ public class RenderMaterial

{ vertices.rewind(); - BufferedModel bufferedModel = new IndexedModel(GlPrimitive.TRIANGLES, format, vertices, vertexCount, QuadConverter.getInstance().quads2Tris(vertexCount / 4)); - //BufferedModel bufferedModel = new BufferedModel(GlPrimitive.QUADS, format, vertices, vertexCount); + // return new BufferedModel(GlPrimitive.QUADS, format, vertices, vertexCount); - return new Instancer<>(bufferedModel, renderer, spec.getInstanceFormat(), spec.getInstanceFactory()); + return new IndexedModel(GlPrimitive.TRIANGLES, modelFormat, vertices, vertexCount, QuadConverter.getInstance().quads2Tris(vertexCount / 4)); } private static final Direction[] dirs; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderRegistry.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java similarity index 55% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderRegistry.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java index 937315a89..d9412cf52 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java @@ -9,24 +9,24 @@ import com.google.common.collect.Maps; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; -public class InstancedTileRenderRegistry { - private static final InstancedTileRenderRegistry INSTANCE = new InstancedTileRenderRegistry(); +public class InstancedRenderRegistry { + private static final InstancedRenderRegistry INSTANCE = new InstancedRenderRegistry(); - public static InstancedTileRenderRegistry getInstance() { + public static InstancedRenderRegistry getInstance() { return INSTANCE; } - private final Map, IRendererFactory> renderers = Maps.newHashMap(); + private final Map, ITileInstanceFactory> renderers = Maps.newHashMap(); - public void register(TileEntityType type, IRendererFactory rendererFactory) { + public void register(TileEntityType type, ITileInstanceFactory rendererFactory) { this.renderers.put(type, rendererFactory); } @SuppressWarnings("unchecked") @Nullable - public TileEntityInstance create(InstancedTileRenderer manager, T tile) { + public TileEntityInstance create(MaterialManager manager, T tile) { TileEntityType type = tile.getType(); - IRendererFactory factory = (IRendererFactory) this.renderers.get(type); + ITileInstanceFactory factory = (ITileInstanceFactory) this.renderers.get(type); if (factory == null) return null; else return factory.create(manager, tile); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java index 9505a9697..b7b0b8054 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/Instancer.java @@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.instancing; import java.util.ArrayList; import java.util.BitSet; +import java.util.function.Supplier; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.GlVertexArray; @@ -13,9 +14,11 @@ import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.util.AttribUtil; +import net.minecraft.util.math.vector.Vector3i; + public class Instancer { - public final InstancedTileRenderer renderer; + public final Supplier originCoordinate; protected final BufferedModel model; @@ -32,11 +35,11 @@ public class Instancer { boolean anyToRemove; boolean anyToUpdate; - public Instancer(BufferedModel model, InstancedTileRenderer renderer, VertexFormat instanceFormat, IInstanceFactory factory) { + public Instancer(BufferedModel model, Supplier originCoordinate, MaterialSpec spec) { this.model = model; - this.factory = factory; - this.instanceFormat = instanceFormat; - this.renderer = renderer; + this.factory = spec.getInstanceFactory(); + this.instanceFormat = spec.getInstanceFormat(); + this.originCoordinate = originCoordinate; if (model.getVertexCount() <= 0) throw new IllegalArgumentException("Refusing to instance a model with no vertices."); @@ -77,6 +80,17 @@ public class Instancer { return instanceData; } + /** + * Clear all instance data without freeing resources. + */ + public void clear() { + data.clear(); + anyToRemove = true; + } + + /** + * Free acquired resources. Attempting to use this after calling delete is undefined behavior. + */ public void delete() { if (deleted) return; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java new file mode 100644 index 000000000..54e409a36 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java @@ -0,0 +1,129 @@ +package com.jozufozu.flywheel.backend.instancing; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.core.WorldContext; +import com.jozufozu.flywheel.core.materials.ModelData; +import com.jozufozu.flywheel.core.materials.OrientedData; +import com.jozufozu.flywheel.core.shader.IProgramCallback; +import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.util.WeakHashSet; +import com.simibubi.create.foundation.render.AllMaterialSpecs; + +import net.minecraft.client.renderer.ActiveRenderInfo; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Matrix4f; +import net.minecraft.util.math.vector.Vector3i; + +public class MaterialManager

{ + + public static int MAX_ORIGIN_DISTANCE = 100; + + protected final ArrayList> renderers; + protected final Map> materials; + + private BlockPos originCoordinate = BlockPos.ZERO; + + private final WeakHashSet listeners; + + public MaterialManager(WorldContext

context) { + this.materials = new HashMap<>(); + this.renderers = new ArrayList<>(Backend.allMaterials().size()); + this.listeners = new WeakHashSet<>(); + + for (MaterialSpec spec : Backend.allMaterials()) { + InstanceMaterial material = new InstanceMaterial<>(this::getOriginCoordinate, spec); + materials.put(spec.name, material); + MaterialRenderer

renderer = new MaterialRenderer<>(context.getProgram(spec.getProgramName()), material); + renderers.add(renderer); + } + + } + + /** + * Render every model for every material. + * + * @param layer Which vanilla {@link RenderType} is being drawn? + * @param viewProjection How do we get from camera space to clip space? + */ + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { + render(layer, viewProjection, camX, camY, camZ, null); + } + + /** + * Render every model for every material. + * + * @param layer Which vanilla {@link RenderType} is being drawn? + * @param viewProjection How do we get from camera space to clip space? + * @param callback Provide additional uniforms or state here. + */ + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

callback) { + camX -= originCoordinate.getX(); + camY -= originCoordinate.getY(); + camZ -= originCoordinate.getZ(); + + Matrix4f translate = Matrix4f.translate((float) -camX, (float) -camY, (float) -camZ); + + translate.multiplyBackward(viewProjection); + + for (MaterialRenderer

material : renderers) { + material.render(layer, translate, camX, camY, camZ, callback); + } + } + + public void delete() { + for (InstanceMaterial material : materials.values()) { + material.delete(); + } + } + + @SuppressWarnings("unchecked") + public InstanceMaterial getMaterial(MaterialSpec materialType) { + return (InstanceMaterial) materials.get(materialType.name); + } + + public InstanceMaterial getTransformMaterial() { + return getMaterial(AllMaterialSpecs.TRANSFORMED); + } + + public InstanceMaterial getOrientedMaterial() { + return getMaterial(AllMaterialSpecs.ORIENTED); + } + + public Vector3i getOriginCoordinate() { + return originCoordinate; + } + + public void onOriginShift(OriginShiftListener listener) { + listeners.add(listener); + } + + public void checkAndShiftOrigin(ActiveRenderInfo info) { + int cX = MathHelper.floor(info.getProjectedView().x); + int cY = MathHelper.floor(info.getProjectedView().y); + int cZ = MathHelper.floor(info.getProjectedView().z); + + int dX = cX - originCoordinate.getX(); + int dY = cY - originCoordinate.getY(); + int dZ = cZ - originCoordinate.getZ(); + + if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) { + + originCoordinate = new BlockPos(cX, cY, cZ); + + materials.values().forEach(InstanceMaterial::clear); + listeners.forEach(OriginShiftListener::onOriginShift); + } + } + + @FunctionalInterface + public interface OriginShiftListener { + void onOriginShift(); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialRenderer.java new file mode 100644 index 000000000..85f4a3581 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialRenderer.java @@ -0,0 +1,34 @@ +package com.jozufozu.flywheel.backend.instancing; + +import com.jozufozu.flywheel.core.shader.IProgramCallback; +import com.jozufozu.flywheel.core.shader.WorldProgram; + +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.math.vector.Matrix4f; + +public class MaterialRenderer

{ + + private final P program; + private final InstanceMaterial material; + + public MaterialRenderer(P program, InstanceMaterial material) { + this.program = program; + this.material = material; + } + + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

setup) { + if (!(layer == RenderType.getCutoutMipped())) return; + + program.bind(); + program.uploadViewProjection(viewProjection); + program.uploadCameraPos(camX, camY, camZ); + + if (setup != null) setup.call(program); + + makeRenderCalls(); + } + + protected void makeRenderCalls() { + material.forEachInstancer(Instancer::render); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java index c9b56277b..b50b3e214 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialSpec.java @@ -21,7 +21,7 @@ public class MaterialSpec { this.instanceFactory = instanceFactory; } - public ResourceLocation getProgramSpec() { + public ResourceLocation getProgramName() { return programSpec; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java index 713f909bb..48948e9ce 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/TileEntityInstance.java @@ -32,20 +32,20 @@ import net.minecraft.world.World; */ public abstract class TileEntityInstance implements IInstance { - protected final InstancedTileRenderer renderer; + protected final MaterialManager materialManager; protected final T tile; protected final World world; protected final BlockPos pos; protected final BlockPos instancePos; protected final BlockState blockState; - public TileEntityInstance(InstancedTileRenderer renderer, T tile) { - this.renderer = renderer; + public TileEntityInstance(MaterialManager materialManager, T tile) { + this.materialManager = materialManager; this.tile = tile; this.world = tile.getWorld(); this.pos = tile.getPos(); this.blockState = tile.getBlockState(); - this.instancePos = pos.subtract(renderer.getOriginCoordinate()); + this.instancePos = pos.subtract(materialManager.getOriginCoordinate()); } /** @@ -54,7 +54,7 @@ public abstract class TileEntityInstance implements IInsta * *

If your animations are complex or more CPU driven, see {@link IDynamicInstance} or {@link ITickableInstance}. */ - protected void update() { + public void update() { } /** @@ -67,14 +67,12 @@ public abstract class TileEntityInstance implements IInsta /** * Free any acquired resources. - * - *
eg. call {@link InstanceKey#delete()}. */ public abstract void remove(); /** * Just before {@link #update()} would be called, shouldReset() is checked. - * If this function returns true, then this instance will be {@link #remove}d, + * If this function returns true, then this instance will be {@link #remove removed}, * and another instance will be constructed to replace it. This allows for more sane resource * acquisition compared to trying to update everything within the lifetime of an instance. * @@ -86,14 +84,14 @@ public abstract class TileEntityInstance implements IInsta /** * In order to accommodate for floating point precision errors at high coordinates, - * {@link InstancedTileRenderer}s are allowed to arbitrarily adjust the origin, and + * {@link TileInstanceManager}s are allowed to arbitrarily adjust the origin, and * shift the world matrix provided as a shader uniform accordingly. * - * @return The {@link BlockPos} at which the {@link TileEntity} this instance + * @return The {@link BlockPos position} of the {@link TileEntity} this instance * represents should be rendered at to appear in the correct location. */ public BlockPos getInstancePosition() { - return instancePos; + return pos.subtract(materialManager.getOriginCoordinate()); } @Override @@ -117,11 +115,11 @@ public abstract class TileEntityInstance implements IInsta models.forEach(model -> model.setBlockLight(block).setSkyLight(sky)); } - protected RenderMaterial getTransformMaterial() { - return renderer.getTransformMaterial(); + protected InstanceMaterial getTransformMaterial() { + return materialManager.getTransformMaterial(); } - protected RenderMaterial getOrientedMaterial() { - return renderer.getOrientedMaterial(); + protected InstanceMaterial getOrientedMaterial() { + return materialManager.getOrientedMaterial(); } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/TileInstanceManager.java similarity index 70% rename from src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java rename to src/main/java/com/jozufozu/flywheel/backend/instancing/TileInstanceManager.java index 2bc74fbdc..ca1b98711 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/TileInstanceManager.java @@ -8,27 +8,17 @@ import java.util.concurrent.ConcurrentHashMap; import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.core.WorldContext; -import com.jozufozu.flywheel.core.materials.ModelData; -import com.jozufozu.flywheel.core.materials.OrientedData; -import com.jozufozu.flywheel.core.shader.IProgramCallback; -import com.jozufozu.flywheel.core.shader.WorldProgram; -import com.simibubi.create.foundation.render.AllMaterialSpecs; import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.RenderType; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Matrix4f; import net.minecraft.util.math.vector.Vector3f; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public abstract class InstancedTileRenderer

{ +public class TileInstanceManager implements MaterialManager.OriginShiftListener { - public final WorldContext

context; - - protected final Map, RenderMaterial> materials; + public final MaterialManager materialManager; protected final ArrayList queuedAdditions; protected final ConcurrentHashMap.KeySetView queuedUpdates; @@ -40,23 +30,17 @@ public abstract class InstancedTileRenderer

{ protected int frame; protected int tick; - protected InstancedTileRenderer(WorldContext

context) { - this.context = context; + public TileInstanceManager(MaterialManager materialManager) { + this.materialManager = materialManager; + this.queuedUpdates = ConcurrentHashMap.newKeySet(64); + this.queuedAdditions = new ArrayList<>(64); + this.dynamicInstances = new HashMap<>(); + this.tickableInstances = new HashMap<>(); + this.instances = new HashMap<>(); - materials = new HashMap<>(); - for (MaterialSpec spec : Backend.allMaterials()) { - materials.put(spec, new RenderMaterial<>(this, spec)); - } - - queuedUpdates = ConcurrentHashMap.newKeySet(64); - queuedAdditions = new ArrayList<>(64); - dynamicInstances = new HashMap<>(); - tickableInstances = new HashMap<>(); - instances = new HashMap<>(); + materialManager.onOriginShift(this); } - public abstract BlockPos getOriginCoordinate(); - public void tick(double cameraX, double cameraY, double cameraZ) { tick++; @@ -112,40 +96,11 @@ public abstract class InstancedTileRenderer

{ } } - /** - * Render every model for every material. - * - * @param layer Which vanilla {@link RenderType} is being drawn? - * @param viewProjection How do we get from camera space to clip space? - */ - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ) { - render(layer, viewProjection, camX, camY, camZ, null); - } - - /** - * Render every model for every material. - * - * @param layer Which vanilla {@link RenderType} is being drawn? - * @param viewProjection How do we get from camera space to clip space? - * @param callback Provide additional uniforms or state here. - */ - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback

callback) { - for (RenderMaterial material : materials.values()) { - material.render(layer, viewProjection, camX, camY, camZ, callback); - } - } - - @SuppressWarnings("unchecked") - public RenderMaterial getMaterial(MaterialSpec materialType) { - return (RenderMaterial) materials.get(materialType); - } - - public RenderMaterial getTransformMaterial() { - return getMaterial(AllMaterialSpecs.TRANSFORMED); - } - - public RenderMaterial getOrientedMaterial() { - return getMaterial(AllMaterialSpecs.ORIENTED); + @Override + public void onOriginShift() { + ArrayList instancedTiles = new ArrayList<>(instances.keySet()); + invalidate(); + instancedTiles.forEach(this::add); } @SuppressWarnings("unchecked") @@ -267,7 +222,7 @@ public abstract class InstancedTileRenderer

{ } private TileEntityInstance createInternal(T tile) { - TileEntityInstance renderer = InstancedTileRenderRegistry.getInstance().create(this, tile); + TileEntityInstance renderer = InstancedRenderRegistry.getInstance().create(materialManager, tile); if (renderer != null) { renderer.updateLight(); @@ -284,9 +239,6 @@ public abstract class InstancedTileRenderer

{ } public void invalidate() { - for (RenderMaterial material : materials.values()) { - material.delete(); - } instances.clear(); dynamicInstances.clear(); tickableInstances.clear(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java new file mode 100644 index 000000000..a872d3a94 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/EntityInstance.java @@ -0,0 +1,104 @@ +package com.jozufozu.flywheel.backend.instancing.entity; + +import java.util.Arrays; +import java.util.stream.Stream; + +import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; +import com.jozufozu.flywheel.backend.instancing.IInstance; +import com.jozufozu.flywheel.backend.instancing.ITickableInstance; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; +import com.jozufozu.flywheel.core.materials.IFlatLight; +import com.jozufozu.flywheel.core.materials.ModelData; +import com.jozufozu.flywheel.core.materials.OrientedData; + +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; +import net.minecraft.util.math.vector.Vector3i; +import net.minecraft.world.LightType; +import net.minecraft.world.World; + +/** + * The layer between a {@link TileEntity} and the Flywheel backend. + ** + *

There are a few additional features that overriding classes can opt in to: + *

    + *
  • {@link IDynamicInstance}
  • + *
  • {@link ITickableInstance}
  • + *
+ * See the interfaces' documentation for more information about each one. + * + *
Implementing one or more of these will give a {@link EntityInstance} access + * to more interesting and regular points within a tick or a frame. + * + * @param The type of {@link Entity} your class is an instance of. + */ +public abstract class EntityInstance implements IInstance { + + protected final MaterialManager materialManager; + protected final E entity; + protected final World world; + + public EntityInstance(MaterialManager materialManager, E entity) { + this.materialManager = materialManager; + this.entity = entity; + this.world = entity.world; + } + + /** + * Free any acquired resources. + */ + public abstract void remove(); + + /** + * In order to accommodate for floating point precision errors at high coordinates, + * {@link TileInstanceManager}s are allowed to arbitrarily adjust the origin, and + * shift the world matrix provided as a shader uniform accordingly. + * + * @return The {@link BlockPos position} of the {@link Entity} this instance + * represents should be rendered at to appear in the correct location. + */ + public Vector3f getInstancePosition() { + Vector3d pos = entity.getPositionVec(); + Vector3i origin = materialManager.getOriginCoordinate(); + return new Vector3f( + (float) (pos.x - origin.getX()), + (float) (pos.y - origin.getY()), + (float) (pos.z - origin.getZ()) + ); + } + + @Override + public BlockPos getWorldPosition() { + return entity.getBlockPos(); + } + + protected void relight(BlockPos pos, IFlatLight... models) { + relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models); + } + + protected > void relight(BlockPos pos, Stream models) { + relight(world.getLightLevel(LightType.BLOCK, pos), world.getLightLevel(LightType.SKY, pos), models); + } + + protected void relight(int block, int sky, IFlatLight... models) { + relight(block, sky, Arrays.stream(models)); + } + + protected > void relight(int block, int sky, Stream models) { + models.forEach(model -> model.setBlockLight(block).setSkyLight(sky)); + } + + protected InstanceMaterial getTransformMaterial() { + return materialManager.getTransformMaterial(); + } + + protected InstanceMaterial getOrientedMaterial() { + return materialManager.getOrientedMaterial(); + } + +} diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java new file mode 100644 index 000000000..7915947e4 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/entity/IEntityInstanceFactory.java @@ -0,0 +1,10 @@ +package com.jozufozu.flywheel.backend.instancing.entity; + +import com.jozufozu.flywheel.backend.instancing.MaterialManager; + +import net.minecraft.entity.Entity; + +@FunctionalInterface +public interface IEntityInstanceFactory { + EntityInstance create(MaterialManager manager, E te); +} diff --git a/src/main/java/com/jozufozu/flywheel/core/CrumblingInstanceManager.java b/src/main/java/com/jozufozu/flywheel/core/CrumblingInstanceManager.java new file mode 100644 index 000000000..6ff67a6b4 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/CrumblingInstanceManager.java @@ -0,0 +1,17 @@ +package com.jozufozu.flywheel.core; + +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; + +import net.minecraft.util.math.BlockPos; + +public class CrumblingInstanceManager extends TileInstanceManager { + public CrumblingInstanceManager() { + super(new MaterialManager<>(WorldContext.CRUMBLING)); + } + + @Override + protected boolean shouldTick(BlockPos worldPos, float lookX, float lookY, float lookZ, int cX, int cY, int cZ) { + return true; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/CrumblingRenderer.java b/src/main/java/com/jozufozu/flywheel/core/CrumblingRenderer.java deleted file mode 100644 index 3e88d32c7..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/CrumblingRenderer.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.jozufozu.flywheel.core; - -import net.minecraft.util.math.BlockPos; - -public class CrumblingRenderer extends WorldTileRenderer { - public CrumblingRenderer() { - super(WorldContext.CRUMBLING); - } - - @Override - protected boolean shouldTick(BlockPos worldPos, float lookX, float lookY, float lookZ, int cX, int cY, int cZ) { - return true; - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java index b77b4e56e..95130b847 100644 --- a/src/main/java/com/jozufozu/flywheel/core/WorldContext.java +++ b/src/main/java/com/jozufozu/flywheel/core/WorldContext.java @@ -13,6 +13,7 @@ import com.jozufozu.flywheel.backend.ResourceUtil; import com.jozufozu.flywheel.backend.ShaderContext; import com.jozufozu.flywheel.backend.ShaderLoader; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.MaterialSpec; import com.jozufozu.flywheel.backend.loading.InstancedArraysTemplate; import com.jozufozu.flywheel.backend.loading.Program; @@ -25,8 +26,10 @@ import com.jozufozu.flywheel.core.shader.IMultiProgram; import com.jozufozu.flywheel.core.shader.StateSensitiveMultiProgram; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.spec.ProgramSpec; +import com.jozufozu.flywheel.util.WorldAttached; import net.minecraft.util.ResourceLocation; +import net.minecraft.world.IWorld; public class WorldContext

extends ShaderContext

{ @@ -37,13 +40,16 @@ public class WorldContext

extends ShaderContext

{ public static final WorldContext CRUMBLING = new WorldContext<>(new ResourceLocation(Flywheel.ID, "context/crumbling"), CrumblingProgram::new); protected final ResourceLocation name; - private final ExtensibleGlProgram.Factory

factory; protected Supplier> specStream; protected TemplateFactory templateFactory; + public final WorldAttached> materialManager = new WorldAttached<>($ -> new MaterialManager<>(this)); + private final Map builtins = new EnumMap<>(ShaderType.class); private final Map builtinSources = new EnumMap<>(ShaderType.class); + private final ExtensibleGlProgram.Factory

factory; + public WorldContext(ResourceLocation root, ExtensibleGlProgram.Factory

factory) { this.factory = factory; this.name = root; @@ -52,11 +58,15 @@ public class WorldContext

extends ShaderContext

{ specStream = () -> Backend.allMaterials() .stream() - .map(MaterialSpec::getProgramSpec); + .map(MaterialSpec::getProgramName); templateFactory = InstancedArraysTemplate::new; } + public MaterialManager

getMaterialManager(IWorld world) { + return materialManager.get(world); + } + public WorldContext

setSpecStream(Supplier> specStream) { this.specStream = specStream; return this; diff --git a/src/main/java/com/jozufozu/flywheel/core/WorldTileRenderer.java b/src/main/java/com/jozufozu/flywheel/core/WorldTileRenderer.java deleted file mode 100644 index b0fe400e3..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/WorldTileRenderer.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.jozufozu.flywheel.core; - -import java.util.ArrayList; - -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; -import com.jozufozu.flywheel.core.shader.IProgramCallback; -import com.jozufozu.flywheel.core.shader.WorldProgram; - -import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.RenderType; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Matrix4f; - -public class WorldTileRenderer

extends InstancedTileRenderer

{ - public static int MAX_ORIGIN_DISTANCE = 100; - - public BlockPos originCoordinate = BlockPos.ZERO; - - public WorldTileRenderer(WorldContext

context) { - super(context); - } - - @Override - public BlockPos getOriginCoordinate() { - return originCoordinate; - } - - @Override - public void beginFrame(ActiveRenderInfo info) { - int cX = MathHelper.floor(info.getProjectedView().x); - int cY = MathHelper.floor(info.getProjectedView().y); - int cZ = MathHelper.floor(info.getProjectedView().z); - - int dX = Math.abs(cX - originCoordinate.getX()); - int dY = Math.abs(cY - originCoordinate.getY()); - int dZ = Math.abs(cZ - originCoordinate.getZ()); - - if (dX > MAX_ORIGIN_DISTANCE || dY > MAX_ORIGIN_DISTANCE || dZ > MAX_ORIGIN_DISTANCE) { - - originCoordinate = new BlockPos(cX, cY, cZ); - - ArrayList instancedTiles = new ArrayList<>(instances.keySet()); - invalidate(); - instancedTiles.forEach(this::add); - } - - super.beginFrame(info); - } - - @Override - public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, - IProgramCallback

callback) { - BlockPos originCoordinate = getOriginCoordinate(); - - camX -= originCoordinate.getX(); - camY -= originCoordinate.getY(); - camZ -= originCoordinate.getZ(); - - Matrix4f translate = Matrix4f.translate((float) -camX, (float) -camY, (float) -camZ); - - translate.multiplyBackward(viewProjection); - - super.render(layer, translate, camX, camY, camZ, callback); - } -} diff --git a/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java b/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java index 326a3c98c..26bcc9d19 100644 --- a/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java +++ b/src/main/java/com/jozufozu/flywheel/core/instancing/ConditionalInstance.java @@ -1,6 +1,7 @@ package com.jozufozu.flywheel.core.instancing; import java.util.Optional; +import java.util.function.Consumer; import javax.annotation.Nullable; @@ -10,19 +11,26 @@ import com.jozufozu.flywheel.backend.instancing.Instancer; public class ConditionalInstance { final Instancer model; - Condition condition; + ICondition condition; + + Consumer setupFunc; @Nullable private D instance; - public ConditionalInstance(Instancer model, Condition condition) { + public ConditionalInstance(Instancer model) { this.model = model; - this.condition = condition; + this.condition = () -> true; update(); } - public ConditionalInstance setCondition(Condition condition) { + public ConditionalInstance withSetupFunc(Consumer setupFunc) { + this.setupFunc = setupFunc; + return this; + } + + public ConditionalInstance withCondition(ICondition condition) { this.condition = condition; return this; } @@ -31,6 +39,7 @@ public class ConditionalInstance { boolean shouldShow = condition.shouldShow(); if (shouldShow && instance == null) { instance = model.createInstance(); + if (setupFunc != null) setupFunc.accept(instance); } else if (!shouldShow && instance != null) { instance.delete(); instance = null; @@ -48,7 +57,7 @@ public class ConditionalInstance { } @FunctionalInterface - public interface Condition { + public interface ICondition { boolean shouldShow(); } } diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java b/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java index 368839298..2fc7fc285 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/BasicData.java @@ -4,7 +4,7 @@ import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer; import com.jozufozu.flywheel.backend.instancing.InstanceData; import com.jozufozu.flywheel.backend.instancing.Instancer; -public class BasicData extends InstanceData implements IFlatLight { +public abstract class BasicData extends InstanceData implements IFlatLight { protected byte blockLight; protected byte skyLight; diff --git a/src/main/java/com/jozufozu/flywheel/core/materials/OrientedData.java b/src/main/java/com/jozufozu/flywheel/core/materials/OrientedData.java index d6c63480a..843d4cb00 100644 --- a/src/main/java/com/jozufozu/flywheel/core/materials/OrientedData.java +++ b/src/main/java/com/jozufozu/flywheel/core/materials/OrientedData.java @@ -21,12 +21,10 @@ public class OrientedData extends BasicData { private float qZ; private float qW; - public OrientedData(Instancer owner) { super(owner); } - public OrientedData setPosition(BlockPos pos) { return setPosition(pos.getX(), pos.getY(), pos.getZ()); } diff --git a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java index 7a8e620ab..74531aa96 100644 --- a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java +++ b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java @@ -3,18 +3,18 @@ package com.jozufozu.flywheel.util; import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; +import java.util.function.Function; import javax.annotation.Nonnull; import net.minecraft.world.IWorld; -import net.minecraftforge.common.util.NonNullSupplier; public class WorldAttached { Map attached; - private final NonNullSupplier factory; + private final WorldAttacher factory; - public WorldAttached(NonNullSupplier factory) { + public WorldAttached(WorldAttacher factory) { this.factory = factory; attached = new HashMap<>(); } @@ -24,7 +24,7 @@ public class WorldAttached { T t = attached.get(world); if (t != null) return t; - T entry = factory.get(); + T entry = factory.attach(world); put(world, entry); return entry; } @@ -38,4 +38,15 @@ public class WorldAttached { .forEach(consumer); } + @FunctionalInterface + public interface WorldAttacher extends Function { + @Nonnull + T attach(IWorld world); + + @Override + default T apply(IWorld world) { + return attach(world); + } + } + } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index caa38fe21..9b4106120 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -9,7 +9,7 @@ import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.OptifineHandler; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; @@ -214,10 +214,10 @@ public class CreateClient { BUFFER_CACHE.invalidate(); if (world != null) { - Backend.tileRenderer.get(world) + Backend.tileInstanceManager.get(world) .invalidate(); } else { - Backend.tileRenderer.forEach(InstancedTileRenderer::invalidate); + Backend.tileInstanceManager.forEach(TileInstanceManager::invalidate); } ContraptionRenderDispatcher.invalidateAll(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java index e613e7d28..592db77bf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/BackHalfShaftInstance.java @@ -1,12 +1,12 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; public class BackHalfShaftInstance extends HalfShaftInstance { - public BackHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public BackHalfShaftInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java index 7e4f3f44a..cd06bf1a4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HalfShaftInstance.java @@ -1,14 +1,14 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; public class HalfShaftInstance extends SingleRotatingInstance { - public HalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public HalfShaftInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java index d34848692..c7298995f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/HorizontalHalfShaftInstance.java @@ -1,13 +1,13 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.Direction; public class HorizontalHalfShaftInstance extends HalfShaftInstance { - public HorizontalHalfShaftInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public HorizontalHalfShaftInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java index 2c0e15355..6eb292670 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticData.java @@ -81,7 +81,6 @@ public class KineticData extends BasicData { return this; } - @Override public void write(MappedBuffer buf) { super.write(buf); diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java index 3525e9417..3fbd9f437 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel; @@ -15,7 +15,7 @@ public abstract class KineticTileInstance extends T protected final Direction.Axis axis; - public KineticTileInstance(InstancedTileRenderer modelManager, T tile) { + public KineticTileInstance(MaterialManager modelManager, T tile) { super(modelManager, tile); axis = ((IRotate) blockState.getBlock()).getRotationAxis(blockState); @@ -84,8 +84,8 @@ public abstract class KineticTileInstance extends T return shaft(getRotationAxis()); } - protected final RenderMaterial getRotatingMaterial() { - return renderer.getMaterial(AllMaterialSpecs.ROTATING); + protected final InstanceMaterial getRotatingMaterial() { + return materialManager.getMaterial(AllMaterialSpecs.ROTATING); } public static BlockState shaft(Direction.Axis axis) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java index f692033b0..415882390 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/ShaftlessCogInstance.java @@ -1,18 +1,18 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.foundation.render.AllMaterialSpecs; public class ShaftlessCogInstance extends SingleRotatingInstance { - public ShaftlessCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public ShaftlessCogInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } @Override protected Instancer getModel() { - return renderer.getMaterial(AllMaterialSpecs.ROTATING).getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, tile.getBlockState()); + return materialManager.getMaterial(AllMaterialSpecs.ROTATING).getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, tile.getBlockState()); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java index adba0e16e..17ba2884d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/SingleRotatingInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.base; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import net.minecraft.block.BlockState; @@ -9,7 +9,7 @@ public class SingleRotatingInstance extends KineticTileInstance modelManager, KineticTileEntity tile) { + public SingleRotatingInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); rotatingModel = setup(getModel().createInstance()); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java index e0dd37923..316d7eed2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillActorInstance.java @@ -1,12 +1,14 @@ package com.simibubi.create.content.contraptions.components.actors; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; 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.ContraptionKineticRenderer; +import com.simibubi.create.foundation.render.AllMaterialSpecs; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; @@ -15,12 +17,12 @@ import net.minecraft.util.math.vector.Quaternion; public class DrillActorInstance extends ActorInstance { ActorData drillHead; - private Direction facing; + private final Direction facing; - public DrillActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { - super(modelManager, context); + public DrillActorInstance(MaterialManager materialManager, PlacementSimulationWorld contraption, MovementContext context) { + super(materialManager, contraption, context); - RenderMaterial renderMaterial = modelManager.getActorMaterial(); + InstanceMaterial instanceMaterial = materialManager.getMaterial(AllMaterialSpecs.ACTORS); BlockState state = context.state; @@ -35,7 +37,7 @@ public class DrillActorInstance extends ActorInstance { else eulerY = facing.getHorizontalAngle() + ((axis == Direction.Axis.X) ? 180 : 0); - drillHead = renderMaterial.getModel(AllBlockPartials.DRILL_HEAD, state).createInstance(); + drillHead = instanceMaterial.getModel(AllBlockPartials.DRILL_HEAD, state).createInstance(); drillHead.setPosition(context.localPos) .setBlockLight(localBlockLight()) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java index f097d1330..1df84bd4e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillInstance.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.components.actors; import static net.minecraft.state.properties.BlockStateProperties.FACING; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -14,7 +14,7 @@ import net.minecraft.util.Direction; public class DrillInstance extends SingleRotatingInstance { - public DrillInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public DrillInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java index 34ab5045f..ebc3658e6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/DrillMovementBehaviour.java @@ -3,9 +3,9 @@ package com.simibubi.create.content.contraptions.components.actors; import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; 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.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; @@ -48,8 +48,8 @@ public class DrillMovementBehaviour extends BlockBreakingMovementBehaviour { @Nullable @Override - public ActorInstance createInstance(ContraptionKineticRenderer kr, MovementContext context) { - return new DrillActorInstance(kr, context); + public ActorInstance createInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + return new DrillActorInstance(materialManager, simulationWorld, context); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java index 1b1068756..fafd7c7e2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterActorInstance.java @@ -2,17 +2,18 @@ package com.simibubi.create.content.contraptions.components.actors; import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; 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.ContraptionKineticRenderer; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; @@ -32,16 +33,16 @@ public class HarvesterActorInstance extends ActorInstance { private double rotation; private double previousRotation; - public HarvesterActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { - super(modelManager, context); + public HarvesterActorInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + super(materialManager, simulationWorld, context); - RenderMaterial renderMaterial = modelManager.getTransformMaterial(); + InstanceMaterial instanceMaterial = materialManager.getTransformMaterial(); BlockState state = context.state; facing = state.get(HORIZONTAL_FACING); - harvester = renderMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state).createInstance(); + harvester = instanceMaterial.getModel(AllBlockPartials.HARVESTER_BLADE, state).createInstance(); horizontalAngle = facing.getHorizontalAngle() + ((facing.getAxis() == Direction.Axis.X) ? 180 : 0); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java index a0a993c24..d500ad6ff 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/actors/HarvesterMovementBehaviour.java @@ -7,10 +7,10 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.mutable.MutableBoolean; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; 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.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.VecHelper; @@ -48,8 +48,8 @@ public class HarvesterMovementBehaviour extends MovementBehaviour { @Nullable @Override - public ActorInstance createInstance(ContraptionKineticRenderer kr, MovementContext context) { - return new HarvesterActorInstance(kr, context); + public ActorInstance createInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + return new HarvesterActorInstance(materialManager, simulationWorld, context); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java index 4931fdd2d..4ca256adf 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCrafterInstance.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.components.crafter; import java.util.function.Supplier; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; @@ -15,7 +15,7 @@ import net.minecraft.util.Direction; public class MechanicalCrafterInstance extends SingleRotatingInstance { - public MechanicalCrafterInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public MechanicalCrafterInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java index 544094d8b..b353c463b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crank/HandCrankInstance.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.crank; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; @@ -20,7 +20,7 @@ public class HandCrankInstance extends SingleRotatingInstance implements IDynami private ModelData crank; private Direction facing; - public HandCrankInstance(InstancedTileRenderer modelManager, HandCrankTileEntity tile) { + public HandCrankInstance(MaterialManager modelManager, HandCrankTileEntity tile) { super(modelManager, tile); this.tile = tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java index 5060c768e..437ac1686 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerActorInstance.java @@ -3,7 +3,8 @@ package com.simibubi.create.content.contraptions.components.deployer; import static com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE; import static com.simibubi.create.content.contraptions.base.DirectionalKineticBlock.FACING; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; @@ -13,14 +14,13 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; 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.ContraptionKineticRenderer; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram; import com.simibubi.create.foundation.render.AllMaterialSpecs; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.MatrixStacker; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; @@ -41,10 +41,10 @@ public class DeployerActorInstance extends ActorInstance { ModelData hand; RotatingData shaft; - public DeployerActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { - super(modelManager, context); + public DeployerActorInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + super(materialManager, simulationWorld, context); - RenderMaterial mat = modelManager.getTransformMaterial(); + InstanceMaterial mat = materialManager.getTransformMaterial(); BlockState state = context.state; DeployerTileEntity.Mode mode = NBTHelper.readEnum(context.tileData, "Mode", DeployerTileEntity.Mode.class); @@ -62,7 +62,7 @@ public class DeployerActorInstance extends ActorInstance { hand = mat.getModel(handPose, state).createInstance(); Direction.Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state); - shaft = modelManager.getMaterial(AllMaterialSpecs.ROTATING) + shaft = materialManager.getMaterial(AllMaterialSpecs.ROTATING) .getModel(KineticTileInstance.shaft(axis)) .createInstance(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java index 2a1f112b4..5981b32d8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerInstance.java @@ -5,7 +5,7 @@ import static com.simibubi.create.content.contraptions.base.DirectionalKineticBl import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.ITickableInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; @@ -36,7 +36,7 @@ public class DeployerInstance extends ShaftInstance implements IDynamicInstance, float progress; private boolean newHand = false; - public DeployerInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public DeployerInstance(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); this.tile = (DeployerTileEntity) super.tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java index edade4430..40e045c81 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/deployer/DeployerMovementBehaviour.java @@ -8,6 +8,7 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.AllTags.AllBlockTags; @@ -16,7 +17,6 @@ import com.simibubi.create.content.contraptions.components.structureMovement.Abs import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; 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.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.schematics.ItemRequirement; @@ -268,7 +268,7 @@ public class DeployerMovementBehaviour extends MovementBehaviour { @Nullable @Override - public ActorInstance createInstance(ContraptionKineticRenderer kr, MovementContext context) { - return new DeployerActorInstance(kr, context); + public ActorInstance createInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + return new DeployerActorInstance(materialManager, simulationWorld, context); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java index 0a440e67f..5bae092ce 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/fan/FanInstance.java @@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.components.fan; import static net.minecraft.state.properties.BlockStateProperties.FACING; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -18,7 +18,7 @@ public class FanInstance extends KineticTileInstance { final Direction direction; private final Direction opposite; - public FanInstance(InstancedTileRenderer modelManager, EncasedFanTileEntity tile) { + public FanInstance(MaterialManager modelManager, EncasedFanTileEntity tile) { super(modelManager, tile); direction = blockState.get(FACING); @@ -41,7 +41,7 @@ public class FanInstance extends KineticTileInstance { } @Override - protected void update() { + public void update() { updateRotation(shaft); updateRotation(fan, getFanSpeed()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java index 059f42ea0..b3cbcb990 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlyWheelInstance.java @@ -8,9 +8,9 @@ import java.util.List; import com.google.common.collect.Lists; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -45,7 +45,7 @@ public class FlyWheelInstance extends KineticTileInstance im protected float lastAngle = Float.NaN; - public FlyWheelInstance(InstancedTileRenderer modelManager, FlywheelTileEntity tile) { + public FlyWheelInstance(MaterialManager modelManager, FlywheelTileEntity tile) { super(modelManager, tile); facing = blockState.get(HORIZONTAL_FACING); @@ -63,7 +63,7 @@ public class FlyWheelInstance extends KineticTileInstance im connectorAngleMult = flipAngle ? -1 : 1; - RenderMaterial mat = getTransformMaterial(); + InstanceMaterial mat = getTransformMaterial(); upperRotating = mat.getModel(AllBlockPartials.FLYWHEEL_UPPER_ROTATING, blockState).createInstance(); lowerRotating = mat.getModel(AllBlockPartials.FLYWHEEL_LOWER_ROTATING, blockState).createInstance(); @@ -136,7 +136,7 @@ public class FlyWheelInstance extends KineticTileInstance im } @Override - protected void update() { + public void update() { updateRotation(shaft); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java index cbfbdc0ae..1bda53f70 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/engine/EngineInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.components.flywheel.engine; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.materials.ModelData; @@ -16,7 +16,7 @@ public class EngineInstance extends TileEntityInstance { protected ModelData frame; - public EngineInstance(InstancedTileRenderer modelManager, EngineTileEntity tile) { + public EngineInstance(MaterialManager modelManager, EngineTileEntity tile) { super(modelManager, tile); Block block = blockState diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java index 84e325545..3cf4316e4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/millstone/MillStoneCogInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.millstone; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -9,7 +9,7 @@ import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; public class MillStoneCogInstance extends SingleRotatingInstance { - public MillStoneCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public MillStoneCogInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java index 490c4de1e..7aac448c8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/mixer/MixerInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.mixer; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -16,7 +16,7 @@ public class MixerInstance extends ShaftlessCogInstance implements IDynamicInsta private final OrientedData mixerPole; private final MechanicalMixerTileEntity mixer; - public MixerInstance(InstancedTileRenderer dispatcher, MechanicalMixerTileEntity tile) { + public MixerInstance(MaterialManager dispatcher, MechanicalMixerTileEntity tile) { super(dispatcher, tile); this.mixer = tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java index c4f68f4c7..866fd4fa3 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/press/PressInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.press; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.relays.encased.ShaftInstance; @@ -16,7 +16,7 @@ public class PressInstance extends ShaftInstance implements IDynamicInstance { private final OrientedData pressHead; private final MechanicalPressTileEntity press; - public PressInstance(InstancedTileRenderer dispatcher, MechanicalPressTileEntity tile) { + public PressInstance(MaterialManager dispatcher, MechanicalPressTileEntity tile) { super(dispatcher, tile); press = tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java index 0c2b57a0c..287e1b80f 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/saw/SawInstance.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.components.saw; import static net.minecraft.state.properties.BlockStateProperties.FACING; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -15,7 +15,7 @@ import net.minecraft.util.Rotation; public class SawInstance extends SingleRotatingInstance { - public SawInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public SawInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java index 5c33522eb..e2b035323 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MovementBehaviour.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement; import javax.annotation.Nullable; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; @@ -66,7 +66,7 @@ public abstract class MovementBehaviour { @OnlyIn(Dist.CLIENT) @Nullable - public ActorInstance createInstance(ContraptionKineticRenderer kr, MovementContext context) { + public ActorInstance createInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { return null; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingInstance.java index d797db75a..52febb972 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/BearingInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; @@ -23,7 +23,7 @@ public class BearingInstance e final Vector3f rotationAxis; final Quaternion blockOrientation; - public BearingInstance(InstancedTileRenderer modelManager, B tile) { + public BearingInstance(MaterialManager modelManager, B tile) { super(modelManager, tile); this.bearing = tile; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingInstance.java index dc30e3adf..9f7080e50 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingInstance.java @@ -1,11 +1,12 @@ package com.simibubi.create.content.contraptions.components.structureMovement.bearing; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; 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.ContraptionKineticRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.block.BlockState; import net.minecraft.state.properties.BlockStateProperties; @@ -21,8 +22,8 @@ public class StabilizedBearingInstance extends ActorInstance { final Vector3f rotationAxis; final Quaternion blockOrientation; - public StabilizedBearingInstance(ContraptionKineticRenderer modelManager, MovementContext context) { - super(modelManager, context); + public StabilizedBearingInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + super(materialManager, simulationWorld, context); BlockState blockState = context.state; @@ -31,7 +32,7 @@ public class StabilizedBearingInstance extends ActorInstance { blockOrientation = BearingInstance.getBlockStateOrientation(facing); - topInstance = modelManager.getOrientedMaterial().getModel(AllBlockPartials.BEARING_TOP, blockState).createInstance(); + topInstance = materialManager.getOrientedMaterial().getModel(AllBlockPartials.BEARING_TOP, blockState).createInstance(); topInstance.setPosition(context.localPos) .setRotation(blockOrientation) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java index 5b13b7f9b..a57df0205 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/bearing/StabilizedBearingMovementBehaviour.java @@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be import javax.annotation.Nullable; import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; @@ -11,7 +12,6 @@ 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.OrientedContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance; -import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionKineticRenderer; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionMatrices; import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; import com.simibubi.create.foundation.render.PartialBufferer; @@ -70,8 +70,8 @@ public class StabilizedBearingMovementBehaviour extends MovementBehaviour { @Nullable @Override - public ActorInstance createInstance(ContraptionKineticRenderer kr, MovementContext context) { - return new StabilizedBearingInstance(kr, context); + public ActorInstance createInstance(MaterialManager materialManager, PlacementSimulationWorld simulationWorld, MovementContext context) { + return new StabilizedBearingInstance(materialManager, simulationWorld, context); } static float getCounterRotationAngle(MovementContext context, Direction facing, float renderPartialTicks) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java index c6bbd204d..0653d4524 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/chassis/StickerInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.chassis; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; @@ -23,7 +23,7 @@ public class StickerInstance extends TileEntityInstance imple private final ModelData head; - public StickerInstance(InstancedTileRenderer modelManager, StickerTileEntity tile) { + public StickerInstance(MaterialManager modelManager, StickerTileEntity tile) { super(modelManager, tile); head = getTransformMaterial().getModel(AllBlockPartials.STICKER_HEAD, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java index 880400dbc..e2d3a8630 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/gantry/GantryCarriageInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.gantry; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -29,7 +29,7 @@ public class GantryCarriageInstance extends ShaftInstance implements IDynamicIns private float lastAngle = Float.NaN; - public GantryCarriageInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public GantryCarriageInstance(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); gantryCogs = getTransformMaterial() 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 new file mode 100644 index 000000000..135f57afa --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/GlueInstance.java @@ -0,0 +1,116 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.glue; + +import java.nio.ByteBuffer; + +import com.jozufozu.flywheel.backend.gl.GlPrimitive; +import com.jozufozu.flywheel.backend.instancing.ITickableInstance; +import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.entity.EntityInstance; +import com.jozufozu.flywheel.backend.model.BufferedModel; +import com.jozufozu.flywheel.backend.model.IndexedModel; +import com.jozufozu.flywheel.core.QuadConverter; +import com.jozufozu.flywheel.core.instancing.ConditionalInstance; +import com.jozufozu.flywheel.core.materials.OrientedData; +import com.simibubi.create.AllItems; +import com.simibubi.create.foundation.render.AllMaterialSpecs; +import com.simibubi.create.foundation.utility.AngleHelper; +import com.simibubi.create.foundation.utility.VecHelper; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Direction; +import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3d; + +public class GlueInstance extends EntityInstance implements ITickableInstance { + + private final Quaternion rotation; + protected ConditionalInstance model; + + public GlueInstance(MaterialManager renderer, SuperGlueEntity entity) { + super(renderer, entity); + + Instancer instancer = renderer.getMaterial(AllMaterialSpecs.ORIENTED) + .get(entity.getType(), GlueInstance::supplyModel); + model = new ConditionalInstance<>(instancer) + .withCondition(this::shouldShow) + .withSetupFunc(this::positionModel) + .update(); + + Direction face = entity.getFacingDirection(); + + rotation = new Quaternion(AngleHelper.verticalAngle(face), AngleHelper.horizontalAngleNew(face), 0, true); + } + + @Override + public void tick() { + model.update(); + } + + @Override + public void remove() { + model.delete(); + } + + private void positionModel(OrientedData model) { + + model.setPosition(getInstancePosition()) + .setRotation(rotation) + .setSkyLight(15) + .setBlockLight(15); + } + + private boolean shouldShow() { + PlayerEntity player = Minecraft.getInstance().player; + + return entity.isVisible() + || AllItems.SUPER_GLUE.isIn(player.getHeldItemMainhand()) + || AllItems.SUPER_GLUE.isIn(player.getHeldItemOffhand()); + } + + public static BufferedModel supplyModel() { + Vector3d diff = Vector3d.of(Direction.SOUTH.getDirectionVec()); + Vector3d extension = diff.normalize() + .scale(1 / 32f - 1 / 128f); + + Vector3d plane = VecHelper.axisAlingedPlaneOf(diff); + Direction.Axis axis = Direction.getFacingFromVector(diff.x, diff.y, diff.z) + .getAxis(); + + Vector3d start = Vector3d.ZERO.subtract(extension); + Vector3d end = Vector3d.ZERO.add(extension); + + plane = plane.scale(1 / 2f); + Vector3d a1 = plane.add(start); + Vector3d b1 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vector3d a2 = plane.add(start); + Vector3d b2 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vector3d a3 = plane.add(start); + Vector3d b3 = plane.add(end); + plane = VecHelper.rotate(plane, -90, axis); + Vector3d a4 = plane.add(start); + Vector3d b4 = plane.add(end); + + float[] quads = new float[] { + // x, y, z,nx, ny,nz, u, v + // inside quad + (float) a1.x, (float) a1.y, (float) a1.z, 0, -1, 0, 1, 0, + (float) a2.x, (float) a2.y, (float) a2.z, 0, -1, 0, 1, 1, + (float) a3.x, (float) a3.y, (float) a3.z, 0, -1, 0, 0, 1, + (float) a4.x, (float) a4.y, (float) a4.z, 0, -1, 0, 0, 0, + // outside quad + (float) b4.x, (float) b4.y, (float) b4.z, 0, 1, 0, 0, 0, + (float) b3.x, (float) b3.y, (float) b3.z, 0, 1, 0, 0, 1, + (float) b2.x, (float) b2.y, (float) b2.z, 0, 1, 0, 1, 1, + (float) b1.x, (float) b1.y, (float) b1.z, 0, 1, 0, 1, 0, + }; + + ByteBuffer buffer = ByteBuffer.allocate(quads.length * 4); + buffer.asFloatBuffer().put(quads); + + return new IndexedModel(GlPrimitive.TRIANGLES, AllMaterialSpecs.UNLIT_MODEL, buffer, 8, QuadConverter.getInstance().quads2Tris(2)); + } +} diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java index a66c769ba..0be88fe66 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/glue/SuperGlueEntity.java @@ -4,6 +4,7 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.Validate; +import com.jozufozu.flywheel.backend.instancing.IInstanceRendered; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllEntityTypes; import com.simibubi.create.AllItems; @@ -64,7 +65,7 @@ import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.PacketDistributor; -public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnData, ISpecialEntityItemRequirement { +public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnData, ISpecialEntityItemRequirement, IInstanceRendered { private int validationTimer; protected BlockPos hangingPosition; @@ -480,4 +481,9 @@ public class SuperGlueEntity extends Entity implements IEntityAdditionalSpawnDat public boolean doesEntityNotTriggerPressurePlate() { return true; } + + @Override + public World getWorld() { + return world; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java index 0fad406f2..b77adc308 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/AbstractPulleyInstance.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pu import java.util.Arrays; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.instancing.ConditionalInstance; import com.jozufozu.flywheel.core.instancing.GroupInstance; import com.jozufozu.flywheel.core.instancing.SelectInstance; @@ -37,7 +37,7 @@ public abstract class AbstractPulleyInstance extends ShaftInstance implements ID private byte[] sLight = new byte[1]; private GridAlignedBB volume; - public AbstractPulleyInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public AbstractPulleyInstance(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); rotatingAbout = Direction.getFacingFromAxis(Direction.AxisDirection.POSITIVE, axis); @@ -52,7 +52,8 @@ public abstract class AbstractPulleyInstance extends ShaftInstance implements ID .addModel(getHalfMagnetModel()); rope = new GroupInstance<>(getRopeModel()); - halfRope = new ConditionalInstance<>(getHalfRopeModel(), this::shouldRenderHalfRope); + halfRope = new ConditionalInstance<>(getHalfRopeModel()) + .withCondition(this::shouldRenderHalfRope); } @Override diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java index f9c8275ec..b6fb4679c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/HosePulleyInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.fluids.actors.HosePulleyTileEntity; @@ -10,7 +10,7 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; public class HosePulleyInstance extends AbstractPulleyInstance { final HosePulleyTileEntity tile = (HosePulleyTileEntity) super.tile; - public HosePulleyInstance(InstancedTileRenderer dispatcher, HosePulleyTileEntity tile) { + public HosePulleyInstance(MaterialManager dispatcher, HosePulleyTileEntity tile) { super(dispatcher, tile); beginFrame(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java index 7f8d03a7a..1fc46cab0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/pulley/RopePulleyInstance.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.contraptions.components.structureMovement.pulley; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.OrientedData; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; @@ -11,7 +11,7 @@ import com.simibubi.create.foundation.utility.AnimationTickHolder; public class RopePulleyInstance extends AbstractPulleyInstance { final PulleyTileEntity tile = (PulleyTileEntity) super.tile; - public RopePulleyInstance(InstancedTileRenderer dispatcher, PulleyTileEntity tile) { + public RopePulleyInstance(MaterialManager dispatcher, PulleyTileEntity tile) { super(dispatcher, tile); beginFrame(); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ActorInstance.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ActorInstance.java index 561d6661b..4c02741d1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ActorInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ActorInstance.java @@ -1,15 +1,19 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; +import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import net.minecraft.world.LightType; public abstract class ActorInstance { - protected final ContraptionKineticRenderer modelManager; - protected final MovementContext context; + protected final MaterialManager materialManager; + protected final PlacementSimulationWorld simulationWorld; + protected final MovementContext context; - public ActorInstance(ContraptionKineticRenderer modelManager, MovementContext context) { - this.modelManager = modelManager; + public ActorInstance(MaterialManager materialManager, PlacementSimulationWorld world, MovementContext context) { + this.materialManager = materialManager; + this.simulationWorld = world; this.context = context; } @@ -18,6 +22,6 @@ public abstract class ActorInstance { public void beginFrame() { } protected int localBlockLight() { - return modelManager.getContraption().renderWorld.getLightLevel(LightType.BLOCK, context.localPos); + return simulationWorld.getLightLevel(LightType.BLOCK, context.localPos); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java similarity index 72% rename from src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java rename to src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java index b10f10f2c..649966d05 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionInstanceManager.java @@ -7,26 +7,24 @@ import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; import com.simibubi.create.AllMovementBehaviours; -import com.simibubi.create.content.contraptions.components.actors.ActorData; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; -import com.simibubi.create.foundation.render.AllMaterialSpecs; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.feature.template.Template; -public class ContraptionKineticRenderer extends InstancedTileRenderer { +public class ContraptionInstanceManager extends TileInstanceManager { protected ArrayList actors = new ArrayList<>(); private final WeakReference contraption; - ContraptionKineticRenderer(RenderedContraption contraption) { - super(ContraptionRenderDispatcher.TILES); + ContraptionInstanceManager(RenderedContraption contraption, MaterialManager materialManager) { + super(materialManager); this.contraption = new WeakReference<>(contraption); } @@ -54,7 +52,7 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer getActorMaterial() { - return getMaterial(AllMaterialSpecs.ACTORS); - } - public RenderedContraption getContraption() { return contraption.get(); } - - @Override - public BlockPos getOriginCoordinate() { - return BlockPos.ZERO; - } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMaterialManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMaterialManager.java new file mode 100644 index 000000000..a6e6e2888 --- /dev/null +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionMaterialManager.java @@ -0,0 +1,22 @@ +package com.simibubi.create.content.contraptions.components.structureMovement.render; + +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.MaterialRenderer; +import com.jozufozu.flywheel.core.WorldContext; +import com.jozufozu.flywheel.core.shader.IProgramCallback; + +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.math.vector.Matrix4f; + +public class ContraptionMaterialManager extends MaterialManager { + public ContraptionMaterialManager(WorldContext context) { + super(context); + } + + @Override + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback callback) { + for (MaterialRenderer material : renderers) { + material.render(layer, viewProjection, camX, camY, camZ, callback); + } + } +} 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 07d228a91..c27a3ca48 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,5 +1,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.render; +import static org.lwjgl.opengl.GL11.glBindTexture; import static org.lwjgl.opengl.GL13.GL_QUADS; import static org.lwjgl.opengl.GL13.GL_TEXTURE0; import static org.lwjgl.opengl.GL13.GL_TEXTURE4; @@ -123,11 +124,11 @@ public class ContraptionRenderDispatcher { if (Backend.canUseInstancing()) { for (RenderedContraption renderer : RENDERERS.values()) { - renderer.kinetics.render(layer, viewProjection, camX, camY, camZ, renderer::setup); - renderer.teardown(); + renderer.materialManager.render(layer, viewProjection, camX, camY, camZ, renderer::setup); } } + glBindTexture(GL_TEXTURE_3D, 0); layer.endDrawing(); glDisable(GL_TEXTURE_3D); glActiveTexture(GL_TEXTURE0); 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 20432ddb5..6b5b8fbb2 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 @@ -14,6 +14,7 @@ import com.jozufozu.flywheel.backend.gl.GlPrimitive; import com.jozufozu.flywheel.backend.gl.attrib.CommonAttributes; import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat; import com.jozufozu.flywheel.backend.instancing.IInstanceRendered; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.model.ArrayModelRenderer; import com.jozufozu.flywheel.backend.model.BufferedModel; import com.jozufozu.flywheel.backend.model.IndexedModel; @@ -48,7 +49,9 @@ public class RenderedContraption extends ContraptionWorldHolder { .build(); private final ContraptionLighter lighter; - public final ContraptionKineticRenderer kinetics; + + public final MaterialManager materialManager; + public final ContraptionInstanceManager kinetics; private final Map renderLayers = new HashMap<>(); @@ -58,7 +61,8 @@ public class RenderedContraption extends ContraptionWorldHolder { public RenderedContraption(World world, PlacementSimulationWorld renderWorld, Contraption contraption) { super(contraption, renderWorld); this.lighter = contraption.makeLighter(); - this.kinetics = new ContraptionKineticRenderer(this); + this.materialManager = new ContraptionMaterialManager(ContraptionRenderDispatcher.TILES); + this.kinetics = new ContraptionInstanceManager(this, materialManager); buildLayers(); if (Backend.canUseInstancing()) { @@ -76,7 +80,6 @@ public class RenderedContraption extends ContraptionWorldHolder { if (structure != null) { setup(shader); structure.draw(); - teardown(); } } @@ -108,10 +111,6 @@ public class RenderedContraption extends ContraptionWorldHolder { lighter.lightVolume.bind(); } - void teardown() { - lighter.lightVolume.unbind(); - } - void invalidate() { for (ModelRenderer buffer : renderLayers.values()) { buffer.delete(); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java index 87b1fcacf..119c8b141 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/PumpCogInstance.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.fluids; import static net.minecraft.state.properties.BlockStateProperties.FACING; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -14,7 +14,7 @@ import net.minecraft.util.Direction; public class PumpCogInstance extends SingleRotatingInstance { - public PumpCogInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public PumpCogInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java index c50a0d5db..33632b40b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.fluids.pipes; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -23,7 +23,7 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc protected final double yRot; protected final int pointerRotationOffset; - public FluidValveInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public FluidValveInstance(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); Direction facing = blockState.get(FluidValveBlock.FACING); @@ -37,7 +37,7 @@ public class FluidValveInstance extends ShaftInstance implements IDynamicInstanc boolean twist = pipeAxis.isHorizontal() && shaftAxis == Direction.Axis.Z || pipeAxis.isVertical(); pointerRotationOffset = twist ? 90 : 0; - pointer = renderer.getTransformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); + pointer = materialManager.getTransformMaterial().getModel(AllBlockPartials.FLUID_VALVE_POINTER, blockState).createInstance(); transformPointer((FluidValveTileEntity) tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java index 9b9ceb910..510e9f125 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/belt/BeltInstance.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.function.Supplier; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.PartialModel; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -35,8 +35,8 @@ public class BeltInstance extends KineticTileInstance { protected ArrayList keys; protected RotatingData pulleyKey; - public BeltInstance(InstancedTileRenderer modelManager, BeltTileEntity tile) { - super(modelManager, tile); + public BeltInstance(MaterialManager materialManager, BeltTileEntity tile) { + super(materialManager, tile); if (!AllBlocks.BELT.has(blockState)) return; @@ -61,7 +61,7 @@ public class BeltInstance extends KineticTileInstance { PartialModel beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom); SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom); - Instancer beltModel = modelManager.getMaterial(AllMaterialSpecs.BELTS).getModel(beltPartial, blockState); + Instancer beltModel = materialManager.getMaterial(AllMaterialSpecs.BELTS).getModel(beltPartial, blockState); keys.add(setup(beltModel.createInstance(), bottom, spriteShift)); diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java index eb7185fc7..0761c6e43 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/ShaftInstance.java @@ -1,6 +1,6 @@ package com.simibubi.create.content.contraptions.relays.encased; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; @@ -8,7 +8,7 @@ import net.minecraft.block.BlockState; public class ShaftInstance extends SingleRotatingInstance { - public ShaftInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public ShaftInstance(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java index 23ff796fc..9dfd819d0 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/encased/SplitShaftInstance.java @@ -3,9 +3,9 @@ package com.simibubi.create.content.contraptions.relays.encased; import java.util.ArrayList; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.IRotate; import com.simibubi.create.content.contraptions.base.KineticTileInstance; @@ -19,14 +19,14 @@ public class SplitShaftInstance extends KineticTileInstance keys; - public SplitShaftInstance(InstancedTileRenderer modelManager, SplitShaftTileEntity tile) { + public SplitShaftInstance(MaterialManager modelManager, SplitShaftTileEntity tile) { super(modelManager, tile); keys = new ArrayList<>(2); float speed = tile.getSpeed(); - RenderMaterial rotatingMaterial = getRotatingMaterial(); + InstanceMaterial rotatingMaterial = getRotatingMaterial(); for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java index d054e653e..de3a27ed8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeInstance.java @@ -3,8 +3,8 @@ package com.simibubi.create.content.contraptions.relays.gauge; import java.util.ArrayList; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -24,7 +24,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns protected MatrixStack ms; - protected GaugeInstance(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + protected GaugeInstance(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); faces = new ArrayList<>(2); @@ -144,7 +144,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns } public static class Speed extends GaugeInstance { - public Speed(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public Speed(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); } @@ -155,7 +155,7 @@ public abstract class GaugeInstance extends ShaftInstance implements IDynamicIns } public static class Stress extends GaugeInstance { - public Stress(InstancedTileRenderer dispatcher, KineticTileEntity tile) { + public Stress(MaterialManager dispatcher, KineticTileEntity tile) { super(dispatcher, tile); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java index d26ec2b62..fc795f92e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gearbox/GearboxInstance.java @@ -4,9 +4,9 @@ import java.util.EnumMap; import java.util.Map; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileInstance; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -22,7 +22,7 @@ public class GearboxInstance extends KineticTileInstance { protected final EnumMap keys; protected Direction sourceFacing; - public GearboxInstance(InstancedTileRenderer modelManager, GearboxTileEntity tile) { + public GearboxInstance(MaterialManager modelManager, GearboxTileEntity tile) { super(modelManager, tile); keys = new EnumMap<>(Direction.class); @@ -33,7 +33,7 @@ public class GearboxInstance extends KineticTileInstance { int skyLight = world.getLightLevel(LightType.SKY, pos); updateSourceFacing(); - RenderMaterial rotatingMaterial = getRotatingMaterial(); + InstanceMaterial rotatingMaterial = getRotatingMaterial(); for (Direction direction : Iterate.directions) { final Direction.Axis axis = direction.getAxis(); diff --git a/src/main/java/com/simibubi/create/content/curiosities/armor/CopperBacktankInstance.java b/src/main/java/com/simibubi/create/content/curiosities/armor/CopperBacktankInstance.java index 6cedfac43..dda0ab339 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/armor/CopperBacktankInstance.java +++ b/src/main/java/com/simibubi/create/content/curiosities/armor/CopperBacktankInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.curiosities.armor; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.RotatingData; @@ -9,7 +9,7 @@ import com.simibubi.create.content.contraptions.base.SingleRotatingInstance; public class CopperBacktankInstance extends SingleRotatingInstance { - public CopperBacktankInstance(InstancedTileRenderer modelManager, KineticTileEntity tile) { + public CopperBacktankInstance(MaterialManager modelManager, KineticTileEntity tile) { super(modelManager, tile); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java b/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java index b280b10c3..bccafee0a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java +++ b/src/main/java/com/simibubi/create/content/curiosities/projector/ChromaticProjectorInstance.java @@ -1,13 +1,13 @@ package com.simibubi.create.content.curiosities.projector; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.simibubi.create.foundation.render.effects.EffectsHandler; public class ChromaticProjectorInstance extends TileEntityInstance implements IDynamicInstance { - public ChromaticProjectorInstance(InstancedTileRenderer renderer, ChromaticProjectorTileEntity tile) { + public ChromaticProjectorInstance(MaterialManager renderer, ChromaticProjectorTileEntity tile) { super(renderer, tile); } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java b/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java index 25d0e0b6a..73ca73d70 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/FlapData.java @@ -7,6 +7,7 @@ import com.jozufozu.flywheel.core.materials.IFlatLight; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector3f; +import net.minecraft.util.math.vector.Vector3i; public class FlapData extends InstanceData implements IFlatLight { @@ -43,7 +44,7 @@ public class FlapData extends InstanceData implements IFlatLight { } public FlapData setPosition(int x, int y, int z) { - BlockPos origin = owner.renderer.getOriginCoordinate(); + Vector3i origin = owner.originCoordinate.get(); return setPosition((float) (x - origin.getX()), (float) (y - origin.getY()), diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java index b9ba09d16..f4ddab828 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java @@ -7,8 +7,8 @@ import java.util.Map; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.logistics.block.FlapData; @@ -23,7 +23,7 @@ public class BeltTunnelInstance extends TileEntityInstance private final Map> tunnelFlaps; - public BeltTunnelInstance(InstancedTileRenderer modelManager, BeltTunnelTileEntity tile) { + public BeltTunnelInstance(MaterialManager modelManager, BeltTunnelTileEntity tile) { super(modelManager, tile); tunnelFlaps = new EnumMap<>(Direction.class); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java index 80ae1ac06..8fc2a0883 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.logistics.block.depot; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -19,7 +19,7 @@ public class EjectorInstance extends ShaftInstance implements IDynamicInstance { private float lastProgress = Float.NaN; - public EjectorInstance(InstancedTileRenderer dispatcher, EjectorTileEntity tile) { + public EjectorInstance(MaterialManager dispatcher, EjectorTileEntity tile) { super(dispatcher, tile); this.tile = tile; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java index b28877f05..0b6dfdbc5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/diodes/AdjustableRepeaterInstance.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.logistics.block.diodes; import com.jozufozu.flywheel.backend.instancing.ITickableInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; @@ -15,7 +15,7 @@ public class AdjustableRepeaterInstance extends TileEntityInstance modelManager, AdjustableRepeaterTileEntity tile) { + public AdjustableRepeaterInstance(MaterialManager modelManager, AdjustableRepeaterTileEntity tile) { super(modelManager, tile); indicator = modelManager.getTransformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java index df5270be5..f19262374 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelInstance.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; import com.jozufozu.flywheel.backend.instancing.Instancer; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.AllBlockPartials; @@ -20,7 +20,7 @@ public class FunnelInstance extends TileEntityInstance impleme private final ArrayList flaps; - public FunnelInstance(InstancedTileRenderer modelManager, FunnelTileEntity tile) { + public FunnelInstance(MaterialManager modelManager, FunnelTileEntity tile) { super(modelManager, tile); flaps = new ArrayList<>(4); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java index 293bb2f57..09c1d7242 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmInstance.java @@ -5,9 +5,9 @@ import java.util.ArrayList; import com.google.common.collect.Lists; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; import com.jozufozu.flywheel.backend.instancing.InstanceData; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; import com.jozufozu.flywheel.backend.instancing.Instancer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.AllBlockPartials; @@ -44,10 +44,10 @@ public class ArmInstance extends SingleRotatingInstance implements IDynamicInsta private float upperArmAngle = Float.NaN; private float headAngle = Float.NaN; - public ArmInstance(InstancedTileRenderer modelManager, ArmTileEntity tile) { + public ArmInstance(MaterialManager modelManager, ArmTileEntity tile) { super(modelManager, tile); - RenderMaterial mat = getTransformMaterial(); + InstanceMaterial mat = getTransformMaterial(); base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance(); lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java index b80f946e7..c07d2c612 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverInstance.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.logistics.block.redstone; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; @@ -23,10 +23,10 @@ public class AnalogLeverInstance extends TileEntityInstance modelManager, AnalogLeverTileEntity tile) { + public AnalogLeverInstance(MaterialManager modelManager, AnalogLeverTileEntity tile) { super(modelManager, tile); - RenderMaterial mat = getTransformMaterial(); + InstanceMaterial mat = getTransformMaterial(); handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance(); indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java index 1c647775d..f579ccb94 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonInstance.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.schematics.block; import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderer; -import com.jozufozu.flywheel.backend.instancing.RenderMaterial; +import com.jozufozu.flywheel.backend.instancing.InstanceMaterial; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.TileEntityInstance; import com.jozufozu.flywheel.core.materials.ModelData; import com.mojang.blaze3d.matrix.MatrixStack; @@ -17,10 +17,10 @@ public class SchematicannonInstance extends TileEntityInstance modelManager, SchematicannonTileEntity tile) { + public SchematicannonInstance(MaterialManager modelManager, SchematicannonTileEntity tile) { super(modelManager, tile); - RenderMaterial mat = getTransformMaterial(); + InstanceMaterial mat = getTransformMaterial(); connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance(); pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance(); diff --git a/src/main/java/com/simibubi/create/events/ClientEvents.java b/src/main/java/com/simibubi/create/events/ClientEvents.java index 1a89e89ab..b969f60c9 100644 --- a/src/main/java/com/simibubi/create/events/ClientEvents.java +++ b/src/main/java/com/simibubi/create/events/ClientEvents.java @@ -5,8 +5,7 @@ import java.util.List; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.RenderWork; -import com.jozufozu.flywheel.core.WorldTileRenderer; -import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllFluids; @@ -157,7 +156,7 @@ public class ClientEvents { if (world.isRemote() && world instanceof ClientWorld && !(world instanceof WrappedClientWorld)) { CreateClient.invalidateRenderers(world); AnimationTickHolder.reset(); - WorldTileRenderer renderer = Backend.tileRenderer.get(world); + TileInstanceManager renderer = Backend.tileInstanceManager.get(world); renderer.invalidate(); ((ClientWorld) world).loadedTileEntityList.forEach(renderer::add); } diff --git a/src/main/java/com/simibubi/create/foundation/command/AllCommands.java b/src/main/java/com/simibubi/create/foundation/command/AllCommands.java index 81b4a5f5a..ee58c121a 100644 --- a/src/main/java/com/simibubi/create/foundation/command/AllCommands.java +++ b/src/main/java/com/simibubi/create/foundation/command/AllCommands.java @@ -33,6 +33,7 @@ public class AllCommands { .then(ConfigCommand.register()) .then(PonderCommand.register()) .then(CloneCommand.register()) + .then(GlueCommand.register()) // utility .then(util) diff --git a/src/main/java/com/simibubi/create/foundation/command/GlueCommand.java b/src/main/java/com/simibubi/create/foundation/command/GlueCommand.java new file mode 100644 index 000000000..269d52023 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/command/GlueCommand.java @@ -0,0 +1,32 @@ +package com.simibubi.create.foundation.command; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.simibubi.create.content.contraptions.components.structureMovement.glue.SuperGlueEntity; + +import net.minecraft.command.CommandSource; +import net.minecraft.command.Commands; +import net.minecraft.command.arguments.BlockPosArgument; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.server.ServerWorld; + +public class GlueCommand { + public static ArgumentBuilder register() { + return Commands.literal("glue") + .requires(cs -> cs.hasPermissionLevel(0)) + .then(Commands.argument("pos", BlockPosArgument.blockPos()) + //.then(Commands.argument("direction", EnumArgument.enumArgument(Direction.class)) + .executes(ctx -> { + BlockPos pos = BlockPosArgument.getBlockPos(ctx, "pos"); + + ServerWorld world = ctx.getSource().getWorld(); + SuperGlueEntity entity = new SuperGlueEntity(world, pos, Direction.UP); + + entity.playPlaceSound(); + world.addEntity(entity); + + return 1; + })); + + } +} diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java b/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java index 151c9097b..7a5b0cd7c 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java @@ -2,8 +2,8 @@ package com.simibubi.create.foundation.data; import javax.annotation.Nullable; -import com.jozufozu.flywheel.backend.instancing.IRendererFactory; -import com.jozufozu.flywheel.backend.instancing.InstancedTileRenderRegistry; +import com.jozufozu.flywheel.backend.instancing.ITileInstanceFactory; +import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import com.tterrag.registrate.AbstractRegistrate; import com.tterrag.registrate.builders.BuilderCallback; import com.tterrag.registrate.builders.TileEntityBuilder; @@ -20,7 +20,7 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; public class CreateTileEntityBuilder extends TileEntityBuilder { @Nullable - private NonNullSupplier> instanceFactory; + private NonNullSupplier> instanceFactory; public static TileEntityBuilder create(AbstractRegistrate owner, P parent, String name, BuilderCallback callback, NonNullFunction, ? extends T> factory) { @@ -32,7 +32,7 @@ public class CreateTileEntityBuilder extends TileEntity super(owner, parent, name, callback, factory); } - public CreateTileEntityBuilder instance(NonNullSupplier> instanceFactory) { + public CreateTileEntityBuilder instance(NonNullSupplier> instanceFactory) { if (this.instanceFactory == null) { DistExecutor.runWhenOn(Dist.CLIENT, () -> this::registerInstance); } @@ -44,9 +44,9 @@ public class CreateTileEntityBuilder extends TileEntity protected void registerInstance() { OneTimeEventReceiver.addModListener(FMLClientSetupEvent.class, ($) -> { - NonNullSupplier> instanceFactory = this.instanceFactory; + NonNullSupplier> instanceFactory = this.instanceFactory; if (instanceFactory != null) { - InstancedTileRenderRegistry.getInstance().register(getEntry(), instanceFactory.get()); + InstancedRenderRegistry.getInstance().register(getEntry(), instanceFactory.get()); } }); diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/CancelEntityRenderMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/CancelEntityRenderMixin.java new file mode 100644 index 000000000..53d6f3efc --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/CancelEntityRenderMixin.java @@ -0,0 +1,31 @@ +package com.simibubi.create.foundation.mixin.flywheel; + +import java.util.ArrayList; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.google.common.collect.Lists; +import com.jozufozu.flywheel.backend.Backend; +import com.jozufozu.flywheel.backend.instancing.IInstanceRendered; + +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; + +@Mixin(ClientWorld.class) +public class CancelEntityRenderMixin { + + @Inject(at = @At("RETURN"), method = "getAllEntities", cancellable = true) + private void filterEntities(CallbackInfoReturnable> cir) { + if (Backend.canUseInstancing()) { + Iterable entities = cir.getReturnValue(); + + ArrayList list = Lists.newArrayList(entities); + list.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderNormally()); + + cir.setReturnValue(list); + } + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java index e115f833e..39bfa9433 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/RenderHooksMixin.java @@ -94,7 +94,7 @@ public class RenderHooksMixin { @Inject(at = @At("TAIL"), method = "scheduleBlockRerenderIfNeeded") private void checkUpdate(BlockPos pos, BlockState lastState, BlockState newState, CallbackInfo ci) { - Backend.tileRenderer.get(world) + Backend.tileInstanceManager.get(world) .update(world.getTileEntity(pos)); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java index 66a6960ae..bf5d14abf 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileRemoveMixin.java @@ -24,7 +24,7 @@ public class TileRemoveMixin { @Inject(at = @At("TAIL"), method = "remove") private void onRemove(CallbackInfo ci) { if (world instanceof ClientWorld) - Backend.tileRenderer.get(this.world) + Backend.tileInstanceManager.get(this.world) .remove((TileEntity) (Object) this); } } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java index 63bc66a82..0ec98abcc 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/TileWorldHookMixin.java @@ -11,8 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.jozufozu.flywheel.backend.Backend; -import com.jozufozu.flywheel.core.WorldTileRenderer; -import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.backend.instancing.TileInstanceManager; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; @@ -36,7 +35,7 @@ public class TileWorldHookMixin { @Inject(at = @At("TAIL"), method = "addTileEntity") private void onAddTile(TileEntity te, CallbackInfoReturnable cir) { if (isRemote) { - Backend.tileRenderer.get(self) + Backend.tileInstanceManager.get(self) .queueAdd(te); } } @@ -47,7 +46,7 @@ public class TileWorldHookMixin { @Inject(at = @At(value = "INVOKE", target = "Ljava/util/Set;clear()V", ordinal = 0), method = "tickBlockEntities") private void onChunkUnload(CallbackInfo ci) { if (isRemote) { - WorldTileRenderer kineticRenderer = Backend.tileRenderer.get(self); + TileInstanceManager kineticRenderer = Backend.tileInstanceManager.get(self); for (TileEntity tile : tileEntitiesToBeRemoved) { kineticRenderer.remove(tile); } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java index d08a6d67e..1f8b0b6ef 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/LightUpdateMixin.java @@ -46,7 +46,7 @@ public abstract class LightUpdateMixin extends AbstractChunkProvider { .getY()) == sectionY) .map(Map.Entry::getValue) .forEach(tile -> { - Backend.tileRenderer.get(world) + Backend.tileInstanceManager.get(world) .onLightUpdate(tile); }); } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java index b87465381..bccbe7822 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/flywheel/light/NetworkLightUpdateMixin.java @@ -36,7 +36,7 @@ public class NetworkLightUpdateMixin { chunk.getTileEntityMap() .values() .forEach(tile -> { - Backend.tileRenderer.get(world) + Backend.tileInstanceManager.get(world) .onLightUpdate(tile); }); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java index 7f65c17e3..634da56bd 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java @@ -21,14 +21,11 @@ import net.minecraft.util.Direction; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.SectionPos; import net.minecraft.util.registry.DynamicRegistries; import net.minecraft.world.ITickList; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.AbstractChunkProvider; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.lighting.WorldLightManager; import net.minecraft.world.storage.ISpawnWorldInfo; import net.minecraft.world.storage.MapData; @@ -38,7 +35,7 @@ import net.minecraft.world.storage.MapData; public class WrappedWorld extends World { protected World world; - private AbstractChunkProvider provider; + protected AbstractChunkProvider provider; public WrappedWorld(World world, AbstractChunkProvider provider) { super((ISpawnWorldInfo) world.getWorldInfo(), world.getRegistryKey(), world.getDimension(), world::getProfiler, diff --git a/src/main/resources/assets/flywheel/flywheel/shaders/model.vert b/src/main/resources/assets/flywheel/flywheel/shaders/model.vert index 310815b56..efdfbf804 100644 --- a/src/main/resources/assets/flywheel/flywheel/shaders/model.vert +++ b/src/main/resources/assets/flywheel/flywheel/shaders/model.vert @@ -1,6 +1,9 @@ #flwbuiltins #flwinclude <"flywheel:core/diffuse.glsl"> +#flwinclude <"flywheel:data/modelvertex.glsl"> +#flwinclude <"flywheel:data/blockfragment.glsl"> + #[InstanceData] struct Instance { vec2 light; @@ -9,9 +12,6 @@ struct Instance { mat3 normalMat; }; -#flwinclude <"flywheel:data/modelvertex.glsl"> -#flwinclude <"flywheel:data/blockfragment.glsl"> - BlockFrag FLWMain(Vertex v, Instance i) { vec4 worldPos = i.transform * vec4(v.pos, 1.); diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 11a1c034f..4cb235d96 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -7,14 +7,14 @@ "mixins": [ ], "client": [ - "EntityContraptionInteractionMixin", - "FixNormalScalingMixin", - "HeavyBootsOnPlayerMixin", - "WindowResizeMixin", - "ModelDataRefreshMixin", "BreakProgressMixin", "ChromaticProjectorHooksMixin", "EntityContraptionInteractionMixin", + "FixNormalScalingMixin", + "HeavyBootsOnPlayerMixin", + "ModelDataRefreshMixin", + "WindowResizeMixin", + "flywheel.CancelEntityRenderMixin", "flywheel.CancelTileEntityRenderMixin", "flywheel.FogColorTrackerMixin", "flywheel.RenderHooksMixin",