Fix and simplify

- Fix #130
- Simplify Material and default FileResolution creation
- Add instancing to command block and TNT minecarts
- Add missing 440-460 GLSL versions
This commit is contained in:
PepperCode1 2022-05-20 21:14:31 -07:00
parent f4e648c057
commit 9886dca1e2
21 changed files with 135 additions and 85 deletions

View file

@ -9,11 +9,13 @@ import com.jozufozu.flywheel.config.BackendTypeArgument;
import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwCommands;
import com.jozufozu.flywheel.config.FlwConfig; import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.core.Contexts; import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.core.GameStateRegistry;
import com.jozufozu.flywheel.core.Models; import com.jozufozu.flywheel.core.Models;
import com.jozufozu.flywheel.core.PartialModel; import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.StitchedSprite;
import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.compile.ProgramCompiler;
import com.jozufozu.flywheel.core.material.MaterialShaders; import com.jozufozu.flywheel.core.material.MaterialShaders;
import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider;
import com.jozufozu.flywheel.core.structs.InstanceShaders; import com.jozufozu.flywheel.core.structs.InstanceShaders;
import com.jozufozu.flywheel.core.vertex.LayoutShaders; import com.jozufozu.flywheel.core.vertex.LayoutShaders;
import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent;
@ -86,6 +88,8 @@ public class Flywheel {
Contexts.init(); Contexts.init();
MaterialShaders.init(); MaterialShaders.init();
GameStateRegistry.register(NormalDebugStateProvider.INSTANCE);
VanillaInstances.init(); VanillaInstances.init();
// https://github.com/Jozufozu/Flywheel/issues/69 // https://github.com/Jozufozu/Flywheel/issues/69

View file

@ -1,17 +1,15 @@
package com.jozufozu.flywheel.api.material; package com.jozufozu.flywheel.api.material;
import java.util.function.Supplier;
import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
public class Material { public class Material {
protected final RenderType renderType; protected final RenderType renderType;
protected final Supplier<FileResolution> vertexShader; protected final FileResolution vertexShader;
protected final Supplier<FileResolution> fragmentShader; protected final FileResolution fragmentShader;
public Material(RenderType renderType, Supplier<FileResolution> vertexShader, Supplier<FileResolution> fragmentShader) { public Material(RenderType renderType, FileResolution vertexShader, FileResolution fragmentShader) {
this.renderType = renderType; this.renderType = renderType;
this.vertexShader = vertexShader; this.vertexShader = vertexShader;
this.fragmentShader = fragmentShader; this.fragmentShader = fragmentShader;
@ -22,10 +20,10 @@ public class Material {
} }
public FileResolution getVertexShader() { public FileResolution getVertexShader() {
return vertexShader.get(); return vertexShader;
} }
public FileResolution getFragmentShader() { public FileResolution getFragmentShader() {
return fragmentShader.get(); return fragmentShader;
} }
} }

View file

@ -11,6 +11,9 @@ public enum GLSLVersion {
V410(410), V410(410),
V420(420), V420(420),
V430(430), V430(430),
V440(440),
V450(450),
V460(460),
; ;
public final int version; public final int version;

View file

@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.gl.shader;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL20;

View file

@ -214,7 +214,6 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
int dZ = cZ - originCoordinate.getZ(); int dZ = cZ - originCoordinate.getZ();
if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) { if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) {
shiftListeners(cX, cY, cZ); shiftListeners(cX, cY, cZ);
} }
} }

View file

@ -15,7 +15,7 @@ import com.jozufozu.flywheel.util.NonNullSupplier;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
public class BasicModelSupplier implements ModelSupplier { public class BasicModelSupplier implements ModelSupplier {
private static final Material DEFAULT_MATERIAL = new Material(RenderType.solid(), () -> MaterialShaders.DEFAULT_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT); private static final Material DEFAULT_MATERIAL = new Material(RenderType.solid(), MaterialShaders.DEFAULT_VERTEX, MaterialShaders.DEFAULT_FRAGMENT);
private Material material; private Material material;
private final Lazy<Mesh> supplier; private final Lazy<Mesh> supplier;

View file

@ -1,41 +1,48 @@
package com.jozufozu.flywheel.core; package com.jozufozu.flywheel.core;
import java.util.function.BiConsumer;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.gl.GLSLVersion; import com.jozufozu.flywheel.backend.gl.GLSLVersion;
import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.compile.ProgramCompiler;
import com.jozufozu.flywheel.core.crumbling.CrumblingProgram; import com.jozufozu.flywheel.core.crumbling.CrumblingProgram;
import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider;
import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceChecks; import com.jozufozu.flywheel.core.source.SourceChecks;
import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.ResourceUtil;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class Contexts { public class Contexts {
public static final BiConsumer<ErrorReporter, SourceFile> VERTEX_CHECK = SourceChecks.checkFunctionArity("flw_contextVertex", 0);
public static final BiConsumer<ErrorReporter, SourceFile> FRAGMENT_CHECK = SourceChecks.checkFunctionArity("flw_contextFragment", 0);
public static ProgramCompiler<WorldProgram> WORLD; public static final ProgramCompiler<WorldProgram> WORLD;
public static ProgramCompiler<CrumblingProgram> CRUMBLING; public static final ProgramCompiler<CrumblingProgram> CRUMBLING;
public static void init() { static {
GameStateRegistry.register(NormalDebugStateProvider.INSTANCE); var worldVertex = createVertex(ResourceUtil.subPath(Names.WORLD, ".vert"));
var worldFragment = createFragment(ResourceUtil.subPath(Names.WORLD, ".frag"));
var checkFrag = SourceChecks.checkFunctionArity("flw_contextFragment", 0); var crumblingVertex = createVertex(ResourceUtil.subPath(Names.CRUMBLING, ".vert"));
var checkVert = SourceChecks.checkFunctionArity("flw_contextVertex", 0); var crumblingFragment = createFragment(ResourceUtil.subPath(Names.CRUMBLING, ".frag"));
var worldVertex = FileResolution.get(ResourceUtil.subPath(Names.WORLD, ".vert"))
.validateWith(checkVert);
var worldFragment = FileResolution.get(ResourceUtil.subPath(Names.WORLD, ".frag"))
.validateWith(checkFrag);
var crumblingVertex = FileResolution.get(ResourceUtil.subPath(Names.CRUMBLING, ".vert"))
.validateWith(checkVert);
var crumblingFragment = FileResolution.get(ResourceUtil.subPath(Names.CRUMBLING, ".frag"))
.validateWith(checkFrag);
WORLD = ProgramCompiler.create(WorldProgram::new, worldVertex, worldFragment, GLSLVersion.V330); WORLD = ProgramCompiler.create(WorldProgram::new, worldVertex, worldFragment, GLSLVersion.V330);
CRUMBLING = ProgramCompiler.create(CrumblingProgram::new, crumblingVertex, crumblingFragment, GLSLVersion.V330); CRUMBLING = ProgramCompiler.create(CrumblingProgram::new, crumblingVertex, crumblingFragment, GLSLVersion.V330);
} }
public static FileResolution createVertex(ResourceLocation location) {
return FileResolution.get(location).validateWith(VERTEX_CHECK);
}
public static FileResolution createFragment(ResourceLocation location) {
return FileResolution.get(location).validateWith(FRAGMENT_CHECK);
}
public static void init() {
}
public static class Names { public static class Names {
public static final ResourceLocation WORLD = Flywheel.rl("context/world"); public static final ResourceLocation WORLD = Flywheel.rl("context/world");
public static final ResourceLocation CRUMBLING = Flywheel.rl("context/crumbling"); public static final ResourceLocation CRUMBLING = Flywheel.rl("context/crumbling");

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.compile;
import java.util.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.backend.gl.GLSLVersion; import com.jozufozu.flywheel.backend.gl.GLSLVersion;
import com.jozufozu.flywheel.backend.gl.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.GlShader;

View file

@ -8,13 +8,10 @@ import static org.lwjgl.opengl.GL20.glGetProgramInfoLog;
import static org.lwjgl.opengl.GL20.glGetProgrami; import static org.lwjgl.opengl.GL20.glGetProgrami;
import static org.lwjgl.opengl.GL20.glLinkProgram; import static org.lwjgl.opengl.GL20.glLinkProgram;
import java.util.List;
import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.shader.GlShader; import com.jozufozu.flywheel.backend.gl.shader.GlShader;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class ProgramAssembler { public class ProgramAssembler {

View file

@ -1,27 +1,33 @@
package com.jozufozu.flywheel.core.material; package com.jozufozu.flywheel.core.material;
import java.util.function.BiConsumer;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceChecks; import com.jozufozu.flywheel.core.source.SourceChecks;
import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.ResourceUtil;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class MaterialShaders { public class MaterialShaders {
public static FileResolution DEFAULT_VERTEX; public static final BiConsumer<ErrorReporter, SourceFile> VERTEX_CHECK = SourceChecks.checkFunctionArity("flw_materialVertex", 0);
public static FileResolution DEFAULT_FRAGMENT; public static final BiConsumer<ErrorReporter, SourceFile> FRAGMENT_CHECK = SourceChecks.checkFunctionArity("flw_materialFragment", 0);
public static FileResolution SHADED_VERTEX;
public static final FileResolution DEFAULT_VERTEX = createVertex(ResourceUtil.subPath(Names.DEFAULT, ".vert"));
public static final FileResolution DEFAULT_FRAGMENT = createFragment(ResourceUtil.subPath(Names.DEFAULT, ".frag"));
public static final FileResolution SHADED_VERTEX = createVertex(ResourceUtil.subPath(Names.SHADED, ".vert"));
public static FileResolution createVertex(ResourceLocation location) {
return FileResolution.get(location).validateWith(VERTEX_CHECK);
}
public static FileResolution createFragment(ResourceLocation location) {
return FileResolution.get(location).validateWith(FRAGMENT_CHECK);
}
public static void init() { public static void init() {
var checkVert = SourceChecks.checkFunctionArity("flw_materialVertex", 0);
var checkFrag = SourceChecks.checkFunctionArity("flw_materialFragment", 0);
DEFAULT_VERTEX = FileResolution.get(ResourceUtil.subPath(Names.DEFAULT, ".vert"))
.validateWith(checkVert);
DEFAULT_FRAGMENT = FileResolution.get(ResourceUtil.subPath(Names.DEFAULT, ".frag"))
.validateWith(checkFrag);
SHADED_VERTEX = FileResolution.get(ResourceUtil.subPath(Names.SHADED, ".vert"))
.validateWith(checkVert);
} }
public static class Names { public static class Names {

View file

@ -271,12 +271,13 @@ public class ModelTransformer {
} }
normal.mul(-1.0F); normal.mul(-1.0F);
return this;
} }
float f = 1.0F / pX; float f = 1.0F / pX;
float f1 = 1.0F / pY; float f1 = 1.0F / pY;
float f2 = 1.0F / pZ; float f2 = 1.0F / pZ;
float f3 = Mth.fastInvCubeRoot(f * f1 * f2); float f3 = Mth.fastInvCubeRoot(Math.abs(f * f1 * f2));
normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2)); normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2));
return this; return this;
} }

View file

@ -15,7 +15,6 @@ import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.core.source.parse.Import; import com.jozufozu.flywheel.core.source.parse.Import;
import com.jozufozu.flywheel.core.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderFunction;
import com.jozufozu.flywheel.core.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import com.jozufozu.flywheel.core.source.parse.Variable;
import com.jozufozu.flywheel.core.source.span.ErrorSpan; import com.jozufozu.flywheel.core.source.span.ErrorSpan;
import com.jozufozu.flywheel.core.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
import com.jozufozu.flywheel.core.source.span.StringSpan; import com.jozufozu.flywheel.core.source.span.StringSpan;

View file

@ -1,23 +1,27 @@
package com.jozufozu.flywheel.core.structs; package com.jozufozu.flywheel.core.structs;
import java.util.function.BiConsumer;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceChecks; import com.jozufozu.flywheel.core.source.SourceChecks;
import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.ResourceUtil;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class InstanceShaders { public class InstanceShaders {
public static FileResolution MODEL; public static final BiConsumer<ErrorReporter, SourceFile> CHECK = SourceChecks.checkFunctionParameterTypeExists("flw_instanceVertex", 1, 0);
public static FileResolution ORIENTED;
public static final FileResolution MODEL = create(ResourceUtil.subPath(Names.MODEL, ".vert"));
public static final FileResolution ORIENTED = create(ResourceUtil.subPath(Names.ORIENTED, ".vert"));
public static FileResolution create(ResourceLocation location) {
return FileResolution.get(location).validateWith(CHECK);
}
public static void init() { public static void init() {
var check = SourceChecks.checkFunctionParameterTypeExists("flw_instanceVertex", 1, 0);
MODEL = FileResolution.get(ResourceUtil.subPath(Names.MODEL, ".vert"))
.validateWith(check);
ORIENTED = FileResolution.get(ResourceUtil.subPath(Names.ORIENTED, ".vert"))
.validateWith(check);
} }
public static class Names { public static class Names {

View file

@ -10,6 +10,9 @@ import com.mojang.math.Quaternion;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
public class ModelData extends BasicData implements Transform<ModelData> { public class ModelData extends BasicData implements Transform<ModelData> {
private static final Matrix4f EMPTY_MATRIX_4f = new Matrix4f();
private static final Matrix3f EMPTY_MATRIX_3f = new Matrix3f();
public final Matrix4f model = new Matrix4f(); public final Matrix4f model = new Matrix4f();
public final Matrix3f normal = new Matrix3f(); public final Matrix3f normal = new Matrix3f();
@ -31,8 +34,8 @@ public class ModelData extends BasicData implements Transform<ModelData> {
public ModelData setEmptyTransform() { public ModelData setEmptyTransform() {
markDirty(); markDirty();
this.model.load(new Matrix4f()); this.model.load(EMPTY_MATRIX_4f);
this.normal.load(new Matrix3f()); this.normal.load(EMPTY_MATRIX_3f);
return this; return this;
} }
@ -64,12 +67,13 @@ public class ModelData extends BasicData implements Transform<ModelData> {
} }
normal.mul(-1.0F); normal.mul(-1.0F);
return this;
} }
float f = 1.0F / pX; float f = 1.0F / pX;
float f1 = 1.0F / pY; float f1 = 1.0F / pY;
float f2 = 1.0F / pZ; float f2 = 1.0F / pZ;
float f3 = Mth.fastInvCubeRoot(f * f1 * f2); float f3 = Mth.fastInvCubeRoot(Math.abs(f * f1 * f2));
normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2)); normal.mul(Matrix3f.createScaleMatrix(f3 * f, f3 * f1, f3 * f2));
return this; return this;
} }

View file

@ -1,24 +1,27 @@
package com.jozufozu.flywheel.core.vertex; package com.jozufozu.flywheel.core.vertex;
import java.util.function.BiConsumer;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceChecks; import com.jozufozu.flywheel.core.source.SourceChecks;
import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.util.ResourceUtil; import com.jozufozu.flywheel.util.ResourceUtil;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class LayoutShaders { public class LayoutShaders {
public static FileResolution BLOCK; public static final BiConsumer<ErrorReporter, SourceFile> CHECK = SourceChecks.checkFunctionArity("flw_layoutVertex", 0);
public static FileResolution POS_TEX_NORMAL;
public static final FileResolution BLOCK = create(ResourceUtil.subPath(Names.BLOCK, ".vert"));
public static final FileResolution POS_TEX_NORMAL = create(ResourceUtil.subPath(Names.POS_TEX_NORMAL, ".vert"));
public static FileResolution create(ResourceLocation location) {
return FileResolution.get(location).validateWith(CHECK);
}
public static void init() { public static void init() {
var check = SourceChecks.checkFunctionArity("flw_layoutVertex", 0);
BLOCK = FileResolution.get(ResourceUtil.subPath(Names.BLOCK, ".vert"))
.validateWith(check);
POS_TEX_NORMAL = FileResolution.get(ResourceUtil.subPath(Names.POS_TEX_NORMAL, ".vert"))
.validateWith(check);
} }
public static class Names { public static class Names {

View file

@ -6,7 +6,6 @@ import com.jozufozu.flywheel.light.LightUpdater;
import com.jozufozu.flywheel.util.WorldAttached; import com.jozufozu.flywheel.util.WorldAttached;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;

View file

@ -22,7 +22,7 @@ import net.minecraft.world.level.block.entity.BellBlockEntity;
public class BellInstance extends BlockEntityInstance<BellBlockEntity> implements DynamicInstance { public class BellInstance extends BlockEntityInstance<BellBlockEntity> implements DynamicInstance {
private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT)); private static final BasicModelSupplier MODEL = new BasicModelSupplier(BellInstance::createBellModel, new Material(Sheets.solidBlockSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
private final OrientedData bell; private final OrientedData bell;

View file

@ -34,8 +34,8 @@ import net.minecraft.world.level.block.state.properties.ChestType;
public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends BlockEntityInstance<T> implements DynamicInstance { public class ChestInstance<T extends BlockEntity & LidBlockEntity> extends BlockEntityInstance<T> implements DynamicInstance {
private static final BiFunction<ChestType, Material, BasicModelSupplier> LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); private static final BiFunction<ChestType, Material, BasicModelSupplier> LID = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createLidModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)));
private static final BiFunction<ChestType, Material, BasicModelSupplier> BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); private static final BiFunction<ChestType, Material, BasicModelSupplier> BASE = Util.memoize((type, mat) -> new BasicModelSupplier(() -> createBaseModel(type, mat.sprite()), new com.jozufozu.flywheel.api.material.Material(Sheets.chestSheet(), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)));
private final OrientedData body; private final OrientedData body;
private final ModelData lid; private final ModelData lid;

View file

@ -31,36 +31,44 @@ import net.minecraft.world.phys.Vec3;
public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance<T> implements DynamicInstance, TickableInstance { public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance<T> implements DynamicInstance, TickableInstance {
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new Material(RenderType.entitySolid(MINECART_LOCATION), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT)); private static final BasicModelSupplier MODEL = new BasicModelSupplier(MinecartInstance::getBodyModel, new Material(RenderType.entitySolid(MINECART_LOCATION), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT));
private final PoseStack stack = new PoseStack(); private final PoseStack stack = new PoseStack();
private final ModelData body; private final ModelData body;
private ModelData contents; private ModelData contents;
private BlockState blockstate; private BlockState blockState;
private boolean active;
public MinecartInstance(InstancerManager instancerManager, T entity) { public MinecartInstance(InstancerManager instancerManager, T entity) {
super(instancerManager, entity); super(instancerManager, entity);
blockstate = entity.getDisplayBlockState();
contents = getContents();
body = getBody(); body = getBody();
blockState = entity.getDisplayBlockState();
contents = getContents();
} }
@Override @Override
public void tick() { public void tick() {
BlockState displayBlockState = entity.getDisplayBlockState(); BlockState displayBlockState = entity.getDisplayBlockState();
if (displayBlockState != blockstate) { if (displayBlockState != blockState) {
blockstate = displayBlockState; blockState = displayBlockState;
contents.delete(); contents.delete();
contents = getContents(); contents = getContents();
updateLight(); if (contents != null) {
relight(getWorldPosition(), contents);
}
} }
} }
@Override @Override
public void beginFrame() { public void beginFrame() {
// TODO: add proper way to temporarily disable rendering a specific instance
if (!active) {
return;
}
TransformStack tstack = TransformStack.cast(stack); TransformStack tstack = TransformStack.cast(stack);
stack.setIdentity(); stack.setIdentity();
float pt = AnimationTickHolder.getPartialTicks(); float pt = AnimationTickHolder.getPartialTicks();
@ -146,11 +154,20 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
} }
private ModelData getContents() { private ModelData getContents() {
if (blockstate.getRenderShape() == RenderShape.INVISIBLE) RenderShape shape = blockState.getRenderShape();
if (shape == RenderShape.ENTITYBLOCK_ANIMATED) {
body.setEmptyTransform();
active = false;
return null;
}
active = true;
if (shape == RenderShape.INVISIBLE)
return null; return null;
return instancerManager.factory(StructTypes.MODEL) return instancerManager.factory(StructTypes.MODEL)
.model(Models.block(blockstate)) .model(Models.block(blockState))
.createInstance(); .createInstance();
} }
@ -171,4 +188,8 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
.cuboid().invertYZ().start(-8, y, -8).size(16, 8, 2).endCuboid() .cuboid().invertYZ().start(-8, y, -8).size(16, 8, 2).endCuboid()
.build(); .build();
} }
public static boolean shouldSkipRender(AbstractMinecart minecart) {
return minecart.getDisplayBlockState().getRenderShape() != RenderShape.ENTITYBLOCK_ANIMATED;
}
} }

View file

@ -28,8 +28,8 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntity> implements DynamicInstance { public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntity> implements DynamicInstance {
private static final Function<TextureAtlasSprite, BasicModelSupplier> BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); private static final Function<TextureAtlasSprite, BasicModelSupplier> BASE = Util.memoize(it -> new BasicModelSupplier(() -> makeBaseModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)));
private static final Function<TextureAtlasSprite, BasicModelSupplier> LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), () -> MaterialShaders.SHADED_VERTEX, () -> MaterialShaders.DEFAULT_FRAGMENT))); private static final Function<TextureAtlasSprite, BasicModelSupplier> LID = Util.memoize(it -> new BasicModelSupplier(() -> makeLidModel(it), new Material(RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), MaterialShaders.SHADED_VERTEX, MaterialShaders.DEFAULT_FRAGMENT)));
private final TextureAtlasSprite texture; private final TextureAtlasSprite texture;

View file

@ -52,15 +52,23 @@ public class VanillaInstances {
.apply(); .apply();
configure(EntityType.MINECART) configure(EntityType.MINECART)
.alwaysSkipRender() .skipRender(MinecartInstance::shouldSkipRender)
.factory(MinecartInstance::new) .factory(MinecartInstance::new)
.apply(); .apply();
configure(EntityType.HOPPER_MINECART) configure(EntityType.COMMAND_BLOCK_MINECART)
.alwaysSkipRender() .skipRender(MinecartInstance::shouldSkipRender)
.factory(MinecartInstance::new) .factory(MinecartInstance::new)
.apply(); .apply();
configure(EntityType.FURNACE_MINECART) configure(EntityType.FURNACE_MINECART)
.alwaysSkipRender() .skipRender(MinecartInstance::shouldSkipRender)
.factory(MinecartInstance::new)
.apply();
configure(EntityType.HOPPER_MINECART)
.skipRender(MinecartInstance::shouldSkipRender)
.factory(MinecartInstance::new)
.apply();
configure(EntityType.TNT_MINECART)
.skipRender(MinecartInstance::shouldSkipRender)
.factory(MinecartInstance::new) .factory(MinecartInstance::new)
.apply(); .apply();
} }