mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 15:06:28 +01:00
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:
parent
c65992ec0e
commit
c9b5fa1ff9
21 changed files with 135 additions and 85 deletions
|
@ -9,11 +9,13 @@ import com.jozufozu.flywheel.config.BackendTypeArgument;
|
|||
import com.jozufozu.flywheel.config.FlwCommands;
|
||||
import com.jozufozu.flywheel.config.FlwConfig;
|
||||
import com.jozufozu.flywheel.core.Contexts;
|
||||
import com.jozufozu.flywheel.core.GameStateRegistry;
|
||||
import com.jozufozu.flywheel.core.Models;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
||||
import com.jozufozu.flywheel.core.compile.ProgramCompiler;
|
||||
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.vertex.LayoutShaders;
|
||||
import com.jozufozu.flywheel.event.ReloadRenderersEvent;
|
||||
|
@ -86,6 +88,8 @@ public class Flywheel {
|
|||
Contexts.init();
|
||||
MaterialShaders.init();
|
||||
|
||||
GameStateRegistry.register(NormalDebugStateProvider.INSTANCE);
|
||||
|
||||
VanillaInstances.init();
|
||||
|
||||
// https://github.com/Jozufozu/Flywheel/issues/69
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package com.jozufozu.flywheel.api.material;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
public class Material {
|
||||
protected final RenderType renderType;
|
||||
protected final Supplier<FileResolution> vertexShader;
|
||||
protected final Supplier<FileResolution> fragmentShader;
|
||||
protected final FileResolution vertexShader;
|
||||
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.vertexShader = vertexShader;
|
||||
this.fragmentShader = fragmentShader;
|
||||
|
@ -22,10 +20,10 @@ public class Material {
|
|||
}
|
||||
|
||||
public FileResolution getVertexShader() {
|
||||
return vertexShader.get();
|
||||
return vertexShader;
|
||||
}
|
||||
|
||||
public FileResolution getFragmentShader() {
|
||||
return fragmentShader.get();
|
||||
return fragmentShader;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ public enum GLSLVersion {
|
|||
V410(410),
|
||||
V420(420),
|
||||
V430(430),
|
||||
V440(440),
|
||||
V450(450),
|
||||
V460(460),
|
||||
;
|
||||
|
||||
public final int version;
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.jozufozu.flywheel.backend.gl.shader;
|
|||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
|
|
@ -214,7 +214,6 @@ public class InstancingEngine<P extends WorldProgram> implements Engine {
|
|||
int dZ = cZ - originCoordinate.getZ();
|
||||
|
||||
if (Math.abs(dX) > MAX_ORIGIN_DISTANCE || Math.abs(dY) > MAX_ORIGIN_DISTANCE || Math.abs(dZ) > MAX_ORIGIN_DISTANCE) {
|
||||
|
||||
shiftListeners(cX, cY, cZ);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.jozufozu.flywheel.util.NonNullSupplier;
|
|||
import net.minecraft.client.renderer.RenderType;
|
||||
|
||||
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 final Lazy<Mesh> supplier;
|
||||
|
|
|
@ -1,41 +1,48 @@
|
|||
package com.jozufozu.flywheel.core;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.backend.gl.GLSLVersion;
|
||||
import com.jozufozu.flywheel.core.compile.ProgramCompiler;
|
||||
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.source.FileResolution;
|
||||
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 net.minecraft.resources.ResourceLocation;
|
||||
|
||||
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 ProgramCompiler<CrumblingProgram> CRUMBLING;
|
||||
public static final ProgramCompiler<WorldProgram> WORLD;
|
||||
public static final ProgramCompiler<CrumblingProgram> CRUMBLING;
|
||||
|
||||
public static void init() {
|
||||
GameStateRegistry.register(NormalDebugStateProvider.INSTANCE);
|
||||
|
||||
var checkFrag = SourceChecks.checkFunctionArity("flw_contextFragment", 0);
|
||||
var checkVert = SourceChecks.checkFunctionArity("flw_contextVertex", 0);
|
||||
|
||||
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);
|
||||
static {
|
||||
var worldVertex = createVertex(ResourceUtil.subPath(Names.WORLD, ".vert"));
|
||||
var worldFragment = createFragment(ResourceUtil.subPath(Names.WORLD, ".frag"));
|
||||
var crumblingVertex = createVertex(ResourceUtil.subPath(Names.CRUMBLING, ".vert"));
|
||||
var crumblingFragment = createFragment(ResourceUtil.subPath(Names.CRUMBLING, ".frag"));
|
||||
|
||||
WORLD = ProgramCompiler.create(WorldProgram::new, worldVertex, worldFragment, 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 final ResourceLocation WORLD = Flywheel.rl("context/world");
|
||||
public static final ResourceLocation CRUMBLING = Flywheel.rl("context/crumbling");
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.jozufozu.flywheel.core.compile;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.jozufozu.flywheel.backend.gl.GLSLVersion;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlShader;
|
||||
|
|
|
@ -8,13 +8,10 @@ import static org.lwjgl.opengl.GL20.glGetProgramInfoLog;
|
|||
import static org.lwjgl.opengl.GL20.glGetProgrami;
|
||||
import static org.lwjgl.opengl.GL20.glLinkProgram;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||
import com.jozufozu.flywheel.backend.gl.shader.GlShader;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class ProgramAssembler {
|
||||
|
|
|
@ -1,27 +1,33 @@
|
|||
package com.jozufozu.flywheel.core.material;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
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 net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class MaterialShaders {
|
||||
public static FileResolution DEFAULT_VERTEX;
|
||||
public static FileResolution DEFAULT_FRAGMENT;
|
||||
public static FileResolution SHADED_VERTEX;
|
||||
public static final BiConsumer<ErrorReporter, SourceFile> VERTEX_CHECK = SourceChecks.checkFunctionArity("flw_materialVertex", 0);
|
||||
public static final BiConsumer<ErrorReporter, SourceFile> FRAGMENT_CHECK = SourceChecks.checkFunctionArity("flw_materialFragment", 0);
|
||||
|
||||
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() {
|
||||
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 {
|
||||
|
|
|
@ -271,12 +271,13 @@ public class ModelTransformer {
|
|||
}
|
||||
|
||||
normal.mul(-1.0F);
|
||||
return this;
|
||||
}
|
||||
|
||||
float f = 1.0F / pX;
|
||||
float f1 = 1.0F / pY;
|
||||
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));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -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.ShaderFunction;
|
||||
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.Span;
|
||||
import com.jozufozu.flywheel.core.source.span.StringSpan;
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
package com.jozufozu.flywheel.core.structs;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
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 net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class InstanceShaders {
|
||||
public static FileResolution MODEL;
|
||||
public static FileResolution ORIENTED;
|
||||
public static final BiConsumer<ErrorReporter, SourceFile> CHECK = SourceChecks.checkFunctionParameterTypeExists("flw_instanceVertex", 1, 0);
|
||||
|
||||
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() {
|
||||
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 {
|
||||
|
|
|
@ -10,6 +10,9 @@ import com.mojang.math.Quaternion;
|
|||
import net.minecraft.util.Mth;
|
||||
|
||||
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 Matrix3f normal = new Matrix3f();
|
||||
|
||||
|
@ -31,8 +34,8 @@ public class ModelData extends BasicData implements Transform<ModelData> {
|
|||
public ModelData setEmptyTransform() {
|
||||
markDirty();
|
||||
|
||||
this.model.load(new Matrix4f());
|
||||
this.normal.load(new Matrix3f());
|
||||
this.model.load(EMPTY_MATRIX_4f);
|
||||
this.normal.load(EMPTY_MATRIX_3f);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -64,12 +67,13 @@ public class ModelData extends BasicData implements Transform<ModelData> {
|
|||
}
|
||||
|
||||
normal.mul(-1.0F);
|
||||
return this;
|
||||
}
|
||||
|
||||
float f = 1.0F / pX;
|
||||
float f1 = 1.0F / pY;
|
||||
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));
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
package com.jozufozu.flywheel.core.vertex;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.core.source.FileResolution;
|
||||
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 net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class LayoutShaders {
|
||||
public static FileResolution BLOCK;
|
||||
public static FileResolution POS_TEX_NORMAL;
|
||||
public static final BiConsumer<ErrorReporter, SourceFile> CHECK = SourceChecks.checkFunctionArity("flw_layoutVertex", 0);
|
||||
|
||||
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() {
|
||||
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 {
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.jozufozu.flywheel.light.LightUpdater;
|
|||
import com.jozufozu.flywheel.util.WorldAttached;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
|
|
|
@ -22,7 +22,7 @@ import net.minecraft.world.level.block.entity.BellBlockEntity;
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
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> 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 final OrientedData body;
|
||||
private final ModelData lid;
|
||||
|
|
|
@ -31,36 +31,44 @@ import net.minecraft.world.phys.Vec3;
|
|||
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 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 ModelData body;
|
||||
private ModelData contents;
|
||||
private BlockState blockstate;
|
||||
private BlockState blockState;
|
||||
private boolean active;
|
||||
|
||||
public MinecartInstance(InstancerManager instancerManager, T entity) {
|
||||
super(instancerManager, entity);
|
||||
|
||||
blockstate = entity.getDisplayBlockState();
|
||||
contents = getContents();
|
||||
body = getBody();
|
||||
blockState = entity.getDisplayBlockState();
|
||||
contents = getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
BlockState displayBlockState = entity.getDisplayBlockState();
|
||||
|
||||
if (displayBlockState != blockstate) {
|
||||
blockstate = displayBlockState;
|
||||
if (displayBlockState != blockState) {
|
||||
blockState = displayBlockState;
|
||||
contents.delete();
|
||||
contents = getContents();
|
||||
updateLight();
|
||||
if (contents != null) {
|
||||
relight(getWorldPosition(), contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginFrame() {
|
||||
// TODO: add proper way to temporarily disable rendering a specific instance
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
TransformStack tstack = TransformStack.cast(stack);
|
||||
stack.setIdentity();
|
||||
float pt = AnimationTickHolder.getPartialTicks();
|
||||
|
@ -146,11 +154,20 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
|
|||
}
|
||||
|
||||
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 instancerManager.factory(StructTypes.MODEL)
|
||||
.model(Models.block(blockstate))
|
||||
.model(Models.block(blockState))
|
||||
.createInstance();
|
||||
}
|
||||
|
||||
|
@ -171,4 +188,8 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
|
|||
.cuboid().invertYZ().start(-8, y, -8).size(16, 8, 2).endCuboid()
|
||||
.build();
|
||||
}
|
||||
|
||||
public static boolean shouldSkipRender(AbstractMinecart minecart) {
|
||||
return minecart.getDisplayBlockState().getRenderShape() != RenderShape.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
|||
|
||||
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> 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> 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 final TextureAtlasSprite texture;
|
||||
|
||||
|
|
|
@ -52,15 +52,23 @@ public class VanillaInstances {
|
|||
.apply();
|
||||
|
||||
configure(EntityType.MINECART)
|
||||
.alwaysSkipRender()
|
||||
.skipRender(MinecartInstance::shouldSkipRender)
|
||||
.factory(MinecartInstance::new)
|
||||
.apply();
|
||||
configure(EntityType.HOPPER_MINECART)
|
||||
.alwaysSkipRender()
|
||||
configure(EntityType.COMMAND_BLOCK_MINECART)
|
||||
.skipRender(MinecartInstance::shouldSkipRender)
|
||||
.factory(MinecartInstance::new)
|
||||
.apply();
|
||||
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)
|
||||
.apply();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue