Things on the screen again

- Use our own model cache that's aware of virtual data.
- Fix memory write issues with instance types.
- Indirect works too, though the cull shaders are still incorrect.
This commit is contained in:
Jozufozu 2024-01-17 13:27:52 -08:00
parent e892003eb5
commit 5bac9e5224
14 changed files with 100 additions and 96 deletions

View file

@ -23,7 +23,7 @@ use_parchment = true
# dependency versions # dependency versions
registrate_version = MC1.20-1.3.3 registrate_version = MC1.20-1.3.3
flywheel_minecraft_version = 1.20.1 flywheel_minecraft_version = 1.20.1
flywheel_version = 1.0.0-alpha-14 flywheel_version = 1.0.0-alpha-18
jei_minecraft_version = 1.20.1 jei_minecraft_version = 1.20.1
jei_version = 15.2.0.22 jei_version = 15.2.0.22
curios_minecraft_version = 1.20.1 curios_minecraft_version = 1.20.1

View file

@ -39,13 +39,14 @@ public class ActorInstance extends AbstractInstance {
return this; return this;
} }
public ActorInstance setBlockLight(int blockLight) { public ActorInstance setBlockLight(int blockLight) {
this.blockLight = (byte) ((blockLight & 0xF) << 4); this.blockLight = (byte) blockLight;
return this; return this;
} }
public ActorInstance setSkyLight(int skyLight) { public ActorInstance setSkyLight(int skyLight) {
this.skyLight = (byte) ((skyLight & 0xF) << 4); this.skyLight = (byte) skyLight;
return this; return this;
} }

View file

@ -9,6 +9,7 @@ import com.jozufozu.flywheel.lib.instance.OrientedInstance;
import com.jozufozu.flywheel.lib.model.Models; import com.jozufozu.flywheel.lib.model.Models;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllPartialModels; import com.simibubi.create.AllPartialModels;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
public class RopePulleyInstance extends AbstractPulleyInstance<PulleyBlockEntity> { public class RopePulleyInstance extends AbstractPulleyInstance<PulleyBlockEntity> {
@ -17,11 +18,11 @@ public class RopePulleyInstance extends AbstractPulleyInstance<PulleyBlockEntity
} }
protected Instancer<OrientedInstance> getRopeModel() { protected Instancer<OrientedInstance> getRopeModel() {
return instancerProvider.instancer(InstanceTypes.ORIENTED, Models.block(AllBlocks.ROPE.getDefaultState()), RenderStage.AFTER_BLOCK_ENTITIES); return instancerProvider.instancer(InstanceTypes.ORIENTED, VirtualRenderHelper.blockModel(AllBlocks.ROPE.getDefaultState()), RenderStage.AFTER_BLOCK_ENTITIES);
} }
protected Instancer<OrientedInstance> getMagnetModel() { protected Instancer<OrientedInstance> getMagnetModel() {
return instancerProvider.instancer(InstanceTypes.ORIENTED, Models.block(AllBlocks.PULLEY_MAGNET.getDefaultState()), RenderStage.AFTER_BLOCK_ENTITIES); return instancerProvider.instancer(InstanceTypes.ORIENTED, VirtualRenderHelper.blockModel(AllBlocks.PULLEY_MAGNET.getDefaultState()), RenderStage.AFTER_BLOCK_ENTITIES);
} }
protected Instancer<OrientedInstance> getHalfMagnetModel() { protected Instancer<OrientedInstance> getHalfMagnetModel() {

View file

@ -1,8 +1,8 @@
package com.simibubi.create.content.kinetics.base; package com.simibubi.create.content.kinetics.base;
import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import net.minecraft.world.level.block.state.BlockState;
public class ShaftInstance<T extends KineticBlockEntity> extends SingleRotatingInstance<T> { public class ShaftInstance<T extends KineticBlockEntity> extends SingleRotatingInstance<T> {
@ -11,8 +11,7 @@ public class ShaftInstance<T extends KineticBlockEntity> extends SingleRotatingI
} }
@Override @Override
protected BlockState getRenderedBlockState() { protected Model model() {
return shaft(); return VirtualRenderHelper.blockModel(shaft());
} }
} }

View file

@ -4,13 +4,10 @@ import java.util.function.Consumer;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.model.Model; import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.model.Models;
import com.simibubi.create.foundation.render.AllInstanceTypes; import com.simibubi.create.foundation.render.AllInstanceTypes;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import net.minecraft.world.level.block.state.BlockState;
public class SingleRotatingInstance<T extends KineticBlockEntity> extends KineticBlockEntityInstance<T> { public class SingleRotatingInstance<T extends KineticBlockEntity> extends KineticBlockEntityInstance<T> {
@ -22,8 +19,9 @@ public class SingleRotatingInstance<T extends KineticBlockEntity> extends Kineti
@Override @Override
public void init(float pt) { public void init(float pt) {
var instance = getModel().createInstance(); rotatingModel = instancerProvider.instancer(AllInstanceTypes.ROTATING, model(), RenderStage.AFTER_BLOCK_ENTITIES)
rotatingModel = setup(instance); .createInstance();
setup(rotatingModel);
} }
@Override @Override
@ -41,16 +39,8 @@ public class SingleRotatingInstance<T extends KineticBlockEntity> extends Kineti
rotatingModel.delete(); rotatingModel.delete();
} }
protected BlockState getRenderedBlockState() {
return blockState;
}
protected Instancer<RotatingInstance> getModel() {
return instancerProvider.instancer(AllInstanceTypes.ROTATING, model(), RenderStage.AFTER_BLOCK_ENTITIES);
}
protected Model model() { protected Model model() {
return Models.block(getRenderedBlockState()); return VirtualRenderHelper.blockModel(blockState);
} }
@Override @Override

View file

@ -35,6 +35,7 @@ public class BeltInstance extends KineticInstance {
} }
public BeltInstance setScrollTexture(SpriteShiftEntry spriteShift) { public BeltInstance setScrollTexture(SpriteShiftEntry spriteShift) {
// FIXME: these are null for some reason
TextureAtlasSprite source = spriteShift.getOriginal(); TextureAtlasSprite source = spriteShift.getOriginal();
TextureAtlasSprite target = spriteShift.getTarget(); TextureAtlasSprite target = spriteShift.getTarget();

View file

@ -4,7 +4,6 @@ import java.util.List;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.jozufozu.flywheel.api.model.Model; import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.lib.model.Models;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.kinetics.base.KineticBlockEntity; import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer; import com.simibubi.create.content.kinetics.base.KineticBlockEntityRenderer;
@ -18,6 +17,7 @@ import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsFormatt
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour; import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import com.simibubi.create.foundation.utility.Components; import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
@ -149,7 +149,7 @@ public class ValveHandleBlockEntity extends HandCrankBlockEntity {
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public Model getRenderedHandleInstance() { public Model getRenderedHandleInstance() {
return Models.block(getBlockState()); return VirtualRenderHelper.blockModel(getBlockState());
} }
@Override @Override

View file

@ -18,6 +18,7 @@ import com.simibubi.create.content.kinetics.base.IRotate;
import com.simibubi.create.content.kinetics.base.KineticBlockEntityInstance; import com.simibubi.create.content.kinetics.base.KineticBlockEntityInstance;
import com.simibubi.create.content.kinetics.base.RotatingInstance; import com.simibubi.create.content.kinetics.base.RotatingInstance;
import com.simibubi.create.foundation.render.AllInstanceTypes; import com.simibubi.create.foundation.render.AllInstanceTypes;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.NBTHelper;
@ -64,7 +65,7 @@ public class DeployerActorInstance extends ActorInstance {
hand = instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(handPose), RenderStage.AFTER_BLOCK_ENTITIES).createInstance(); hand = instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.partial(handPose), RenderStage.AFTER_BLOCK_ENTITIES).createInstance();
Direction.Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state); Direction.Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state);
shaft = instancerProvider.instancer(AllInstanceTypes.ROTATING, Models.block(KineticBlockEntityInstance.shaft(axis)), RenderStage.AFTER_BLOCK_ENTITIES) shaft = instancerProvider.instancer(AllInstanceTypes.ROTATING, VirtualRenderHelper.blockModel(KineticBlockEntityInstance.shaft(axis)), RenderStage.AFTER_BLOCK_ENTITIES)
.createInstance(); .createInstance();
int blockLight = localBlockLight(); int blockLight = localBlockLight();

