Added HWYLA
This commit is contained in:
@@ -63,7 +63,7 @@ public enum FacingToRotation implements StringIdentifiable {
|
||||
private final Quaternion combinedRotation;
|
||||
private final Matrix4f mat;
|
||||
|
||||
private FacingToRotation(Vector3f rot) {
|
||||
FacingToRotation(Vector3f rot) {
|
||||
this.rot = rot;
|
||||
this.mat = new Matrix4f();
|
||||
this.mat.loadIdentity();
|
||||
|
||||
@@ -24,10 +24,7 @@ import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.client.util.math.Vector4f;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Matrix3f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
|
||||
import java.util.EnumMap;
|
||||
@@ -39,7 +36,7 @@ import java.util.EnumMap;
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class QuadRotator implements RenderContext.QuadTransform {
|
||||
|
||||
private static final RenderContext.QuadTransform NULL_TRANSFORM = quad -> true;
|
||||
public static final RenderContext.QuadTransform NULL_TRANSFORM = quad -> true;
|
||||
|
||||
private static final EnumMap<FacingToRotation, RenderContext.QuadTransform> TRANSFORMS
|
||||
= new EnumMap<>(FacingToRotation.class);
|
||||
@@ -58,16 +55,20 @@ public class QuadRotator implements RenderContext.QuadTransform {
|
||||
|
||||
private final Quaternion quaternion;
|
||||
|
||||
public QuadRotator(FacingToRotation rotation) {
|
||||
private QuadRotator(FacingToRotation rotation) {
|
||||
this.rotation = rotation;
|
||||
this.quaternion = rotation.getRot();
|
||||
}
|
||||
|
||||
public static RenderContext.QuadTransform get(Direction newForward, Direction newUp) {
|
||||
if (newForward == Direction.NORTH && newUp == Direction.UP) {
|
||||
return get(getRotation(newForward, newUp));
|
||||
}
|
||||
|
||||
public static RenderContext.QuadTransform get(FacingToRotation rotation) {
|
||||
if (rotation.isRedundant()) {
|
||||
return NULL_TRANSFORM; // This is the default orientation
|
||||
}
|
||||
return TRANSFORMS.get(getRotation(newForward, newUp));
|
||||
return TRANSFORMS.get(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,12 +86,17 @@ public class QuadRotator implements RenderContext.QuadTransform {
|
||||
|
||||
// Transform the normal
|
||||
quad.copyNormal(i, tmp);
|
||||
tmp.rotate(rotation.getRot());
|
||||
tmp.rotate(quaternion);
|
||||
quad.normal(i, tmp);
|
||||
|
||||
// Transform the nominal face
|
||||
quad.nominalFace(rotation.rotate(quad.nominalFace()));
|
||||
}
|
||||
|
||||
// Transform the nominal face
|
||||
quad.nominalFace(rotation.rotate(quad.nominalFace()));
|
||||
Direction cullFace = quad.cullFace();
|
||||
if (cullFace != null) {
|
||||
quad.cullFace(rotation.rotate(cullFace));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package appeng.client.render.model;
|
||||
|
||||
import appeng.client.render.cablebus.QuadRotator;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockRenderView;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class AutoRotatingBakedModel extends ForwardingBakedModel implements FabricBakedModel {
|
||||
|
||||
public AutoRotatingBakedModel(BakedModel wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaAdapter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
RenderContext.QuadTransform transform = getTransform(blockView, pos);
|
||||
|
||||
if (transform != null) {
|
||||
context.pushTransform(transform);
|
||||
}
|
||||
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
|
||||
|
||||
if (transform != null) {
|
||||
context.popTransform();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
super.emitItemQuads(stack, randomSupplier, context);
|
||||
}
|
||||
|
||||
private RenderContext.QuadTransform getTransform(BlockRenderView view, BlockPos pos) {
|
||||
if (!(view instanceof RenderAttachedBlockView)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object data = ((RenderAttachedBlockView) view).getBlockEntityRenderAttachment(pos);
|
||||
if (!(data instanceof AEModelData)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AEModelData aeModelData = (AEModelData) data;
|
||||
RenderContext.QuadTransform transform = QuadRotator.get(aeModelData.getForward(), aeModelData.getUp());
|
||||
if (transform == QuadRotator.NULL_TRANSFORM) {
|
||||
return null;
|
||||
}
|
||||
return transform;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user