Merge remote-tracking branch 'origin/1.18/dev' into 1.18/fabric/dev

Conflicts:
	build.gradle
	src/main/java/com/jozufozu/flywheel/backend/Backend.java
	src/main/java/com/jozufozu/flywheel/backend/OptifineHandler.java
	src/main/java/com/jozufozu/flywheel/backend/instancing/batching/BatchedMaterialGroup.java
	src/main/java/com/jozufozu/flywheel/core/model/ModelTransformer.java
	src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java
	src/main/java/com/jozufozu/flywheel/util/RenderMath.java
This commit is contained in:
PepperCode1 2022-02-12 21:38:01 -08:00
commit 9cc6523368
19 changed files with 198 additions and 214 deletions

View file

@ -59,6 +59,7 @@ body:
label: Mod Version
description: The version of the mod you were using when the bug occured
options:
- "0.6.1"
- "0.6.0"
- "0.5.1"
- "0.5.0a"

View file

@ -6,10 +6,10 @@ plugins {
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false');
ext.buildnumber = 0
project.buildnumber = System.getenv('BUILD_NUMBER') != null ? System.getenv('BUILD_NUMBER') : 'custom'
ext.buildNumber = System.getenv('BUILD_NUMBER')
if (buildNumber == null) buildNumber = 'custom'
version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildnumber}" : '')
version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildNumber}" : '')
group = 'com.jozufozu.flywheel'
archivesBaseName = 'flywheel-fabric'
@ -55,7 +55,7 @@ dependencies {
// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}"
modCompileOnly 'curse.maven:starlight-521783:3554912'
modCompileOnly 'curse.maven:starlight-521783:3599857'
modCompileOnly 'maven.modrinth:iris:1.18.x-v1.1.4'
modCompileOnly 'maven.modrinth:sodium:mc1.18.1-0.4.0-alpha6'

View file

@ -10,6 +10,7 @@ import com.jozufozu.flywheel.util.Pair;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
public interface Material<D extends InstanceData> {
@ -26,6 +27,10 @@ public interface Material<D extends InstanceData> {
return model(partial, () -> new BlockModel(partial.get(), referenceState));
}
default Instancer<D> getModel(PartialModel partial) {
return model(partial, () -> new BlockModel(partial.get(), Blocks.AIR.defaultBlockState()));
}
default Instancer<D> getModel(PartialModel partial, BlockState referenceState, Direction dir) {
return getModel(partial, referenceState, dir, ModelUtil.rotateToFace(dir));
}

View file

@ -32,7 +32,7 @@ public class Backend {
* (Meshlet, MDI, GL31 Draw Instanced are planned), this will name which one is in use.
*/
public static String getBackendDescriptor() {
return engine == null ? "" : engine.getProperName();
return engine == null ? "Uninitialized" : engine.getProperName();
}
@Nullable
@ -77,7 +77,7 @@ public class Backend {
FlwEngine preferredChoice = FlwConfig.get()
.getEngine();
boolean usingShaders = IrisShaderHandler.areShadersEnabled();
boolean usingShaders = IrisShaderHandler.isShaderPackInUse();
boolean canUseEngine = switch (preferredChoice) {
case OFF -> true;
case BATCHING -> !usingShaders;

View file

@ -19,10 +19,6 @@ public class IrisShaderHandler {
private IrisShaderHandler() {
}
public static boolean areShadersEnabled() {
return HANDLER.areShadersEnabled();
}
public static boolean isShaderPackInUse() {
return HANDLER.isShaderPackInUse();
}
@ -32,10 +28,6 @@ public class IrisShaderHandler {
}
private interface InternalHandler {
default boolean areShadersEnabled() {
return false;
};
default boolean isShaderPackInUse() {
return false;
};
@ -46,11 +38,6 @@ public class IrisShaderHandler {
}
private static class InternalHandlerImpl implements InternalHandler {
@Override
public boolean areShadersEnabled() {
return IrisApi.getInstance().getConfig().areShadersEnabled();
};
@Override
public boolean isShaderPackInUse() {
return IrisApi.getInstance().isShaderPackInUse();

View file

@ -12,6 +12,7 @@ import com.jozufozu.flywheel.core.Contexts;
import com.jozufozu.flywheel.core.shader.WorldProgram;
import com.jozufozu.flywheel.event.BeginFrameEvent;
import com.jozufozu.flywheel.event.RenderLayerEvent;
import com.jozufozu.flywheel.util.ClientLevelExtension;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
@ -130,7 +131,8 @@ public class InstanceWorld {
public void loadEntities(ClientLevel world) {
// Block entities are loaded while chunks are baked.
// Entities are loaded with the world, so when chunks are reloaded they need to be re-added.
world.entitiesForRendering()
ClientLevelExtension.cast(world)
.flywheel$getAllLoadedEntities()
.forEach(entityInstanceManager::add);
}

View file

@ -2,6 +2,10 @@ package com.jozufozu.flywheel.core.materials;
import com.jozufozu.flywheel.api.InstanceData;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.LightLayer;
/**
* An interface that implementors of {@link InstanceData} should also implement
* if they wish to make use of Flywheel's provided light update methods.
@ -25,5 +29,10 @@ public interface FlatLit<D extends InstanceData & FlatLit<D>> {
*/
D setSkyLight(int skyLight);
default D updateLight(BlockAndTintGetter level, BlockPos pos) {
return setBlockLight(level.getBrightness(LightLayer.BLOCK, pos))
.setSkyLight(level.getBrightness(LightLayer.SKY, pos));
}
int getPackedLight();
}

View file

@ -1,7 +1,7 @@
package com.jozufozu.flywheel.core.model;
import com.jozufozu.flywheel.api.vertex.VertexList;
import com.jozufozu.flywheel.util.RenderMath;
import com.jozufozu.flywheel.util.DiffuseLightCalculator;
import com.jozufozu.flywheel.util.transform.Transform;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@ -47,7 +47,9 @@ public class ModelTransformer {
normalMat = params.normal.copy();
}
int vertexCount = reader.getVertexCount();
final DiffuseLightCalculator diffuseCalculator = DiffuseLightCalculator.forCurrentLevel();
final int vertexCount = reader.getVertexCount();
for (int i = 0; i < vertexCount; i++) {
float x = reader.getX(i);
float y = reader.getY(i);
@ -67,23 +69,26 @@ public class ModelTransformer {
float ny = normal.y();
float nz = normal.z();
byte r, g, b, a;
if (params.useParamColor) {
if (context.outputColorDiffuse) {
float instanceDiffuse = RenderMath.diffuseLight(nx, ny, nz);
int colorR = transformColor(params.r, instanceDiffuse);
int colorG = transformColor(params.g, instanceDiffuse);
int colorB = transformColor(params.b, instanceDiffuse);
builder.color(colorR, colorG, colorB, params.a);
} else {
builder.color(params.r, params.g, params.b, params.a);
}
r = (byte) params.r;
g = (byte) params.g;
b = (byte) params.b;
a = (byte) params.a;
} else {
if (context.outputColorDiffuse) {
int d = RenderMath.unb(RenderMath.diffuseLight(nx, ny, nz));
builder.color(d, d, d, 0xFF);
} else {
builder.color(reader.getR(i), reader.getG(i), reader.getB(i), reader.getA(i));
}
r = reader.getR(i);
g = reader.getG(i);
b = reader.getB(i);
a = reader.getA(i);
}
if (context.outputColorDiffuse) {
float instanceDiffuse = diffuseCalculator.getDiffuse(nx, ny, nz);
int colorR = transformColor(r, instanceDiffuse);
int colorG = transformColor(g, instanceDiffuse);
int colorB = transformColor(b, instanceDiffuse);
builder.color(colorR, colorG, colorB, a);
} else {
builder.color(r, g, b, a);
}
//builder.color(Math.max(0, (int) (nx * 255)), Math.max(0, (int) (ny * 255)), Math.max(0, (int) (nz * 255)), 0xFF);
@ -117,6 +122,10 @@ public class ModelTransformer {
return "ModelTransformer[" + model + ']';
}
public static int transformColor(byte component, float scale) {
return Mth.clamp((int) (Byte.toUnsignedInt(component) * scale), 0, 255);
}
public static int transformColor(int component, float scale) {
return Mth.clamp((int) (component * scale), 0, 255);
}
@ -136,7 +145,6 @@ public class ModelTransformer {
* Do we need to bake diffuse lighting into the output colors?
*/
public boolean outputColorDiffuse = true;
}
public static class Params implements Transform<Params> {

View file

@ -1,6 +1,5 @@
package com.jozufozu.flywheel.core.model;
import java.util.Arrays;
import java.util.Collection;
import java.util.Random;
import java.util.function.Supplier;
@ -10,7 +9,6 @@ import com.jozufozu.flywheel.fabric.model.CullingBakedModel;
import com.jozufozu.flywheel.fabric.model.DefaultLayerFilteringBakedModel;
import com.jozufozu.flywheel.fabric.model.FabricModelUtil;
import com.jozufozu.flywheel.fabric.model.LayerFilteringBakedModel;
import com.jozufozu.flywheel.util.Lazy;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
@ -20,7 +18,7 @@ import com.mojang.blaze3d.vertex.VertexFormat;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.BlockModelShaper;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.block.ModelBlockRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.resources.model.BakedModel;
@ -32,17 +30,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
public class ModelUtil {
private static final Lazy<ModelBlockRenderer> MODEL_RENDERER = Lazy.of(() -> new ModelBlockRenderer(Minecraft.getInstance().getBlockColors()));
// DOWN, UP, NORTH, SOUTH, WEST, EAST, null
private static final Direction[] CULL_FACES;
static {
Direction[] directions = Direction.values();
CULL_FACES = Arrays.copyOf(directions, directions.length + 1);
}
public static BufferBuilder getBufferBuilder(BakedModel model, BlockState referenceState, PoseStack ms) {
ModelBlockRenderer blockRenderer = Minecraft.getInstance().getBlockRenderer().getModelRenderer();
BufferBuilder builder = new BufferBuilder(512);
@ -55,8 +42,8 @@ public class ModelUtil {
}
public static BufferBuilder getBufferBuilderFromTemplate(BlockAndTintGetter renderWorld, RenderType layer, Collection<StructureTemplate.StructureBlockInfo> blocks) {
ModelBlockRenderer modelRenderer = MODEL_RENDERER.get();
BlockModelShaper blockModels = Minecraft.getInstance().getModelManager().getBlockModelShaper();
BlockRenderDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer();
ModelBlockRenderer modelRenderer = dispatcher.getModelRenderer();
PoseStack ms = new PoseStack();
Random random = new Random();
@ -70,7 +57,7 @@ public class ModelUtil {
if (state.getRenderShape() != RenderShape.MODEL)
continue;
BakedModel model = blockModels.getBlockModel(state);
BakedModel model = dispatcher.getBlockModel(state);
if (((FabricBakedModel) model).isVanillaAdapter()) {
if (!FabricModelUtil.doesLayerMatch(state, layer)) {
continue;

View file

@ -1,51 +0,0 @@
package com.jozufozu.flywheel.mixin;
import java.util.ArrayList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Group;
import org.spongepowered.asm.mixin.injection.Redirect;
import com.google.common.collect.Lists;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.world.entity.Entity;
@Mixin(LevelRenderer.class)
public class CancelEntityRenderMixin {
// TODO: Don't use redirect
@Group(name = "entityFilter", min = 1, max = 1)
@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;entitiesForRendering()Ljava/lang/Iterable;"))
private Iterable<Entity> filterEntities(ClientLevel world) {
Iterable<Entity> entities = world.entitiesForRendering();
if (Backend.isOn()) {
ArrayList<Entity> filtered = Lists.newArrayList(entities);
filtered.removeIf(InstancedRenderRegistry::shouldSkipRender);
return filtered;
}
return entities;
}
// @Group(name = "entityFilter")
// @Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ClassInstanceMultiMap;iterator()Ljava/util/Iterator;"))
// private Iterator<Entity> filterEntitiesOF(ClassInstanceMultiMap<Entity> classInheritanceMultiMap) {
// if (Backend.getInstance()
// .canUseInstancing()) {
//
// ArrayList<Entity> filtered = Lists.newArrayList(classInheritanceMultiMap);
//
// InstancedRenderRegistry r = InstancedRenderRegistry.getInstance();
// filtered.removeIf(r::shouldSkipRender);
//
// return filtered.iterator();
// }
// return classInheritanceMultiMap.iterator();
// }
}

View file

@ -0,0 +1,42 @@
package com.jozufozu.flywheel.mixin;
import java.util.ArrayList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.InstancedRenderRegistry;
import com.jozufozu.flywheel.util.ClientLevelExtension;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.entity.LevelEntityGetter;
@Mixin(ClientLevel.class)
public abstract class ClientLevelMixin implements ClientLevelExtension {
@Shadow
protected abstract LevelEntityGetter<Entity> getEntities();
@Override
public Iterable<Entity> flywheel$getAllLoadedEntities() {
return getEntities().getAll();
}
@Inject(method = "entitiesForRendering", at = @At("RETURN"), cancellable = true)
private void filterEntities(CallbackInfoReturnable<Iterable<Entity>> cir) {
if (Backend.isOn()) {
Iterable<Entity> entities = cir.getReturnValue();
ArrayList<Entity> filtered = Lists.newArrayList(entities);
filtered.removeIf(InstancedRenderRegistry::shouldSkipRender);
cir.setReturnValue(filtered);
}
}
}

View file

@ -0,0 +1,22 @@
package com.jozufozu.flywheel.util;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
public interface ClientLevelExtension {
/**
* Get an iterator over all entities in this level.
*
* <p>
* Normally, this would be accomplished by {@link ClientLevel#entitiesForRendering()}, but the output of that
* method is filtered of entities that are rendered by flywheel. This interface provides a workaround.
* </p>
* @return An iterator over all entities in the level, including entities that are rendered by flywheel.
*/
Iterable<Entity> flywheel$getAllLoadedEntities();
static ClientLevelExtension cast(ClientLevel level) {
return (ClientLevelExtension) level;
}
}

View file

@ -0,0 +1,19 @@
package com.jozufozu.flywheel.util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
public interface DiffuseLightCalculator {
DiffuseLightCalculator DEFAULT = RenderMath::diffuseLight;
DiffuseLightCalculator NETHER = RenderMath::diffuseLightNether;
static DiffuseLightCalculator forCurrentLevel() {
return forLevel(Minecraft.getInstance().level);
}
static DiffuseLightCalculator forLevel(ClientLevel level) {
return level.effects().constantAmbientLight() ? NETHER : DEFAULT;
}
float getDiffuse(float normalX, float normalY, float normalZ);
}

View file

@ -71,4 +71,8 @@ public class RenderMath {
public static float diffuseLight(float x, float y, float z) {
return Math.min(x * x * 0.6f + y * y * ((3f + y) / 4f) + z * z * 0.8f, 1f);
}
public static float diffuseLightNether(float x, float y, float z) {
return Math.min(x * x * 0.6f + y * y * 0.9f + z * z * 0.8f, 1f);
}
}

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.util.box;
import java.util.Collection;
import com.jozufozu.flywheel.util.RenderMath;
import net.minecraft.core.BlockPos;
@ -61,7 +63,28 @@ public class GridAlignedBB implements ImmutableBox {
return new GridAlignedBB(startX, 0, startZ, startX + 16, 256, startZ + 16);
}
public void fixMinMax() {
public static ImmutableBox containingAll(Collection<BlockPos> positions) {
if (positions.isEmpty()) {
return new GridAlignedBB();
}
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int minZ = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int maxY = Integer.MIN_VALUE;
int maxZ = Integer.MIN_VALUE;
for (BlockPos pos : positions) {
minX = Math.min(minX, pos.getX());
minY = Math.min(minY, pos.getY());
minZ = Math.min(minZ, pos.getZ());
maxX = Math.max(maxX, pos.getX());
maxY = Math.max(maxY, pos.getY());
maxZ = Math.max(maxZ, pos.getZ());
}
return new GridAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
}
public void fixMinMax() {
int minX = Math.min(this.minX, this.maxX);
int minY = Math.min(this.minY, this.maxY);
int minZ = Math.min(this.minZ, this.maxZ);

View file

@ -1,81 +0,0 @@
package com.jozufozu.flywheel.util.transform;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;
public class MatrixTransformStack implements TransformStack {
private final PoseStack internal;
public MatrixTransformStack() {
this(new PoseStack());
}
public MatrixTransformStack(PoseStack internal) {
this.internal = internal;
}
public PoseStack unwrap() {
return internal;
}
public MatrixTransformStack setIdentity() {
if (internal.clear()) {
PoseStack.Pose last = internal.last();
last.normal()
.setIdentity();
last.pose()
.setIdentity();
} else {
internal.popPose();
internal.pushPose();
}
return this;
}
@Override
public TransformStack translate(double x, double y, double z) {
internal.translate(x, y, z);
return this;
}
@Override
public TransformStack multiply(Quaternion quaternion) {
internal.mulPose(quaternion);
return this;
}
@Override
public TransformStack scale(float factorX, float factorY, float factorZ) {
internal.scale(factorX, factorY, factorZ);
return this;
}
@Override
public TransformStack pushPose() {
internal.pushPose();
return this;
}
@Override
public TransformStack popPose() {
internal.popPose();
return this;
}
@Override
public TransformStack mulPose(Matrix4f pose) {
internal.last().pose().multiply(pose);
return this;
}
@Override
public TransformStack mulNormal(Matrix3f normal) {
internal.last().normal().mul(normal);
return this;
}
}

View file

@ -9,7 +9,8 @@ import com.jozufozu.flywheel.core.hardcoded.ModelPart;
import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.core.model.Model;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.RenderType;
@ -25,7 +26,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png");
MatrixTransformStack stack = new MatrixTransformStack();
private final PoseStack stack = new PoseStack();
private final ModelData body;
private ModelData contents;
@ -53,11 +54,12 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
@Override
public void beginFrame() {
TransformStack tstack = TransformStack.cast(stack);
stack.setIdentity();
float pt = AnimationTickHolder.getPartialTicks();
Vec3i originCoordinate = materialManager.getOriginCoordinate();
stack.translate(
tstack.translate(
Mth.lerp(pt, entity.xOld, entity.getX()) - originCoordinate.getX(),
Mth.lerp(pt, entity.yOld, entity.getY()) - originCoordinate.getY(),
Mth.lerp(pt, entity.zOld, entity.getZ()) - originCoordinate.getZ());
@ -69,8 +71,8 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
float f = (((float)(i >> 16 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F;
float f1 = (((float)(i >> 20 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F;
float f2 = (((float)(i >> 24 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F;
stack.translate(f, f1, f2);
stack.nudge(entity.getId());
tstack.translate(f, f1, f2);
tstack.nudge(entity.getId());
double d0 = Mth.lerp(pt, entity.xOld, entity.getX());
double d1 = Mth.lerp(pt, entity.yOld, entity.getY());
double d2 = Mth.lerp(pt, entity.zOld, entity.getZ());
@ -87,7 +89,7 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
vector3d2 = vector3d;
}
stack.translate(vector3d.x - d0, (vector3d1.y + vector3d2.y) / 2.0D - d1, vector3d.z - d2);
tstack.translate(vector3d.x - d0, (vector3d1.y + vector3d2.y) / 2.0D - d1, vector3d.z - d2);
Vec3 vector3d3 = vector3d2.add(-vector3d1.x, -vector3d1.y, -vector3d1.z);
if (vector3d3.length() != 0.0D) {
vector3d3 = vector3d3.normalize();
@ -96,9 +98,9 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
}
}
stack.translate(0.0D, 0.375D, 0.0D);
stack.multiply(Vector3f.YP.rotationDegrees(180 - yaw));
stack.multiply(Vector3f.ZP.rotationDegrees(-f3));
tstack.translate(0.0D, 0.375D, 0.0D);
tstack.multiply(Vector3f.YP.rotationDegrees(180 - yaw));
tstack.multiply(Vector3f.ZP.rotationDegrees(-f3));
float f5 = (float)entity.getHurtTime() - pt;
float f6 = entity.getDamage() - pt;
if (f6 < 0) {
@ -106,20 +108,20 @@ public class MinecartInstance<T extends AbstractMinecart> extends EntityInstance
}
if (f5 > 0) {
stack.multiply(Vector3f.XP.rotationDegrees(Mth.sin(f5) * f5 * f6 / 10 * (float)entity.getHurtDir()));
tstack.multiply(Vector3f.XP.rotationDegrees(Mth.sin(f5) * f5 * f6 / 10 * (float)entity.getHurtDir()));
}
int j = entity.getDisplayOffset();
if (contents != null) {
stack.pushPose();
stack.scale(0.75F);
stack.translate(-0.5D, (float)(j - 8) / 16, 0.5D);
stack.multiply(Vector3f.YP.rotationDegrees(90));
contents.setTransform(stack.unwrap());
stack.popPose();
tstack.pushPose();
tstack.scale(0.75F);
tstack.translate(-0.5D, (float)(j - 8) / 16, 0.5D);
tstack.multiply(Vector3f.YP.rotationDegrees(90));
contents.setTransform(stack);
tstack.popPose();
}
body.setTransform(stack.unwrap());
body.setTransform(stack);
}
@Override

View file

@ -7,7 +7,8 @@ import com.jozufozu.flywheel.core.Materials;
import com.jozufozu.flywheel.core.hardcoded.ModelPart;
import com.jozufozu.flywheel.core.materials.model.ModelData;
import com.jozufozu.flywheel.util.AnimationTickHolder;
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
import com.jozufozu.flywheel.util.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
@ -25,7 +26,7 @@ public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntit
private final ModelData base;
private final ModelData lid;
private final MatrixTransformStack stack = new MatrixTransformStack();
private final PoseStack stack = new PoseStack();
private float lastProgress = Float.NaN;
@ -40,18 +41,20 @@ public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntit
}
Quaternion rotation = getDirection().getRotation();
stack.translate(getInstancePosition())
TransformStack tstack = TransformStack.cast(stack);
tstack.translate(getInstancePosition())
.scale(0.9995f)
.translateAll(0.00025)
.centre()
.multiply(rotation)
.unCentre();
base = makeBaseInstance().setTransform(stack.unwrap());
base = makeBaseInstance().setTransform(stack);
stack.translateY(0.25);
tstack.translateY(0.25);
lid = makeLidInstance().setTransform(stack.unwrap());
lid = makeLidInstance().setTransform(stack);
}
@Override
@ -63,13 +66,15 @@ public class ShulkerBoxInstance extends BlockEntityInstance<ShulkerBoxBlockEntit
Quaternion spin = Vector3f.YP.rotationDegrees(270.0F * progress);
stack.pushPose()
TransformStack tstack = TransformStack.cast(stack);
tstack.pushPose()
.centre()
.multiply(spin)
.unCentre()
.translateY(progress * 0.5f);
lid.setTransform(stack.unwrap());
lid.setTransform(stack);
stack.popPose();
}

View file

@ -9,7 +9,7 @@
"BufferBuilderMixin",
"BufferUploaderMixin",
"CameraMixin",
"CancelEntityRenderMixin",
"ClientLevelMixin",
"ChunkRebuildHooksMixin",
"EntityTypeMixin",
"FixFabulousDepthMixin",