View file

@ -9,12 +9,12 @@ import com.jozufozu.flywheel.api.visual.VisualFrameContext;
import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.instance.InstanceTypes;
import com.jozufozu.flywheel.lib.instance.TransformedInstance; import com.jozufozu.flywheel.lib.instance.TransformedInstance;
import com.jozufozu.flywheel.lib.model.Models;
import com.jozufozu.flywheel.lib.transform.TransformStack; import com.jozufozu.flywheel.lib.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.content.kinetics.base.KineticBlockEntityInstance; import com.simibubi.create.content.kinetics.base.KineticBlockEntityInstance;
import com.simibubi.create.content.kinetics.base.RotatingInstance; import com.simibubi.create.content.kinetics.base.RotatingInstance;
import com.simibubi.create.foundation.render.AllInstanceTypes; import com.simibubi.create.foundation.render.AllInstanceTypes;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -29,9 +29,9 @@ public class FlywheelInstance extends KineticBlockEntityInstance<FlywheelBlockEn
public FlywheelInstance(VisualizationContext materialManager, FlywheelBlockEntity blockEntity) { public FlywheelInstance(VisualizationContext materialManager, FlywheelBlockEntity blockEntity) {
super(materialManager, blockEntity); super(materialManager, blockEntity);
shaft = setup(instancerProvider.instancer(AllInstanceTypes.ROTATING, Models.block(shaft()), RenderStage.AFTER_BLOCK_ENTITIES) shaft = setup(instancerProvider.instancer(AllInstanceTypes.ROTATING, VirtualRenderHelper.blockModel(shaft()), RenderStage.AFTER_BLOCK_ENTITIES)
.createInstance()); .createInstance());
wheel = instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState), RenderStage.AFTER_BLOCK_ENTITIES) wheel = instancerProvider.instancer(InstanceTypes.TRANSFORMED, VirtualRenderHelper.blockModel(blockState), RenderStage.AFTER_BLOCK_ENTITIES)
.createInstance(); .createInstance();
animate(blockEntity.angle); animate(blockEntity.angle);

View file

@ -5,6 +5,7 @@ import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.model.Models; import com.jozufozu.flywheel.lib.model.Models;
import com.simibubi.create.AllPartialModels; import com.simibubi.create.AllPartialModels;
import com.simibubi.create.content.kinetics.base.SingleRotatingInstance; import com.simibubi.create.content.kinetics.base.SingleRotatingInstance;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.Rotation;
@ -26,7 +27,7 @@ public class SawInstance extends SingleRotatingInstance<SawBlockEntity> {
Direction facing = referenceState.getValue(BlockStateProperties.FACING); Direction facing = referenceState.getValue(BlockStateProperties.FACING);
return Models.partial(AllPartialModels.SHAFT_HALF, facing); return Models.partial(AllPartialModels.SHAFT_HALF, facing);
} else { } else {
return Models.block(shaft()); return VirtualRenderHelper.blockModel(shaft());
} }
} }
} }

View file

