Start working on instanced enti- oh wait I've got to do all this other stuff first

- Separate model-level instance management from object-level instance management
 - Separate material management from rendering
 - A few things here and there related to entity instancing
 - Add a rudimentary command to spawn superglue
This commit is contained in:
JozsefA 2021-06-03 21:23:06 -07:00
parent d7ed765dde
commit bef6d77a59
95 changed files with 862 additions and 462 deletions

View file

@ -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<WorldTileRenderer<WorldProgram>> tileRenderer = new WorldAttached<>(() -> new WorldTileRenderer<>(WorldContext.INSTANCE));
public static LazyValue<Vector<CrumblingRenderer>> blockBreaking = new LazyValue<>(() -> {
Vector<CrumblingRenderer> renderers = new Vector<>(10);
public static WorldAttached<TileInstanceManager> tileInstanceManager = new WorldAttached<>(world -> new TileInstanceManager(WorldContext.INSTANCE.getMaterialManager(world)));
public static LazyValue<Vector<CrumblingInstanceManager>> blockBreaking = new LazyValue<>(() -> {
Vector<CrumblingInstanceManager> 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<WorldProgram> 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<WorldProgram> 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<WorldProgram> renderer = tileRenderer.get(world);
MaterialManager<WorldProgram> 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<SortedSet<DestroyBlockProgress>> breakingProgressions = worldRenderer.blockBreakingProgressions;
if (breakingProgressions.isEmpty()) return;
Vector<CrumblingRenderer> renderers = blockBreaking.getValue();
Vector<CrumblingInstanceManager> 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() {

View file

@ -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<String> 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<ResourceLocation, String> shaderSource = new HashMap<>();
private boolean shouldCrash;
private final Gson gson = new GsonBuilder().create();
void onResourceManagerReload(IResourceManager manager, Predicate<IResourceType> predicate) {
@Override
public void onResourceManagerReload(IResourceManager manager, Predicate<IResourceType> predicate) {
if (predicate.test(VanillaResourceType.SHADERS)) {
OptifineHandler.refresh();
Backend.refresh();

View file

@ -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 {

View file

@ -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();
}

View file

@ -1,8 +0,0 @@
package com.jozufozu.flywheel.backend.instancing;
import net.minecraft.tileentity.TileEntity;
@FunctionalInterface
public interface IRendererFactory<T extends TileEntity> {
TileEntityInstance<? super T> create(InstancedTileRenderer<?> manager, T te);
}

View file

@ -0,0 +1,8 @@
package com.jozufozu.flywheel.backend.instancing;
import net.minecraft.tileentity.TileEntity;
@FunctionalInterface
public interface ITileInstanceFactory<T extends TileEntity> {
TileEntityInstance<? super T> create(MaterialManager<?> manager, T te);
}

View file

@ -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<P extends WorldProgram, D extends InstanceData> {
public class InstanceMaterial<D extends InstanceData> {
protected final InstancedTileRenderer<P> renderer;
protected final Supplier<Vector3i> originCoordinate;
protected final Cache<Object, Instancer<D>> models;
protected final MaterialSpec<D> spec;
private final VertexFormat modelFormat;
public RenderMaterial(InstancedTileRenderer<P> renderer, MaterialSpec<D> spec) {
this.renderer = renderer;
public InstanceMaterial(Supplier<Vector3i> renderer, MaterialSpec<D> spec) {
this.originCoordinate = renderer;
this.spec = spec;
this.models = CacheBuilder.newBuilder()
@ -55,35 +53,21 @@ public class RenderMaterial<P extends WorldProgram, D extends InstanceData> {
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<P> 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<Instancer<D>> f) {
public void forEachInstancer(Consumer<Instancer<D>> f) {
for (Instancer<D> model : models.asMap().values()) {
f.accept(model);
}
@ -106,31 +90,30 @@ public class RenderMaterial<P extends WorldProgram, D extends InstanceData> {
return get(toRender, () -> buildModel(toRender));
}
public Instancer<D> get(Object key, Supplier<Instancer<D>> supplier) {
public Instancer<D> get(Object key, Supplier<BufferedModel> 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<D> buildModel(BlockState renderedState) {
private BufferedModel buildModel(BlockState renderedState) {
BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher();
return buildModel(dispatcher.getModelForState(renderedState), renderedState);
}
private Instancer<D> buildModel(IBakedModel model, BlockState renderedState) {
private BufferedModel buildModel(IBakedModel model, BlockState renderedState) {
return buildModel(model, renderedState, new MatrixStack());
}
private Instancer<D> 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<P extends WorldProgram, D extends InstanceData> {
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;

View file

@ -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<TileEntityType<?>, IRendererFactory<?>> renderers = Maps.newHashMap();
private final Map<TileEntityType<?>, ITileInstanceFactory<?>> renderers = Maps.newHashMap();
public <T extends TileEntity> void register(TileEntityType<? extends T> type, IRendererFactory<? super T> rendererFactory) {
public <T extends TileEntity> void register(TileEntityType<? extends T> type, ITileInstanceFactory<? super T> rendererFactory) {
this.renderers.put(type, rendererFactory);
}
@SuppressWarnings("unchecked")
@Nullable
public <T extends TileEntity> TileEntityInstance<? super T> create(InstancedTileRenderer<?> manager, T tile) {
public <T extends TileEntity> TileEntityInstance<? super T> create(MaterialManager<?> manager, T tile) {
TileEntityType<?> type = tile.getType();
IRendererFactory<? super T> factory = (IRendererFactory<? super T>) this.renderers.get(type);
ITileInstanceFactory<? super T> factory = (ITileInstanceFactory<? super T>) this.renderers.get(type);
if (factory == null) return null;
else return factory.create(manager, tile);

View file

@ -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<D extends InstanceData> {
public final InstancedTileRenderer<?> renderer;
public final Supplier<Vector3i> originCoordinate;
protected final BufferedModel model;
@ -32,11 +35,11 @@ public class Instancer<D extends InstanceData> {
boolean anyToRemove;
boolean anyToUpdate;
public Instancer(BufferedModel model, InstancedTileRenderer<?> renderer, VertexFormat instanceFormat, IInstanceFactory<D> factory) {
public Instancer(BufferedModel model, Supplier<Vector3i> originCoordinate, MaterialSpec<D> 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<D extends InstanceData> {
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;

View file

@ -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<P extends WorldProgram> {
public static int MAX_ORIGIN_DISTANCE = 100;
protected final ArrayList<MaterialRenderer<P>> renderers;
protected final Map<ResourceLocation, InstanceMaterial<?>> materials;
private BlockPos originCoordinate = BlockPos.ZERO;
private final WeakHashSet<OriginShiftListener> listeners;
public MaterialManager(WorldContext<P> 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<P> 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<P> 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<P> material : renderers) {
material.render(layer, translate, camX, camY, camZ, callback);
}
}
public void delete() {
for (InstanceMaterial<?> material : materials.values()) {
material.delete();
}
}
@SuppressWarnings("unchecked")
public <D extends InstanceData> InstanceMaterial<D> getMaterial(MaterialSpec<D> materialType) {
return (InstanceMaterial<D>) materials.get(materialType.name);
}
public InstanceMaterial<ModelData> getTransformMaterial() {
return getMaterial(AllMaterialSpecs.TRANSFORMED);
}
public InstanceMaterial<OrientedData> 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();
}
}

View file

@ -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<P extends WorldProgram> {
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<P> 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);
}
}

View file

@ -21,7 +21,7 @@ public class MaterialSpec<D extends InstanceData> {
this.instanceFactory = instanceFactory;
}
public ResourceLocation getProgramSpec() {
public ResourceLocation getProgramName() {
return programSpec;
}

View file

@ -32,20 +32,20 @@ import net.minecraft.world.World;
*/
public abstract class TileEntityInstance<T extends TileEntity> 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<T extends TileEntity> implements IInsta
*
* <br><br> 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<T extends TileEntity> implements IInsta
/**
* Free any acquired resources.
*
* <br> eg. call {@link InstanceKey#delete()}.
*/
public abstract void remove();
/**
* Just before {@link #update()} would be called, <code>shouldReset()</code> is checked.
* If this function returns <code>true</code>, then this instance will be {@link #remove}d,
* If this function returns <code>true</code>, 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<T extends TileEntity> 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<T extends TileEntity> implements IInsta
models.forEach(model -> model.setBlockLight(block).setSkyLight(sky));
}
protected RenderMaterial<?, ModelData> getTransformMaterial() {
return renderer.getTransformMaterial();
protected InstanceMaterial<ModelData> getTransformMaterial() {
return materialManager.getTransformMaterial();
}
protected RenderMaterial<?, OrientedData> getOrientedMaterial() {
return renderer.getOrientedMaterial();
protected InstanceMaterial<OrientedData> getOrientedMaterial() {
return materialManager.getOrientedMaterial();
}
}

View file

@ -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<P extends WorldProgram> {
public class TileInstanceManager implements MaterialManager.OriginShiftListener {
public final WorldContext<P> context;
protected final Map<MaterialSpec<?>, RenderMaterial<P, ?>> materials;
public final MaterialManager<?> materialManager;
protected final ArrayList<TileEntity> queuedAdditions;
protected final ConcurrentHashMap.KeySetView<TileEntity, Boolean> queuedUpdates;
@ -40,23 +30,17 @@ public abstract class InstancedTileRenderer<P extends WorldProgram> {
protected int frame;
protected int tick;
protected InstancedTileRenderer(WorldContext<P> 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<P extends WorldProgram> {
}
}
/**
* 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<P> callback) {
for (RenderMaterial<P, ?> material : materials.values()) {
material.render(layer, viewProjection, camX, camY, camZ, callback);
}
}
@SuppressWarnings("unchecked")
public <D extends InstanceData> RenderMaterial<P, D> getMaterial(MaterialSpec<D> materialType) {
return (RenderMaterial<P, D>) materials.get(materialType);
}
public RenderMaterial<P, ModelData> getTransformMaterial() {
return getMaterial(AllMaterialSpecs.TRANSFORMED);
}
public RenderMaterial<P, OrientedData> getOrientedMaterial() {
return getMaterial(AllMaterialSpecs.ORIENTED);
@Override
public void onOriginShift() {
ArrayList<TileEntity> instancedTiles = new ArrayList<>(instances.keySet());
invalidate();
instancedTiles.forEach(this::add);
}
@SuppressWarnings("unchecked")
@ -267,7 +222,7 @@ public abstract class InstancedTileRenderer<P extends WorldProgram> {
}
private <T extends TileEntity> TileEntityInstance<? super T> createInternal(T tile) {
TileEntityInstance<? super T> renderer = InstancedTileRenderRegistry.getInstance().create(this, tile);
TileEntityInstance<? super T> renderer = InstancedRenderRegistry.getInstance().create(materialManager, tile);
if (renderer != null) {
renderer.updateLight();
@ -284,9 +239,6 @@ public abstract class InstancedTileRenderer<P extends WorldProgram> {
}
public void invalidate() {
for (RenderMaterial<?, ?> material : materials.values()) {
material.delete();
}
instances.clear();
dynamicInstances.clear();
tickableInstances.clear();

View file

@ -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.
**
* <br><br> There are a few additional features that overriding classes can opt in to:
* <ul>
* <li>{@link IDynamicInstance}</li>
* <li>{@link ITickableInstance}</li>
* </ul>
* See the interfaces' documentation for more information about each one.
*
* <br> 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 <E> The type of {@link Entity} your class is an instance of.
*/
public abstract class EntityInstance<E extends Entity> 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 <L extends IFlatLight<?>> void relight(BlockPos pos, Stream<L> 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 <L extends IFlatLight<?>> void relight(int block, int sky, Stream<L> models) {
models.forEach(model -> model.setBlockLight(block).setSkyLight(sky));
}
protected InstanceMaterial<ModelData> getTransformMaterial() {
return materialManager.getTransformMaterial();
}
protected InstanceMaterial<OrientedData> getOrientedMaterial() {
return materialManager.getOrientedMaterial();
}
}

View file

@ -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<E extends Entity> {
EntityInstance<? super E> create(MaterialManager<?> manager, E te);
}

View file

@ -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;
}
}

View file

@ -1,14 +0,0 @@
package com.jozufozu.flywheel.core;
import net.minecraft.util.math.BlockPos;
public class CrumblingRenderer extends WorldTileRenderer<CrumblingProgram> {
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;
}
}

View file

@ -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<P extends WorldProgram> extends ShaderContext<P> {
@ -37,13 +40,16 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(new ResourceLocation(Flywheel.ID, "context/crumbling"), CrumblingProgram::new);
protected final ResourceLocation name;
private final ExtensibleGlProgram.Factory<P> factory;
protected Supplier<Stream<ResourceLocation>> specStream;
protected TemplateFactory templateFactory;
public final WorldAttached<MaterialManager<P>> materialManager = new WorldAttached<>($ -> new MaterialManager<>(this));
private final Map<ShaderType, ResourceLocation> builtins = new EnumMap<>(ShaderType.class);
private final Map<ShaderType, String> builtinSources = new EnumMap<>(ShaderType.class);
private final ExtensibleGlProgram.Factory<P> factory;
public WorldContext(ResourceLocation root, ExtensibleGlProgram.Factory<P> factory) {
this.factory = factory;
this.name = root;
@ -52,11 +58,15 @@ public class WorldContext<P extends WorldProgram> extends ShaderContext<P> {
specStream = () -> Backend.allMaterials()
.stream()
.map(MaterialSpec::getProgramSpec);
.map(MaterialSpec::getProgramName);
templateFactory = InstancedArraysTemplate::new;
}
public MaterialManager<P> getMaterialManager(IWorld world) {
return materialManager.get(world);
}
public WorldContext<P> setSpecStream(Supplier<Stream<ResourceLocation>> specStream) {
this.specStream = specStream;
return this;

View file

@ -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<P extends WorldProgram> extends InstancedTileRenderer<P> {
public static int MAX_ORIGIN_DISTANCE = 100;
public BlockPos originCoordinate = BlockPos.ZERO;
public WorldTileRenderer(WorldContext<P> 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<TileEntity> 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<P> 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);
}
}

View file

@ -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<D extends InstanceData> {
final Instancer<D> model;
Condition condition;
ICondition condition;
Consumer<D> setupFunc;
@Nullable
private D instance;
public ConditionalInstance(Instancer<D> model, Condition condition) {
public ConditionalInstance(Instancer<D> model) {
this.model = model;
this.condition = condition;
this.condition = () -> true;
update();
}
public ConditionalInstance<D> setCondition(Condition condition) {
public ConditionalInstance<D> withSetupFunc(Consumer<D> setupFunc) {
this.setupFunc = setupFunc;
return this;
}
public ConditionalInstance<D> withCondition(ICondition condition) {
this.condition = condition;
return this;
}
@ -31,6 +39,7 @@ public class ConditionalInstance<D extends InstanceData> {
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<D extends InstanceData> {
}
@FunctionalInterface
public interface Condition {
public interface ICondition {
boolean shouldShow();
}
}

View file

@ -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<BasicData> {
public abstract class BasicData extends InstanceData implements IFlatLight<BasicData> {
protected byte blockLight;
protected byte skyLight;

View file

@ -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());
}

View file

@ -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<T> {
Map<IWorld, T> attached;
private final NonNullSupplier<T> factory;
private final WorldAttacher<T> factory;
public WorldAttached(NonNullSupplier<T> factory) {
public WorldAttached(WorldAttacher<T> factory) {
this.factory = factory;
attached = new HashMap<>();
}
@ -24,7 +24,7 @@ public class WorldAttached<T> {
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<T> {
.forEach(consumer);
}
@FunctionalInterface
public interface WorldAttacher<T> extends Function<IWorld, T> {
@Nonnull
T attach(IWorld world);
@Override
default T apply(IWorld world) {
return attach(world);
}
}
}

View file

@ -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();

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -81,7 +81,6 @@ public class KineticData extends BasicData {
return this;
}
@Override
public void write(MappedBuffer buf) {
super.write(buf);

View file

@ -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<T extends KineticTileEntity> 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<T extends KineticTileEntity> extends T
return shaft(getRotationAxis());
}
protected final RenderMaterial<?, RotatingData> getRotatingMaterial() {
return renderer.getMaterial(AllMaterialSpecs.ROTATING);
protected final InstanceMaterial<RotatingData> getRotatingMaterial() {
return materialManager.getMaterial(AllMaterialSpecs.ROTATING);
}
public static BlockState shaft(Direction.Axis axis) {

View file

@ -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<RotatingData> getModel() {
return renderer.getMaterial(AllMaterialSpecs.ROTATING).getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, tile.getBlockState());
return materialManager.getMaterial(AllMaterialSpecs.ROTATING).getModel(AllBlockPartials.SHAFTLESS_COGWHEEL, tile.getBlockState());
}
}

View file

@ -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<KineticTileEntit
protected final RotatingData rotatingModel;
public SingleRotatingInstance(InstancedTileRenderer<?> modelManager, KineticTileEntity tile) {
public SingleRotatingInstance(MaterialManager<?> modelManager, KineticTileEntity tile) {
super(modelManager, tile);
rotatingModel = setup(getModel().createInstance());

View file

@ -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<?, ActorData> renderMaterial = modelManager.getActorMaterial();
InstanceMaterial<ActorData> 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())

View file

@ -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);
}

View file

@ -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

View file

@ -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<?, ModelData> renderMaterial = modelManager.getTransformMaterial();
InstanceMaterial<ModelData> 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);

View file

@ -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

View file

@ -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);
}

View file

@ -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;

View file

@ -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<ContraptionProgram, ModelData> mat = modelManager.getTransformMaterial();
InstanceMaterial<ModelData> 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();

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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<EncasedFanTileEntity> {
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<EncasedFanTileEntity> {
}
@Override
protected void update() {
public void update() {
updateRotation(shaft);
updateRotation(fan, getFanSpeed());
}

View file

@ -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<FlywheelTileEntity> 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<FlywheelTileEntity> im
connectorAngleMult = flipAngle ? -1 : 1;
RenderMaterial<?, ModelData> mat = getTransformMaterial();
InstanceMaterial<ModelData> 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<FlywheelTileEntity> im
}
@Override
protected void update() {
public void update() {
updateRotation(shaft);
}

View file

@ -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<EngineTileEntity> {
protected ModelData frame;
public EngineInstance(InstancedTileRenderer<?> modelManager, EngineTileEntity tile) {
public EngineInstance(MaterialManager<?> modelManager, EngineTileEntity tile) {
super(modelManager, tile);
Block block = blockState

View file

@ -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);
}

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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<B extends KineticTileEntity & IBearingTileEntity> 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;

View file

@ -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)

View file

@ -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) {

View file

@ -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<StickerTileEntity> 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();

View file

@ -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()

View file

@ -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<SuperGlueEntity> implements ITickableInstance {
private final Quaternion rotation;
protected ConditionalInstance<OrientedData> model;
public GlueInstance(MaterialManager<?> renderer, SuperGlueEntity entity) {
super(renderer, entity);
Instancer<OrientedData> 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));
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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);
}
}

View file

@ -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<ContraptionProgram> {
public class ContraptionInstanceManager extends TileInstanceManager {
protected ArrayList<ActorInstance> actors = new ArrayList<>();
private final WeakReference<RenderedContraption> 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<Contraptio
MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state);
if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) {
ActorInstance instance = movementBehaviour.createInstance(this, context);
ActorInstance instance = movementBehaviour.createInstance(materialManager, getContraption().renderWorld, context);
actors.add(instance);
@ -64,17 +62,8 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer<Contraptio
return null;
}
public RenderMaterial<?, ActorData> getActorMaterial() {
return getMaterial(AllMaterialSpecs.ACTORS);
}
public RenderedContraption getContraption() {
return contraption.get();
}
@Override
public BlockPos getOriginCoordinate() {
return BlockPos.ZERO;
}
}

View file

@ -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<ContraptionProgram> {
public ContraptionMaterialManager(WorldContext<ContraptionProgram> context) {
super(context);
}
@Override
public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback<ContraptionProgram> callback) {
for (MaterialRenderer<ContraptionProgram> material : renderers) {
material.render(layer, viewProjection, camX, camY, camZ, callback);
}
}
}

View file

@ -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);

View file

@ -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<ContraptionProgram> materialManager;
public final ContraptionInstanceManager kinetics;
private final Map<RenderType, ModelRenderer> 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();

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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<BeltTileEntity> {
protected ArrayList<BeltData> 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<BeltTileEntity> {
PartialModel beltPartial = BeltRenderer.getBeltPartial(diagonal, start, end, bottom);
SpriteShiftEntry spriteShift = BeltRenderer.getSpriteShiftEntry(color, diagonal, bottom);
Instancer<BeltData> beltModel = modelManager.getMaterial(AllMaterialSpecs.BELTS).getModel(beltPartial, blockState);
Instancer<BeltData> beltModel = materialManager.getMaterial(AllMaterialSpecs.BELTS).getModel(beltPartial, blockState);
keys.add(setup(beltModel.createInstance(), bottom, spriteShift));

View file

@ -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);
}

View file

@ -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<SplitShaftTileEntity
protected final ArrayList<RotatingData> 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<?, RotatingData> rotatingMaterial = getRotatingMaterial();
InstanceMaterial<RotatingData> rotatingMaterial = getRotatingMaterial();
for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) {

View file

@ -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);
}

View file

@ -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<GearboxTileEntity> {
protected final EnumMap<Direction, RotatingData> 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<GearboxTileEntity> {
int skyLight = world.getLightLevel(LightType.SKY, pos);
updateSourceFacing();
RenderMaterial<?, RotatingData> rotatingMaterial = getRotatingMaterial();
InstanceMaterial<RotatingData> rotatingMaterial = getRotatingMaterial();
for (Direction direction : Iterate.directions) {
final Direction.Axis axis = direction.getAxis();

View file

@ -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);
}

View file

@ -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<ChromaticProjectorTileEntity> implements IDynamicInstance {
public ChromaticProjectorInstance(InstancedTileRenderer<?> renderer, ChromaticProjectorTileEntity tile) {
public ChromaticProjectorInstance(MaterialManager<?> renderer, ChromaticProjectorTileEntity tile) {
super(renderer, tile);
}

View file

@ -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<FlapData> {
@ -43,7 +44,7 @@ public class FlapData extends InstanceData implements IFlatLight<FlapData> {
}
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()),

View file

@ -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<BeltTunnelTileEntity>
private final Map<Direction, ArrayList<FlapData>> tunnelFlaps;
public BeltTunnelInstance(InstancedTileRenderer<?> modelManager, BeltTunnelTileEntity tile) {
public BeltTunnelInstance(MaterialManager<?> modelManager, BeltTunnelTileEntity tile) {
super(modelManager, tile);
tunnelFlaps = new EnumMap<>(Direction.class);

View file

@ -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;

View file

@ -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<AdjustableRep
protected int previousState;
public AdjustableRepeaterInstance(InstancedTileRenderer<?> modelManager, AdjustableRepeaterTileEntity tile) {
public AdjustableRepeaterInstance(MaterialManager<?> modelManager, AdjustableRepeaterTileEntity tile) {
super(modelManager, tile);
indicator = modelManager.getTransformMaterial().getModel(AllBlockPartials.FLEXPEATER_INDICATOR, blockState).createInstance();

View file

@ -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<FunnelTileEntity> impleme
private final ArrayList<FlapData> flaps;
public FunnelInstance(InstancedTileRenderer<?> modelManager, FunnelTileEntity tile) {
public FunnelInstance(MaterialManager<?> modelManager, FunnelTileEntity tile) {
super(modelManager, tile);
flaps = new ArrayList<>(4);

View file

@ -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<?, ModelData> mat = getTransformMaterial();
InstanceMaterial<ModelData> mat = getTransformMaterial();
base = mat.getModel(AllBlockPartials.ARM_BASE, blockState).createInstance();
lowerBody = mat.getModel(AllBlockPartials.ARM_LOWER_BODY, blockState).createInstance();

View file

@ -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<AnalogLeverTileEntit
final float rX;
final float rY;
public AnalogLeverInstance(InstancedTileRenderer<?> modelManager, AnalogLeverTileEntity tile) {
public AnalogLeverInstance(MaterialManager<?> modelManager, AnalogLeverTileEntity tile) {
super(modelManager, tile);
RenderMaterial<?, ModelData> mat = getTransformMaterial();
InstanceMaterial<ModelData> mat = getTransformMaterial();
handle = mat.getModel(AllBlockPartials.ANALOG_LEVER_HANDLE, blockState).createInstance();
indicator = mat.getModel(AllBlockPartials.ANALOG_LEVER_INDICATOR, blockState).createInstance();

View file

@ -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<SchematicannonTil
private final ModelData connector;
private final ModelData pipe;
public SchematicannonInstance(InstancedTileRenderer<?> modelManager, SchematicannonTileEntity tile) {
public SchematicannonInstance(MaterialManager<?> modelManager, SchematicannonTileEntity tile) {
super(modelManager, tile);
RenderMaterial<?, ModelData> mat = getTransformMaterial();
InstanceMaterial<ModelData> mat = getTransformMaterial();
connector = mat.getModel(AllBlockPartials.SCHEMATICANNON_CONNECTOR, blockState).createInstance();
pipe = mat.getModel(AllBlockPartials.SCHEMATICANNON_PIPE, blockState).createInstance();

View file

@ -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<WorldProgram> renderer = Backend.tileRenderer.get(world);
TileInstanceManager renderer = Backend.tileInstanceManager.get(world);
renderer.invalidate();
((ClientWorld) world).loadedTileEntityList.forEach(renderer::add);
}

View file

@ -33,6 +33,7 @@ public class AllCommands {
.then(ConfigCommand.register())
.then(PonderCommand.register())
.then(CloneCommand.register())
.then(GlueCommand.register())
// utility
.then(util)

View file

@ -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<CommandSource, ?> 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;
}));
}
}

View file

@ -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<T extends TileEntity, P> extends TileEntityBuilder<T, P> {
@Nullable
private NonNullSupplier<IRendererFactory<? super T>> instanceFactory;
private NonNullSupplier<ITileInstanceFactory<? super T>> instanceFactory;
public static <T extends TileEntity, P> TileEntityBuilder<T, P> create(AbstractRegistrate<?> owner, P parent,
String name, BuilderCallback callback, NonNullFunction<TileEntityType<T>, ? extends T> factory) {
@ -32,7 +32,7 @@ public class CreateTileEntityBuilder<T extends TileEntity, P> extends TileEntity
super(owner, parent, name, callback, factory);
}
public CreateTileEntityBuilder<T, P> instance(NonNullSupplier<IRendererFactory<? super T>> instanceFactory) {
public CreateTileEntityBuilder<T, P> instance(NonNullSupplier<ITileInstanceFactory<? super T>> instanceFactory) {
if (this.instanceFactory == null) {
DistExecutor.runWhenOn(Dist.CLIENT, () -> this::registerInstance);
}
@ -44,9 +44,9 @@ public class CreateTileEntityBuilder<T extends TileEntity, P> extends TileEntity
protected void registerInstance() {
OneTimeEventReceiver.addModListener(FMLClientSetupEvent.class, ($) -> {
NonNullSupplier<IRendererFactory<? super T>> instanceFactory = this.instanceFactory;
NonNullSupplier<ITileInstanceFactory<? super T>> instanceFactory = this.instanceFactory;
if (instanceFactory != null) {
InstancedTileRenderRegistry.getInstance().register(getEntry(), instanceFactory.get());
InstancedRenderRegistry.getInstance().register(getEntry(), instanceFactory.get());
}
});

View file

@ -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<Iterable<Entity>> cir) {
if (Backend.canUseInstancing()) {
Iterable<Entity> entities = cir.getReturnValue();
ArrayList<Entity> list = Lists.newArrayList(entities);
list.removeIf(tile -> tile instanceof IInstanceRendered && !((IInstanceRendered) tile).shouldRenderNormally());
cir.setReturnValue(list);
}
}
}

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

@ -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<Boolean> 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<WorldProgram> kineticRenderer = Backend.tileRenderer.get(self);
TileInstanceManager kineticRenderer = Backend.tileInstanceManager.get(self);
for (TileEntity tile : tileEntitiesToBeRemoved) {
kineticRenderer.remove(tile);
}

View file

@ -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);
});
}

View file

@ -36,7 +36,7 @@ public class NetworkLightUpdateMixin {
chunk.getTileEntityMap()
.values()
.forEach(tile -> {
Backend.tileRenderer.get(world)
Backend.tileInstanceManager.get(world)
.onLightUpdate(tile);
});
}

View file

@ -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,

View file

@ -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.);

View file

@ -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",