Block Colors Registration,
fixing... schtuff.
This commit is contained in:
@@ -60,6 +60,7 @@ public enum FacingToRotation implements StringIdentifiable {
|
||||
private final Quaternion xRot;
|
||||
private final Quaternion yRot;
|
||||
private final Quaternion zRot;
|
||||
private final Quaternion combinedRotation;
|
||||
private final Matrix4f mat;
|
||||
|
||||
private FacingToRotation(Vector3f rot) {
|
||||
@@ -69,14 +70,15 @@ public enum FacingToRotation implements StringIdentifiable {
|
||||
this.mat.multiply(xRot = Vector3f.POSITIVE_X.getDegreesQuaternion(rot.getX()));
|
||||
this.mat.multiply(yRot = Vector3f.POSITIVE_Y.getDegreesQuaternion(rot.getY()));
|
||||
this.mat.multiply(zRot = Vector3f.POSITIVE_Z.getDegreesQuaternion(rot.getZ()));
|
||||
this.combinedRotation = new Quaternion(rot.getX(), rot.getY(), rot.getZ(), true);
|
||||
}
|
||||
|
||||
public boolean isRedundant() {
|
||||
return rot.getX() == 0 && rot.getY() == 0 && rot.getZ() == 0;
|
||||
}
|
||||
|
||||
public Vector3f getRot() {
|
||||
return this.rot;
|
||||
public Quaternion getRot() {
|
||||
return this.combinedRotation;
|
||||
}
|
||||
|
||||
public Matrix4f getMat() {
|
||||
|
||||
@@ -18,30 +18,28 @@
|
||||
|
||||
package appeng.client.render.cablebus;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.registries.PartModels;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.features.registries.PartModels;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The built-in model for the cable bus block.
|
||||
@@ -57,6 +55,7 @@ public class CableBusModel implements UnbakedModel {
|
||||
|
||||
@Override
|
||||
public Collection<Identifier> getModelDependencies() {
|
||||
partModels.setInitialized(true);
|
||||
return partModels.getModels();
|
||||
}
|
||||
|
||||
@@ -78,7 +77,12 @@ public class CableBusModel implements UnbakedModel {
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier, UnbakedModel> unbakedModelGetter, Set<Pair<String, String>> unresolvedTextureReferences) {
|
||||
return Collections.unmodifiableList(CableBuilder.getTextures());
|
||||
return Stream.concat(
|
||||
getModelDependencies().stream()
|
||||
.map(unbakedModelGetter)
|
||||
.flatMap(ubm -> ubm.getTextureDependencies(unbakedModelGetter, unresolvedTextureReferences).stream()),
|
||||
CableBuilder.getTextures().stream()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<Identifier, BakedModel> loadPartModels(ModelLoader loader,
|
||||
|
||||
@@ -24,8 +24,13 @@ 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;
|
||||
|
||||
/**
|
||||
* Assuming a default-orientation of forward=NORTH and up=UP, this class rotates
|
||||
@@ -33,47 +38,59 @@ import net.minecraft.util.math.Matrix4f;
|
||||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class QuadRotator implements RenderContext.QuadTransform {
|
||||
// FIXME private static final ThreadLocal<BakedPipeline> pipelines = ThreadLocal.withInitial(() -> //
|
||||
// FIXME BakedPipeline.builder()//
|
||||
// FIXME .addElement("transformer", QuadMatrixTransformer.FACTORY)//
|
||||
// FIXME .build());
|
||||
// FIXME private static final ThreadLocal<Quad> collectors = ThreadLocal.withInitial(Quad::new);
|
||||
|
||||
private static final RenderContext.QuadTransform NULL_TRANSFORM = quad -> true;
|
||||
|
||||
private static final EnumMap<FacingToRotation, RenderContext.QuadTransform> TRANSFORMS
|
||||
= new EnumMap<>(FacingToRotation.class);
|
||||
|
||||
static {
|
||||
for (FacingToRotation rotation : FacingToRotation.values()) {
|
||||
if (rotation.isRedundant()) {
|
||||
TRANSFORMS.put(rotation, NULL_TRANSFORM);
|
||||
} else {
|
||||
TRANSFORMS.put(rotation, new QuadRotator(rotation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final FacingToRotation rotation;
|
||||
|
||||
private final Quaternion quaternion;
|
||||
|
||||
public 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 NULL_TRANSFORM; // This is the default orientation
|
||||
}
|
||||
FacingToRotation rotation = getRotation(newForward, newUp);
|
||||
if (rotation.isRedundant()) {
|
||||
return NULL_TRANSFORM;
|
||||
}
|
||||
return new QuadRotator(rotation);
|
||||
return TRANSFORMS.get(getRotation(newForward, newUp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean transform(MutableQuadView quad) {
|
||||
|
||||
// FIXME: Temporary rotation fix
|
||||
Matrix4f mat = new Matrix4f();
|
||||
mat.addToLastColumn(new Vector3f(-0.5f, -0.5f, -0.5f));
|
||||
mat.multiply(rotation.getMat());
|
||||
mat.addToLastColumn(new Vector3f(0.5f, 0.5f, 0.5f));
|
||||
Vector3f tmp = new Vector3f();
|
||||
|
||||
// FIXME ROTATION pipeline.reset(format);
|
||||
// FIXME ROTATION collector.reset(format);
|
||||
// FIXME ROTATION
|
||||
// FIXME ROTATION transformer.setMatrix(mat);
|
||||
// FIXME ROTATION pipeline.prepare(collector);
|
||||
// FIXME ROTATION quad.pipe(pipeline);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Transform the position (center of rotation is 0.5, 0.5, 0.5)
|
||||
quad.copyPos(i, tmp);
|
||||
tmp.add(-0.5f, -0.5f, -0.5f);
|
||||
tmp.rotate(quaternion);
|
||||
tmp.add(0.5f, 0.5f, 0.5f);
|
||||
quad.pos(i, tmp);
|
||||
|
||||
// Transform the normal
|
||||
quad.copyNormal(i, tmp);
|
||||
tmp.rotate(rotation.getRot());
|
||||
quad.normal(i, tmp);
|
||||
|
||||
// Transform the nominal face
|
||||
quad.nominalFace(rotation.rotate(quad.nominalFace()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user