@ -3,7 +3,6 @@ package com.simibubi.create.content.kinetics.waterwheel;
import com.jozufozu.flywheel.api.model.Model; import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.model.ModelCache; import com.jozufozu.flywheel.lib.model.ModelCache;
import com.jozufozu.flywheel.lib.model.Models;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder; import com.jozufozu.flywheel.lib.model.baked.BakedModelBuilder;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.content.kinetics.base.CutoutRotatingInstance; import com.simibubi.create.content.kinetics.base.CutoutRotatingInstance;
@ -12,7 +11,6 @@ import com.simibubi.create.foundation.render.CachedBufferer;
import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.AxisDirection; import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
public class WaterWheelInstance<T extends WaterWheelBlockEntity> extends CutoutRotatingInstance<T> { public class WaterWheelInstance<T extends WaterWheelBlockEntity> extends CutoutRotatingInstance<T> {
@ -24,7 +22,7 @@ public class WaterWheelInstance<T extends WaterWheelBlockEntity> extends CutoutR
public WaterWheelInstance(VisualizationContext materialManager, T blockEntity, boolean large) { public WaterWheelInstance(VisualizationContext materialManager, T blockEntity, boolean large) {
super(materialManager, blockEntity); super(materialManager, blockEntity);
this.large = large; this.large = large;
key = new WaterWheelModelKey(large, getRenderedBlockState(), blockEntity.material); key = new WaterWheelModelKey(large, blockState, blockEntity.material);
} }
public static <T extends WaterWheelBlockEntity> WaterWheelInstance<T> standard(VisualizationContext materialManager, T blockEntity) { public static <T extends WaterWheelBlockEntity> WaterWheelInstance<T> standard(VisualizationContext materialManager, T blockEntity) {

View file

@ -12,7 +12,6 @@ import org.joml.Matrix4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.visualization.VisualizationContext; import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.lib.instance.InstanceTypes; import com.jozufozu.flywheel.lib.instance.InstanceTypes;
import com.jozufozu.flywheel.lib.instance.TransformedInstance; import com.jozufozu.flywheel.lib.instance.TransformedInstance;
@ -24,13 +23,13 @@ import com.mojang.blaze3d.vertex.VertexConsumer;
import com.simibubi.create.content.trains.entity.CarriageBogey; import com.simibubi.create.content.trains.entity.CarriageBogey;
import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.CachedBufferer;
import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.VirtualRenderHelper;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.model.data.ModelData;
/** /**
* This is a port of the bogey api from Extended Bogeys, If you are looking to implement your own bogeys you can find some helpful resources below: * This is a port of the bogey api from Extended Bogeys, If you are looking to implement your own bogeys you can find some helpful resources below:
@ -214,7 +213,7 @@ public abstract class BogeyRenderer {
*/ */
public void createModelInstance(VisualizationContext materialManager, BlockState state, int count) { public void createModelInstance(VisualizationContext materialManager, BlockState state, int count) {
var instancer = materialManager.instancerProvider() var instancer = materialManager.instancerProvider()
.instancer(InstanceTypes.TRANSFORMED, Models.block(state), RenderStage.AFTER_BLOCK_ENTITIES); .instancer(InstanceTypes.TRANSFORMED, VirtualRenderHelper.blockModel(state), RenderStage.AFTER_BLOCK_ENTITIES);
BogeyModelData[] modelData = IntStream.range(0, count) BogeyModelData[] modelData = IntStream.range(0, count)
.mapToObj(i -> instancer.createInstance()) .mapToObj(i -> instancer.createInstance())
.map(BogeyModelData::new) .map(BogeyModelData::new)

View file

@ -10,8 +10,8 @@ import com.jozufozu.flywheel.api.layout.IntegerRepr;
import com.jozufozu.flywheel.api.layout.LayoutBuilder; import com.jozufozu.flywheel.api.layout.LayoutBuilder;
import com.jozufozu.flywheel.lib.instance.SimpleInstanceType; import com.jozufozu.flywheel.lib.instance.SimpleInstanceType;
import com.simibubi.create.content.contraptions.actors.flwdata.ActorInstance; import com.simibubi.create.content.contraptions.actors.flwdata.ActorInstance;
import com.simibubi.create.content.kinetics.belt.BeltInstance;
import com.simibubi.create.content.kinetics.base.RotatingInstance; import com.simibubi.create.content.kinetics.base.RotatingInstance;
import com.simibubi.create.content.kinetics.belt.BeltInstance;
import com.simibubi.create.content.logistics.flwdata.FlapData; import com.simibubi.create.content.logistics.flwdata.FlapData;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@ -19,7 +19,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class AllInstanceTypes { public class AllInstanceTypes {
// FIXME: memory alignment issues and light being represented by bytes // FIXME: optimize layouts/pack fields together if possible
public static final InstanceType<RotatingInstance> ROTATING = SimpleInstanceType.builder(RotatingInstance::new) public static final InstanceType<RotatingInstance> ROTATING = SimpleInstanceType.builder(RotatingInstance::new)
.cullShader(asResource("instance/cull/rotating.glsl")) .cullShader(asResource("instance/cull/rotating.glsl"))
@ -39,14 +39,14 @@ public class AllInstanceTypes {
MemoryUtil.memPutByte(ptr + 5, instance.g); MemoryUtil.memPutByte(ptr + 5, instance.g);
MemoryUtil.memPutByte(ptr + 6, instance.b); MemoryUtil.memPutByte(ptr + 6, instance.b);
MemoryUtil.memPutByte(ptr + 7, instance.a); MemoryUtil.memPutByte(ptr + 7, instance.a);
MemoryUtil.memPutFloat(ptr + 6, instance.x); MemoryUtil.memPutFloat(ptr + 8, instance.x);
MemoryUtil.memPutFloat(ptr + 10, instance.y); MemoryUtil.memPutFloat(ptr + 12, instance.y);
MemoryUtil.memPutFloat(ptr + 14, instance.z); MemoryUtil.memPutFloat(ptr + 16, instance.z);
MemoryUtil.memPutFloat(ptr + 18, instance.rotationalSpeed); MemoryUtil.memPutFloat(ptr + 20, instance.rotationalSpeed);
MemoryUtil.memPutFloat(ptr + 22, instance.rotationOffset); MemoryUtil.memPutFloat(ptr + 24, instance.rotationOffset);
MemoryUtil.memPutByte(ptr + 26, instance.rotationAxisX); MemoryUtil.memPutByte(ptr + 28, instance.rotationAxisX);
MemoryUtil.memPutByte(ptr + 27, instance.rotationAxisY); MemoryUtil.memPutByte(ptr + 29, instance.rotationAxisY);
MemoryUtil.memPutByte(ptr + 28, instance.rotationAxisZ); MemoryUtil.memPutByte(ptr + 30, instance.rotationAxisZ);
}) })
.register(); .register();
public static final InstanceType<BeltInstance> BELTS = SimpleInstanceType.builder(BeltInstance::new) public static final InstanceType<BeltInstance> BELTS = SimpleInstanceType.builder(BeltInstance::new)
@ -70,22 +70,22 @@ public class AllInstanceTypes {
MemoryUtil.memPutByte(ptr + 5, instance.g); MemoryUtil.memPutByte(ptr + 5, instance.g);
MemoryUtil.memPutByte(ptr + 6, instance.b); MemoryUtil.memPutByte(ptr + 6, instance.b);
MemoryUtil.memPutByte(ptr + 7, instance.a); MemoryUtil.memPutByte(ptr + 7, instance.a);
MemoryUtil.memPutFloat(ptr + 6, instance.x); MemoryUtil.memPutFloat(ptr + 8, instance.x);
MemoryUtil.memPutFloat(ptr + 10, instance.y); MemoryUtil.memPutFloat(ptr + 12, instance.y);
MemoryUtil.memPutFloat(ptr + 14, instance.z); MemoryUtil.memPutFloat(ptr + 16, instance.z);
MemoryUtil.memPutFloat(ptr + 18, instance.rotationalSpeed); MemoryUtil.memPutFloat(ptr + 20, instance.rotationalSpeed);
MemoryUtil.memPutFloat(ptr + 22, instance.rotationOffset); MemoryUtil.memPutFloat(ptr + 24, instance.rotationOffset);
MemoryUtil.memPutFloat(ptr + 26, instance.qX); MemoryUtil.memPutFloat(ptr + 28, instance.qX);
MemoryUtil.memPutFloat(ptr + 30, instance.qY); MemoryUtil.memPutFloat(ptr + 32, instance.qY);
MemoryUtil.memPutFloat(ptr + 34, instance.qZ); MemoryUtil.memPutFloat(ptr + 36, instance.qZ);
MemoryUtil.memPutFloat(ptr + 38, instance.qW); MemoryUtil.memPutFloat(ptr + 40, instance.qW);
MemoryUtil.memPutFloat(ptr + 42, instance.sourceU); MemoryUtil.memPutFloat(ptr + 44, instance.sourceU);
MemoryUtil.memPutFloat(ptr + 46, instance.sourceV); MemoryUtil.memPutFloat(ptr + 48, instance.sourceV);
MemoryUtil.memPutFloat(ptr + 50, instance.minU); MemoryUtil.memPutFloat(ptr + 52, instance.minU);
MemoryUtil.memPutFloat(ptr + 54, instance.minV); MemoryUtil.memPutFloat(ptr + 56, instance.minV);
MemoryUtil.memPutFloat(ptr + 58, instance.maxU); MemoryUtil.memPutFloat(ptr + 60, instance.maxU);
MemoryUtil.memPutFloat(ptr + 62, instance.maxV); MemoryUtil.memPutFloat(ptr + 64, instance.maxV);
MemoryUtil.memPutByte(ptr + 66, instance.scrollMult); MemoryUtil.memPutByte(ptr + 68, instance.scrollMult);
}) })
.register(); .register();
public static final InstanceType<ActorInstance> ACTORS = SimpleInstanceType.builder(ActorInstance::new) public static final InstanceType<ActorInstance> ACTORS = SimpleInstanceType.builder(ActorInstance::new)
@ -104,20 +104,20 @@ public class AllInstanceTypes {
MemoryUtil.memPutFloat(ptr, instance.x); MemoryUtil.memPutFloat(ptr, instance.x);
MemoryUtil.memPutFloat(ptr + 4, instance.y); MemoryUtil.memPutFloat(ptr + 4, instance.y);
MemoryUtil.memPutFloat(ptr + 8, instance.z); MemoryUtil.memPutFloat(ptr + 8, instance.z);
MemoryUtil.memPutByte(ptr + 12, instance.blockLight); MemoryUtil.memPutShort(ptr + 12, instance.blockLight);
MemoryUtil.memPutByte(ptr + 13, instance.skyLight); MemoryUtil.memPutShort(ptr + 14, instance.skyLight);
MemoryUtil.memPutFloat(ptr + 14, instance.rotationOffset); MemoryUtil.memPutFloat(ptr + 16, instance.rotationOffset);
MemoryUtil.memPutByte(ptr + 18, instance.rotationAxisX); MemoryUtil.memPutByte(ptr + 20, instance.rotationAxisX);
MemoryUtil.memPutByte(ptr + 19, instance.rotationAxisY); MemoryUtil.memPutByte(ptr + 21, instance.rotationAxisY);
MemoryUtil.memPutByte(ptr + 20, instance.rotationAxisZ); MemoryUtil.memPutByte(ptr + 22, instance.rotationAxisZ);
MemoryUtil.memPutFloat(ptr + 21, instance.qX); MemoryUtil.memPutFloat(ptr + 24, instance.qX);
MemoryUtil.memPutFloat(ptr + 25, instance.qY); MemoryUtil.memPutFloat(ptr + 28, instance.qY);
MemoryUtil.memPutFloat(ptr + 29, instance.qZ); MemoryUtil.memPutFloat(ptr + 32, instance.qZ);
MemoryUtil.memPutFloat(ptr + 33, instance.qW); MemoryUtil.memPutFloat(ptr + 34, instance.qW);
MemoryUtil.memPutByte(ptr + 37, instance.rotationCenterX); MemoryUtil.memPutByte(ptr + 38, instance.rotationCenterX);
MemoryUtil.memPutByte(ptr + 38, instance.rotationCenterY); MemoryUtil.memPutByte(ptr + 39, instance.rotationCenterY);
MemoryUtil.memPutByte(ptr + 39, instance.rotationCenterZ); MemoryUtil.memPutByte(ptr + 40, instance.rotationCenterZ);
MemoryUtil.memPutFloat(ptr + 40, instance.speed); MemoryUtil.memPutFloat(ptr + 42, instance.speed);
}) })
.register(); .register();
public static final InstanceType<FlapData> FLAPS = SimpleInstanceType.builder(FlapData::new) public static final InstanceType<FlapData> FLAPS = SimpleInstanceType.builder(FlapData::new)
@ -137,18 +137,18 @@ public class AllInstanceTypes {
MemoryUtil.memPutFloat(ptr, instance.x); MemoryUtil.memPutFloat(ptr, instance.x);
MemoryUtil.memPutFloat(ptr + 4, instance.y); MemoryUtil.memPutFloat(ptr + 4, instance.y);
MemoryUtil.memPutFloat(ptr + 8, instance.z); MemoryUtil.memPutFloat(ptr + 8, instance.z);
MemoryUtil.memPutByte(ptr + 12, (byte) (instance.blockLight << 4)); MemoryUtil.memPutShort(ptr + 12, instance.blockLight);
MemoryUtil.memPutByte(ptr + 13, (byte) (instance.skyLight << 4)); MemoryUtil.memPutShort(ptr + 14, instance.skyLight);
MemoryUtil.memPutFloat(ptr + 14, instance.segmentOffsetX); MemoryUtil.memPutFloat(ptr + 16, instance.segmentOffsetX);
MemoryUtil.memPutFloat(ptr + 18, instance.segmentOffsetY); MemoryUtil.memPutFloat(ptr + 20, instance.segmentOffsetY);
MemoryUtil.memPutFloat(ptr + 22, instance.segmentOffsetZ); MemoryUtil.memPutFloat(ptr + 24, instance.segmentOffsetZ);
MemoryUtil.memPutFloat(ptr + 26, instance.pivotX); MemoryUtil.memPutFloat(ptr + 28, instance.pivotX);
MemoryUtil.memPutFloat(ptr + 30, instance.pivotY); MemoryUtil.memPutFloat(ptr + 32, instance.pivotY);
MemoryUtil.memPutFloat(ptr + 34, instance.pivotZ); MemoryUtil.memPutFloat(ptr + 36, instance.pivotZ);
MemoryUtil.memPutFloat(ptr + 38, instance.horizontalAngle); MemoryUtil.memPutFloat(ptr + 40, instance.horizontalAngle);
MemoryUtil.memPutFloat(ptr + 42, instance.intensity); MemoryUtil.memPutFloat(ptr + 44, instance.intensity);
MemoryUtil.memPutFloat(ptr + 46, instance.flapScale); MemoryUtil.memPutFloat(ptr + 48, instance.flapScale);
MemoryUtil.memPutFloat(ptr + 50, instance.flapness); MemoryUtil.memPutFloat(ptr + 52, instance.flapness);
}) })
.register(); .register();

View file

@ -7,9 +7,12 @@ import java.util.List;
import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableInt;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.lib.model.ModelCache;
import com.jozufozu.flywheel.lib.model.ModelUtil; import com.jozufozu.flywheel.lib.model.ModelUtil;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer; import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer;
import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer; import com.jozufozu.flywheel.lib.model.baked.BakedModelBufferer.ShadeSeparatedResultConsumer;
import com.jozufozu.flywheel.lib.model.baked.BlockModelBuilder;
import com.jozufozu.flywheel.lib.model.baked.VirtualEmptyBlockGetter; import com.jozufozu.flywheel.lib.model.baked.VirtualEmptyBlockGetter;
import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer; import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer;
@ -24,11 +27,21 @@ import net.minecraftforge.client.model.data.ModelProperty;
public class VirtualRenderHelper { public class VirtualRenderHelper {
public static final ModelProperty<Boolean> VIRTUAL_PROPERTY = new ModelProperty<>(); public static final ModelProperty<Boolean> VIRTUAL_PROPERTY = new ModelProperty<>();
public static final ModelData VIRTUAL_DATA = ModelData.builder().with(VIRTUAL_PROPERTY, true).build(); public static final ModelData VIRTUAL_DATA = ModelData.builder().with(VIRTUAL_PROPERTY, true).build();
public static final ModelCache<BlockState> VIRTUAL_BLOCKS = new ModelCache<>(state -> new BlockModelBuilder(state).modelData(VIRTUAL_DATA).build());
public static boolean isVirtual(ModelData data) { public static boolean isVirtual(ModelData data) {
return data.has(VirtualRenderHelper.VIRTUAL_PROPERTY) && data.get(VirtualRenderHelper.VIRTUAL_PROPERTY); return data.has(VirtualRenderHelper.VIRTUAL_PROPERTY) && data.get(VirtualRenderHelper.VIRTUAL_PROPERTY);
} }
/**
* A copy of {@link com.jozufozu.flywheel.lib.model.Models#block(BlockState)}, but with virtual model data passed in.
* @param state The block state to get the model for.
* @return The model for the given block state.
*/
public static Model blockModel(BlockState state) {
return VIRTUAL_BLOCKS.get(state);
}
public static SuperByteBuffer bufferBlock(BlockState state) { public static SuperByteBuffer bufferBlock(BlockState state) {
return bufferModel(ModelUtil.VANILLA_RENDERER.getBlockModel(state), state); return bufferModel(ModelUtil.VANILLA_RENDERER.getBlockModel(state), state);
} }