mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-02-06 18:24:59 +01:00
Port fixes and other changes
This commit is contained in:
parent
581bec1e7a
commit
9bcc334bfa
64 changed files with 653 additions and 776 deletions
16
build.gradle
16
build.gradle
|
@ -94,8 +94,8 @@ dependencies {
|
|||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
|
||||
|
||||
compileOnly fg.deobf("maven.modrinth:rubidium:0.6.5")
|
||||
compileOnly fg.deobf("maven.modrinth:oculus:1.20-1.6.4")
|
||||
compileOnly fg.deobf("maven.modrinth:embeddium:0.2.10+mc1.20.1")
|
||||
compileOnly fg.deobf("maven.modrinth:oculus:1.20.1-1.6.9")
|
||||
|
||||
jarJar(group: 'com.dreizak', name: 'miniball', version: '[1.0.3,2.0.0)')
|
||||
library 'com.dreizak:miniball:1.0.3'
|
||||
|
@ -104,7 +104,7 @@ dependencies {
|
|||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||
// This allows 'Settings > Build, Execution, and Deployment > Build Tools > Gradle > Build and run using' set to IntelliJ to work correctly
|
||||
// if (System.getProperty('idea.sync.active') != 'true') {
|
||||
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
||||
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -151,12 +151,12 @@ void addLicense(jarTask) {
|
|||
tasks.named('jar', Jar).configure {
|
||||
manifest {
|
||||
attributes([
|
||||
'Specification-Title' : 'flywheel',
|
||||
//'Specification-Vendor': 'flywheel authors',
|
||||
'Specification-Version' : '1', // We are version 1 of ourselves
|
||||
'Specification-Title': 'flywheel',
|
||||
// 'Specification-Vendor': 'flywheel authors',
|
||||
'Specification-Version': '1', // We are version 1 of ourselves
|
||||
'Implementation-Title': project.jar.archiveBaseName,
|
||||
'Implementation-Version' : project.jar.archiveVersion,
|
||||
//'Implementation-Vendor': 'flywheel authors',
|
||||
'Implementation-Version': project.jar.archiveVersion,
|
||||
// 'Implementation-Vendor': 'flywheel authors',
|
||||
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
])
|
||||
}
|
||||
|
|
|
@ -90,8 +90,8 @@ public class Flywheel {
|
|||
forgeEventBus.addListener(VisualizationEventHandler::onClientTick);
|
||||
forgeEventBus.addListener(VisualizationEventHandler::onBeginFrame);
|
||||
forgeEventBus.addListener(VisualizationEventHandler::onRenderStage);
|
||||
forgeEventBus.addListener(VisualizationEventHandler::onEntityJoinWorld);
|
||||
forgeEventBus.addListener(VisualizationEventHandler::onEntityLeaveWorld);
|
||||
forgeEventBus.addListener(VisualizationEventHandler::onEntityJoinLevel);
|
||||
forgeEventBus.addListener(VisualizationEventHandler::onEntityLeaveLevel);
|
||||
|
||||
forgeEventBus.addListener(FlwCommands::registerClientCommands);
|
||||
|
||||
|
@ -103,6 +103,8 @@ public class Flywheel {
|
|||
forgeEventBus.addListener(ModelHolder::onReloadRenderers);
|
||||
forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.onUnloadLevel(e));
|
||||
|
||||
modEventBus.addListener(Flywheel::lateInit);
|
||||
|
||||
modEventBus.addListener(PartialModel::onModelRegistry);
|
||||
modEventBus.addListener(PartialModel::onModelBake);
|
||||
|
||||
|
@ -116,8 +118,6 @@ public class Flywheel {
|
|||
Loader.init();
|
||||
|
||||
ShadersModHandler.init();
|
||||
|
||||
modEventBus.addListener(Flywheel::lateInit);
|
||||
}
|
||||
|
||||
private static void lateInit(final FMLClientSetupEvent event) {
|
||||
|
|
|
@ -29,12 +29,12 @@ public interface Engine extends InstancerProvider {
|
|||
|
||||
/**
|
||||
* Render the given instances as a crumbling overlay.
|
||||
* @param taskExecutor The task executor running the frame plan.
|
||||
* @param executor The task executor running the frame plan.
|
||||
* @param context The render context for this frame.
|
||||
* @param instances The instances to render.
|
||||
* @param progress The progress of the crumbling animation, i.e. which texture to use.
|
||||
*/
|
||||
void renderCrumblingInstances(TaskExecutor taskExecutor, RenderContext context, List<Instance> instances, int progress);
|
||||
void renderCrumblingInstances(TaskExecutor executor, RenderContext context, List<Instance> instances, int progress);
|
||||
|
||||
/**
|
||||
* Maintain the render origin to be within a certain distance from the camera in all directions,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.jozufozu.flywheel.api.task;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface Plan<C> {
|
||||
/**
|
||||
* Submit this plan for execution.
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.jozufozu.flywheel.backend.compile.core.CompilerStats;
|
|||
import com.jozufozu.flywheel.glsl.ShaderSources;
|
||||
import com.jozufozu.flywheel.glsl.generate.FnSignature;
|
||||
import com.jozufozu.flywheel.glsl.generate.GlslExpr;
|
||||
import com.jozufozu.flywheel.lib.context.Contexts;
|
||||
import com.jozufozu.flywheel.lib.material.MaterialIndices;
|
||||
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.Collection;
|
|||
import java.util.Map;
|
||||
|
||||
import com.jozufozu.flywheel.glsl.SourceComponent;
|
||||
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
|
@ -44,7 +43,7 @@ public final class StringSubstitutionSourceComponent implements SourceComponent
|
|||
|
||||
@Override
|
||||
public ResourceLocation name() {
|
||||
return ResourceUtil.subPath(source.name(), "_string_substitution");
|
||||
return source.name().withSuffix("_string_substitution");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.joml.FrustumIntersection;
|
|||
import org.joml.Matrix4f;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.RenderContext;
|
||||
import com.jozufozu.flywheel.lib.util.FlwUtil;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
@ -17,7 +17,7 @@ public record BatchContext(FrustumIntersection frustum, ClientLevel level, PoseS
|
|||
static BatchContext create(RenderContext context, BlockPos origin) {
|
||||
Vec3 cameraPos = context.camera()
|
||||
.getPosition();
|
||||
var stack = FlwUtil.copyPoseStack(context.stack());
|
||||
var stack = MatrixMath.copyPoseStack(context.stack());
|
||||
stack.translate(origin.getX() - cameraPos.x, origin.getY() - cameraPos.y, origin.getZ() - cameraPos.z);
|
||||
|
||||
Matrix4f viewProjection = new Matrix4f(context.viewProjection());
|
||||
|
|
|
@ -71,7 +71,6 @@ public class BatchedDrawTracker {
|
|||
if (buffer.hasVertices()) {
|
||||
BufferBuilderExtension scratch = (BufferBuilderExtension) this.scratch;
|
||||
buffer.inject(scratch);
|
||||
// FIXME: Maybe we shouldn't pass null.
|
||||
buffer.getRenderType()
|
||||
.end(this.scratch, null);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class BatchingEngine extends AbstractEngine implements SimplyComposedPlan
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderCrumblingInstances(TaskExecutor taskExecutor, RenderContext context, List<Instance> instances, int progress) {
|
||||
public void renderCrumblingInstances(TaskExecutor executor, RenderContext context, List<Instance> instances, int progress) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ public class IndirectEngine extends AbstractEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderCrumblingInstances(TaskExecutor taskExecutor, RenderContext context, List<Instance> instances, int progress) {
|
||||
public void renderCrumblingInstances(TaskExecutor executor, RenderContext context, List<Instance> instances, int progress) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import com.jozufozu.flywheel.lib.task.SyncedPlan;
|
|||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
|
||||
public class InstancingEngine extends AbstractEngine {
|
||||
|
@ -83,10 +82,10 @@ public class InstancingEngine extends AbstractEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderCrumblingInstances(TaskExecutor taskExecutor, RenderContext context, List<Instance> instances, int progress) {
|
||||
public void renderCrumblingInstances(TaskExecutor executor, RenderContext context, List<Instance> instances, int progress) {
|
||||
// TODO: optimize
|
||||
|
||||
taskExecutor.syncUntil(flushFlag::isRaised);
|
||||
executor.syncUntil(flushFlag::isRaised);
|
||||
|
||||
var type = ModelBakery.DESTROY_TYPES.get(progress);
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ import java.util.Map;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
|
@ -67,7 +65,7 @@ public class ShaderSources {
|
|||
|
||||
@NotNull
|
||||
protected LoadResult load(ResourceLocation loc) {
|
||||
return manager.getResource(ResourceUtil.prefixed(SHADER_DIR, loc))
|
||||
return manager.getResource(loc.withPrefix(SHADER_DIR))
|
||||
.map(resource -> {
|
||||
try (InputStream stream = resource.open()) {
|
||||
String sourceString = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
|
|
|
@ -65,7 +65,7 @@ public final class VisualizationEventHandler {
|
|||
manager.renderStage(event.getContext(), event.getStage());
|
||||
}
|
||||
|
||||
public static void onEntityJoinWorld(EntityJoinLevelEvent event) {
|
||||
public static void onEntityJoinLevel(EntityJoinLevelEvent event) {
|
||||
Level level = event.getLevel();
|
||||
VisualizationManager manager = VisualizationManager.get(level);
|
||||
if (manager == null) {
|
||||
|
@ -75,7 +75,7 @@ public final class VisualizationEventHandler {
|
|||
manager.getEntities().queueAdd(event.getEntity());
|
||||
}
|
||||
|
||||
public static void onEntityLeaveWorld(EntityLeaveLevelEvent event) {
|
||||
public static void onEntityLeaveLevel(EntityLeaveLevelEvent event) {
|
||||
Level level = event.getLevel();
|
||||
VisualizationManager manager = VisualizationManager.get(level);
|
||||
if (manager == null) {
|
||||
|
|
|
@ -22,10 +22,10 @@ import com.jozufozu.flywheel.impl.visualization.manager.BlockEntityVisualManager
|
|||
import com.jozufozu.flywheel.impl.visualization.manager.EffectVisualManager;
|
||||
import com.jozufozu.flywheel.impl.visualization.manager.EntityVisualManager;
|
||||
import com.jozufozu.flywheel.lib.task.Flag;
|
||||
import com.jozufozu.flywheel.lib.task.IfElsePlan;
|
||||
import com.jozufozu.flywheel.lib.task.MapContextPlan;
|
||||
import com.jozufozu.flywheel.lib.task.NamedFlag;
|
||||
import com.jozufozu.flywheel.lib.task.RaisePlan;
|
||||
import com.jozufozu.flywheel.lib.task.IfElsePlan;
|
||||
import com.jozufozu.flywheel.lib.util.LevelAttached;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
|
@ -207,10 +207,10 @@ public class VisualizationManagerImpl implements VisualizationManager {
|
|||
|
||||
for (var entry : destructionProgress.long2ObjectEntrySet()) {
|
||||
var set = entry.getValue();
|
||||
if (set == null || set.isEmpty()) {
|
||||
if (set == null || set.isEmpty()) {
|
||||
// Nothing to do if there's no crumbling.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var visual = blockEntities.visualAtPos(entry.getLongKey());
|
||||
|
||||
|
@ -232,7 +232,7 @@ public class VisualizationManagerImpl implements VisualizationManager {
|
|||
.getProgress();
|
||||
|
||||
engine.renderCrumblingInstances(taskExecutor, context, instances, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.api.task.Plan;
|
||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||
|
|
|
@ -2,12 +2,11 @@ package com.jozufozu.flywheel.lib.box;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
public class MutableBox implements Box {
|
||||
|
@ -252,9 +251,9 @@ public class MutableBox implements Box {
|
|||
* Grow this box to have power of 2 side lengths, scaling from the minimum coords.
|
||||
*/
|
||||
public void nextPowerOf2() {
|
||||
int sizeX = RenderMath.nextPowerOf2(sizeX());
|
||||
int sizeY = RenderMath.nextPowerOf2(sizeY());
|
||||
int sizeZ = RenderMath.nextPowerOf2(sizeZ());
|
||||
int sizeX = Mth.smallestEncompassingPowerOfTwo(sizeX());
|
||||
int sizeY = Mth.smallestEncompassingPowerOfTwo(sizeY());
|
||||
int sizeZ = Mth.smallestEncompassingPowerOfTwo(sizeZ());
|
||||
|
||||
maxX = minX + sizeX;
|
||||
maxY = minY + sizeY;
|
||||
|
@ -269,9 +268,9 @@ public class MutableBox implements Box {
|
|||
int sizeY = sizeY();
|
||||
int sizeZ = sizeZ();
|
||||
|
||||
int newSizeX = RenderMath.nextPowerOf2(sizeX);
|
||||
int newSizeY = RenderMath.nextPowerOf2(sizeY);
|
||||
int newSizeZ = RenderMath.nextPowerOf2(sizeZ);
|
||||
int newSizeX = Mth.smallestEncompassingPowerOfTwo(sizeX);
|
||||
int newSizeY = Mth.smallestEncompassingPowerOfTwo(sizeY);
|
||||
int newSizeZ = Mth.smallestEncompassingPowerOfTwo(sizeZ);
|
||||
|
||||
int diffX = newSizeX - sizeX;
|
||||
int diffY = newSizeY - sizeY;
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.jetbrains.annotations.ApiStatus;
|
|||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.api.context.Context;
|
||||
import com.jozufozu.flywheel.gl.shader.GlProgram;
|
||||
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
|
@ -33,10 +32,10 @@ public final class Contexts {
|
|||
}
|
||||
|
||||
public static final class Files {
|
||||
public static final ResourceLocation WORLD_VERTEX = ResourceUtil.subPath(Names.WORLD, ".vert");
|
||||
public static final ResourceLocation WORLD_FRAGMENT = ResourceUtil.subPath(Names.WORLD, ".frag");
|
||||
public static final ResourceLocation CRUMBLING_VERTEX = ResourceUtil.subPath(Names.CRUMBLING, ".vert");
|
||||
public static final ResourceLocation CRUMBLING_FRAGMENT = ResourceUtil.subPath(Names.CRUMBLING, ".frag");
|
||||
public static final ResourceLocation WORLD_VERTEX = Names.WORLD.withSuffix(".vert");
|
||||
public static final ResourceLocation WORLD_FRAGMENT = Names.WORLD.withSuffix(".frag");
|
||||
public static final ResourceLocation CRUMBLING_VERTEX = Names.CRUMBLING.withSuffix(".vert");
|
||||
public static final ResourceLocation CRUMBLING_FRAGMENT = Names.CRUMBLING.withSuffix(".frag");
|
||||
}
|
||||
|
||||
public static final class Names {
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.jetbrains.annotations.ApiStatus;
|
|||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
|
@ -20,8 +19,8 @@ public final class InstanceTypes {
|
|||
}
|
||||
|
||||
public static final class Files {
|
||||
public static final ResourceLocation TRANSFORMED = ResourceUtil.subPath(Names.TRANSFORMED, ".vert");
|
||||
public static final ResourceLocation ORIENTED = ResourceUtil.subPath(Names.ORIENTED, ".vert");
|
||||
public static final ResourceLocation TRANSFORMED = Names.TRANSFORMED.withSuffix(".vert");
|
||||
public static final ResourceLocation ORIENTED = Names.ORIENTED.withSuffix(".vert");
|
||||
}
|
||||
|
||||
public static final class Names {
|
||||
|
|
|
@ -5,59 +5,27 @@ import org.joml.Vector3f;
|
|||
|
||||
import com.jozufozu.flywheel.api.instance.InstanceHandle;
|
||||
import com.jozufozu.flywheel.api.instance.InstanceType;
|
||||
import com.jozufozu.flywheel.lib.transform.Rotate;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class OrientedInstance extends ColoredLitInstance {
|
||||
public float posX;
|
||||
public float posY;
|
||||
public float posZ;
|
||||
public class OrientedInstance extends ColoredLitInstance implements Rotate<OrientedInstance> {
|
||||
public final Quaternionf rotation = new Quaternionf();
|
||||
public float pivotX = 0.5f;
|
||||
public float pivotY = 0.5f;
|
||||
public float pivotZ = 0.5f;
|
||||
public final Quaternionf rotation = new Quaternionf();
|
||||
public float posX;
|
||||
public float posY;
|
||||
public float posZ;
|
||||
|
||||
public OrientedInstance(InstanceType<? extends OrientedInstance> type, InstanceHandle handle) {
|
||||
super(type, handle);
|
||||
}
|
||||
|
||||
public OrientedInstance setPosition(BlockPos pos) {
|
||||
return setPosition(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public OrientedInstance setPosition(Vector3f pos) {
|
||||
return setPosition(pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
|
||||
public OrientedInstance setPosition(float x, float y, float z) {
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.posZ = z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance nudge(float x, float y, float z) {
|
||||
this.posX += x;
|
||||
this.posY += y;
|
||||
this.posZ += z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setPivot(Vector3f pos) {
|
||||
return setPivot(pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
|
||||
public OrientedInstance setPivot(Vec3 pos) {
|
||||
return setPivot((float) pos.x(), (float) pos.y(), (float) pos.z());
|
||||
}
|
||||
|
||||
public OrientedInstance setPivot(float x, float y, float z) {
|
||||
this.pivotX = x;
|
||||
this.pivotY = y;
|
||||
this.pivotZ = z;
|
||||
@Override
|
||||
public OrientedInstance rotate(Quaternionf quaternion) {
|
||||
rotation.mul(quaternion);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
@ -79,4 +47,48 @@ public class OrientedInstance extends ColoredLitInstance {
|
|||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setPivot(float x, float y, float z) {
|
||||
pivotX = x;
|
||||
pivotY = y;
|
||||
pivotZ = z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setPivot(Vector3f pos) {
|
||||
return setPivot(pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
|
||||
public OrientedInstance setPivot(Vec3 pos) {
|
||||
return setPivot((float) pos.x(), (float) pos.y(), (float) pos.z());
|
||||
}
|
||||
|
||||
public OrientedInstance nudgePosition(float x, float y, float z) {
|
||||
posX += x;
|
||||
posY += y;
|
||||
posZ += z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setPosition(float x, float y, float z) {
|
||||
posX = x;
|
||||
posY = y;
|
||||
posZ = z;
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public OrientedInstance setPosition(Vector3f pos) {
|
||||
return setPosition(pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
|
||||
public OrientedInstance setPosition(Vec3i pos) {
|
||||
return setPosition(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public OrientedInstance resetPosition() {
|
||||
return setPosition(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.jozufozu.flywheel.lib.instance;
|
|||
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
|
||||
import com.jozufozu.flywheel.api.instance.InstanceBoundingSphereTransformer;
|
||||
import com.jozufozu.flywheel.api.instance.InstanceHandle;
|
||||
|
|
|
@ -22,52 +22,22 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
|||
super(type, handle);
|
||||
}
|
||||
|
||||
public TransformedInstance setTransform(PoseStack stack) {
|
||||
@Override
|
||||
public TransformedInstance mulPose(Matrix4f pose) {
|
||||
this.model.mul(pose);
|
||||
setChanged();
|
||||
|
||||
this.model.set(stack.last()
|
||||
.pose());
|
||||
this.normal.set(stack.last()
|
||||
.normal());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the transform matrices to be all zeros.
|
||||
*
|
||||
* <p>
|
||||
* This will allow the gpu to quickly discard all geometry for this instance, effectively "turning it off".
|
||||
* </p>
|
||||
*/
|
||||
public TransformedInstance setEmptyTransform() {
|
||||
setChanged();
|
||||
|
||||
model.set(ZERO_MATRIX_4f);
|
||||
normal.set(ZERO_MATRIX_3f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransformedInstance loadIdentity() {
|
||||
setChanged();
|
||||
|
||||
model.identity();
|
||||
normal.identity();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance multiply(Quaternionf quaternion) {
|
||||
public TransformedInstance mulNormal(Matrix3f normal) {
|
||||
this.normal.mul(normal);
|
||||
setChanged();
|
||||
|
||||
model.rotate(quaternion);
|
||||
normal.rotate(quaternion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance scale(float x, float y, float z) {
|
||||
setChanged();
|
||||
|
||||
model.scale(x, y, z);
|
||||
|
||||
if (x == y && y == z) {
|
||||
|
@ -83,30 +53,52 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
|
|||
float invZ = 1.0f / z;
|
||||
float f = Mth.fastInvCubeRoot(Math.abs(invX * invY * invZ));
|
||||
normal.scale(f * invX, f * invY, f * invZ);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance rotate(Quaternionf quaternion) {
|
||||
model.rotate(quaternion);
|
||||
normal.rotate(quaternion);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance translate(double x, double y, double z) {
|
||||
setChanged();
|
||||
|
||||
model.translate((float) x, (float) y, (float) z);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance mulPose(Matrix4f pose) {
|
||||
public TransformedInstance setTransform(PoseStack stack) {
|
||||
this.model.set(stack.last()
|
||||
.pose());
|
||||
this.normal.set(stack.last()
|
||||
.normal());
|
||||
setChanged();
|
||||
|
||||
this.model.mul(pose);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformedInstance mulNormal(Matrix3f normal) {
|
||||
/**
|
||||
* Sets the transform matrices to be all zeros.
|
||||
*
|
||||
* <p>
|
||||
* This will allow the GPU to quickly discard all geometry for this instance, effectively "turning it off".
|
||||
* </p>
|
||||
*/
|
||||
public TransformedInstance setEmptyTransform() {
|
||||
model.set(ZERO_MATRIX_4f);
|
||||
normal.set(ZERO_MATRIX_3f);
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
this.normal.mul(normal);
|
||||
public TransformedInstance loadIdentity() {
|
||||
model.identity();
|
||||
normal.identity();
|
||||
setChanged();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.jozufozu.flywheel.api.instance.InstanceVertexTransformer;
|
|||
import com.jozufozu.flywheel.api.instance.InstanceWriter;
|
||||
import com.jozufozu.flywheel.api.layout.BufferLayout;
|
||||
import com.jozufozu.flywheel.lib.layout.CommonItems;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixUtil;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
||||
import com.jozufozu.flywheel.lib.math.RenderMath;
|
||||
import com.jozufozu.flywheel.lib.vertex.VertexTransformations;
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class TransformedType implements InstanceType<TransformedInstance> {
|
|||
var radius = boundingSphere.w;
|
||||
boundingSphere.w = 1;
|
||||
boundingSphere.mul(instance.model);
|
||||
boundingSphere.w = radius * MatrixUtil.extractScale(instance.model);
|
||||
boundingSphere.w = radius * MatrixMath.extractScale(instance.model);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.lib.instance;
|
||||
|
||||
import com.jozufozu.flywheel.lib.math.MatrixUtil;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
||||
|
||||
public class TransformedWriter extends ColoredLitWriter<TransformedInstance> {
|
||||
public static final TransformedWriter INSTANCE = new TransformedWriter();
|
||||
|
@ -8,8 +8,8 @@ public class TransformedWriter extends ColoredLitWriter<TransformedInstance> {
|
|||
@Override
|
||||
public void write(final long ptr, final TransformedInstance instance) {
|
||||
super.write(ptr, instance);
|
||||
MatrixUtil.writeUnsafe(instance.model, ptr + 8);
|
||||
MatrixUtil.writeUnsafe(instance.normal, ptr + 72);
|
||||
MatrixMath.writeUnsafe(instance.model, ptr + 8);
|
||||
MatrixMath.writeUnsafe(instance.normal, ptr + 72);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.jozufozu.flywheel.api.material.MaterialVertexTransformer;
|
|||
import com.jozufozu.flywheel.gl.GlTextureUnit;
|
||||
import com.jozufozu.flywheel.lib.material.SimpleMaterial.GlStateShard;
|
||||
import com.jozufozu.flywheel.lib.math.DiffuseLightCalculator;
|
||||
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
||||
import com.jozufozu.flywheel.lib.util.ShadersModHandler;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
@ -166,7 +165,6 @@ public final class Materials {
|
|||
return new GlStateShard(
|
||||
() -> {
|
||||
GlTextureUnit.T0.makeActive();
|
||||
// FIXME: I think it got removed RenderSystem.enableTexture();
|
||||
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(loc);
|
||||
texture.setFilter(blur, mipmap);
|
||||
RenderSystem.setShaderTexture(0, texture.getId());
|
||||
|
@ -180,10 +178,10 @@ public final class Materials {
|
|||
}
|
||||
|
||||
public static final class Files {
|
||||
public static final ResourceLocation DEFAULT_VERTEX = ResourceUtil.subPath(Names.DEFAULT, ".vert");
|
||||
public static final ResourceLocation SHADED_VERTEX = ResourceUtil.subPath(Names.SHADED, ".vert");
|
||||
public static final ResourceLocation DEFAULT_FRAGMENT = ResourceUtil.subPath(Names.DEFAULT, ".frag");
|
||||
public static final ResourceLocation CUTOUT_FRAGMENT = ResourceUtil.subPath(Names.CUTOUT, ".frag");
|
||||
public static final ResourceLocation DEFAULT_VERTEX = Names.DEFAULT.withSuffix(".vert");
|
||||
public static final ResourceLocation SHADED_VERTEX = Names.SHADED.withSuffix(".vert");
|
||||
public static final ResourceLocation DEFAULT_FRAGMENT = Names.DEFAULT.withSuffix(".frag");
|
||||
public static final ResourceLocation CUTOUT_FRAGMENT = Names.CUTOUT.withSuffix(".frag");
|
||||
}
|
||||
|
||||
public static final class Names {
|
||||
|
|
210
src/main/java/com/jozufozu/flywheel/lib/math/MatrixMath.java
Normal file
210
src/main/java/com/jozufozu/flywheel/lib/math/MatrixMath.java
Normal file
|
@ -0,0 +1,210 @@
|
|||
package com.jozufozu.flywheel.lib.math;
|
||||
|
||||
import static org.joml.Math.fma;
|
||||
|
||||
import org.joml.Math;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
public final class MatrixMath {
|
||||
private MatrixMath() {
|
||||
}
|
||||
|
||||
public static PoseStack copyPoseStack(PoseStack stack) {
|
||||
PoseStack copy = new PoseStack();
|
||||
copy.last()
|
||||
.pose()
|
||||
.set(stack.last()
|
||||
.pose());
|
||||
copy.last()
|
||||
.normal()
|
||||
.set(stack.last()
|
||||
.normal());
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static float transformPositionX(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m00(), x, fma(matrix.m10(), y, fma(matrix.m20(), z, matrix.m30())));
|
||||
}
|
||||
|
||||
public static float transformPositionY(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m01(), x, fma(matrix.m11(), y, fma(matrix.m21(), z, matrix.m31())));
|
||||
}
|
||||
|
||||
public static float transformPositionZ(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m02(), x, fma(matrix.m12(), y, fma(matrix.m22(), z, matrix.m32())));
|
||||
}
|
||||
|
||||
public static float transformNormalX(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m00(), x, fma(matrix.m10(), y, matrix.m20() * z));
|
||||
}
|
||||
|
||||
public static float transformNormalY(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m01(), x, fma(matrix.m11(), y, matrix.m21() * z));
|
||||
}
|
||||
|
||||
public static float transformNormalZ(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m02(), x, fma(matrix.m12(), y, matrix.m22() * z));
|
||||
}
|
||||
|
||||
public static void writeUnsafe(Matrix4f matrix, long ptr) {
|
||||
MemoryUtil.memPutFloat(ptr, matrix.m00());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m03());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m11());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m13());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 36, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 40, matrix.m22());
|
||||
MemoryUtil.memPutFloat(ptr + 44, matrix.m23());
|
||||
MemoryUtil.memPutFloat(ptr + 48, matrix.m30());
|
||||
MemoryUtil.memPutFloat(ptr + 52, matrix.m31());
|
||||
MemoryUtil.memPutFloat(ptr + 56, matrix.m32());
|
||||
MemoryUtil.memPutFloat(ptr + 60, matrix.m33());
|
||||
}
|
||||
|
||||
public static void writeUnsafe(Matrix3f matrix, long ptr) {
|
||||
MemoryUtil.memPutFloat(ptr, matrix.m00());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m11());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m22());
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the greatest scale factor across all axes from the given matrix.
|
||||
*
|
||||
* @param matrix The matrix to extract the scale from.
|
||||
* @return The greatest scale factor across all axes.
|
||||
*/
|
||||
public static float extractScale(Matrix4f matrix) {
|
||||
float scaleSqrX = matrix.m00() * matrix.m00() + matrix.m01() * matrix.m01() + matrix.m02() * matrix.m02();
|
||||
float scaleSqrY = matrix.m10() * matrix.m10() + matrix.m11() * matrix.m11() + matrix.m12() * matrix.m12();
|
||||
float scaleSqrZ = matrix.m20() * matrix.m20() + matrix.m21() * matrix.m21() + matrix.m22() * matrix.m22();
|
||||
return Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the frustum planes of the given projection matrix to the given buffer.<p>
|
||||
* Uses a different format that is friendly towards an optimized instruction-parallel
|
||||
* implementation of sphere-frustum intersection.<p>
|
||||
* The format is as follows:<p>
|
||||
* {@code vec4(nxX, pxX, nyX, pyX)}<br>
|
||||
* {@code vec4(nxY, pxY, nyY, pyY)}<br>
|
||||
* {@code vec4(nxZ, pxZ, nyZ, pyZ)}<br>
|
||||
* {@code vec4(nxW, pxW, nyW, pyW)}<br>
|
||||
* {@code vec2(nzX, pzX)}<br>
|
||||
* {@code vec2(nzY, pzY)}<br>
|
||||
* {@code vec2(nzZ, pzZ)}<br>
|
||||
* {@code vec2(nzW, pzW)}<br>
|
||||
* <p>
|
||||
* Writes 96 bytes to the buffer.
|
||||
*
|
||||
* @param ptr The buffer to write the planes to.
|
||||
* @param m The projection matrix to compute the frustum planes for.
|
||||
*/
|
||||
public static void writePackedFrustumPlanes(long ptr, Matrix4f m) {
|
||||
float nxX, nxY, nxZ, nxW;
|
||||
float pxX, pxY, pxZ, pxW;
|
||||
float nyX, nyY, nyZ, nyW;
|
||||
float pyX, pyY, pyZ, pyW;
|
||||
float nzX, nzY, nzZ, nzW;
|
||||
float pzX, pzY, pzZ, pzW;
|
||||
|
||||
float invl;
|
||||
nxX = m.m03() + m.m00();
|
||||
nxY = m.m13() + m.m10();
|
||||
nxZ = m.m23() + m.m20();
|
||||
nxW = m.m33() + m.m30();
|
||||
invl = Math.invsqrt(nxX * nxX + nxY * nxY + nxZ * nxZ);
|
||||
nxX *= invl;
|
||||
nxY *= invl;
|
||||
nxZ *= invl;
|
||||
nxW *= invl;
|
||||
|
||||
pxX = m.m03() - m.m00();
|
||||
pxY = m.m13() - m.m10();
|
||||
pxZ = m.m23() - m.m20();
|
||||
pxW = m.m33() - m.m30();
|
||||
invl = Math.invsqrt(pxX * pxX + pxY * pxY + pxZ * pxZ);
|
||||
pxX *= invl;
|
||||
pxY *= invl;
|
||||
pxZ *= invl;
|
||||
pxW *= invl;
|
||||
|
||||
nyX = m.m03() + m.m01();
|
||||
nyY = m.m13() + m.m11();
|
||||
nyZ = m.m23() + m.m21();
|
||||
nyW = m.m33() + m.m31();
|
||||
invl = Math.invsqrt(nyX * nyX + nyY * nyY + nyZ * nyZ);
|
||||
nyX *= invl;
|
||||
nyY *= invl;
|
||||
nyZ *= invl;
|
||||
nyW *= invl;
|
||||
|
||||
pyX = m.m03() - m.m01();
|
||||
pyY = m.m13() - m.m11();
|
||||
pyZ = m.m23() - m.m21();
|
||||
pyW = m.m33() - m.m31();
|
||||
invl = Math.invsqrt(pyX * pyX + pyY * pyY + pyZ * pyZ);
|
||||
pyX *= invl;
|
||||
pyY *= invl;
|
||||
pyZ *= invl;
|
||||
pyW *= invl;
|
||||
|
||||
nzX = m.m03() + m.m02();
|
||||
nzY = m.m13() + m.m12();
|
||||
nzZ = m.m23() + m.m22();
|
||||
nzW = m.m33() + m.m32();
|
||||
invl = Math.invsqrt(nzX * nzX + nzY * nzY + nzZ * nzZ);
|
||||
nzX *= invl;
|
||||
nzY *= invl;
|
||||
nzZ *= invl;
|
||||
nzW *= invl;
|
||||
|
||||
pzX = m.m03() - m.m02();
|
||||
pzY = m.m13() - m.m12();
|
||||
pzZ = m.m23() - m.m22();
|
||||
pzW = m.m33() - m.m32();
|
||||
invl = Math.invsqrt(pzX * pzX + pzY * pzY + pzZ * pzZ);
|
||||
pzX *= invl;
|
||||
pzY *= invl;
|
||||
pzZ *= invl;
|
||||
pzW *= invl;
|
||||
|
||||
MemoryUtil.memPutFloat(ptr, nxX);
|
||||
MemoryUtil.memPutFloat(ptr + 4, pxX);
|
||||
MemoryUtil.memPutFloat(ptr + 8, nyX);
|
||||
MemoryUtil.memPutFloat(ptr + 12, pyX);
|
||||
MemoryUtil.memPutFloat(ptr + 16, nxY);
|
||||
MemoryUtil.memPutFloat(ptr + 20, pxY);
|
||||
MemoryUtil.memPutFloat(ptr + 24, nyY);
|
||||
MemoryUtil.memPutFloat(ptr + 28, pyY);
|
||||
MemoryUtil.memPutFloat(ptr + 32, nxZ);
|
||||
MemoryUtil.memPutFloat(ptr + 36, pxZ);
|
||||
MemoryUtil.memPutFloat(ptr + 40, nyZ);
|
||||
MemoryUtil.memPutFloat(ptr + 44, pyZ);
|
||||
MemoryUtil.memPutFloat(ptr + 48, nxW);
|
||||
MemoryUtil.memPutFloat(ptr + 52, pxW);
|
||||
MemoryUtil.memPutFloat(ptr + 56, nyW);
|
||||
MemoryUtil.memPutFloat(ptr + 60, pyW);
|
||||
MemoryUtil.memPutFloat(ptr + 64, nzX);
|
||||
MemoryUtil.memPutFloat(ptr + 68, pzX);
|
||||
MemoryUtil.memPutFloat(ptr + 72, nzY);
|
||||
MemoryUtil.memPutFloat(ptr + 76, pzY);
|
||||
MemoryUtil.memPutFloat(ptr + 80, nzZ);
|
||||
MemoryUtil.memPutFloat(ptr + 84, pzZ);
|
||||
MemoryUtil.memPutFloat(ptr + 88, nzW);
|
||||
MemoryUtil.memPutFloat(ptr + 92, pzW);
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
package com.jozufozu.flywheel.lib.math;
|
||||
|
||||
import static org.joml.Math.fma;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.joml.Math;
|
||||
import org.joml.Matrix3f;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
public final class MatrixUtil {
|
||||
public static float transformPositionX(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m00(), x, fma(matrix.m10(), y, fma(matrix.m20(), z, matrix.m30())));
|
||||
}
|
||||
|
||||
public static float transformPositionY(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m01(), x, fma(matrix.m11(), y, fma(matrix.m21(), z, matrix.m31())));
|
||||
}
|
||||
|
||||
public static float transformPositionZ(Matrix4f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m02(), x, fma(matrix.m12(), y, fma(matrix.m22(), z, matrix.m32())));
|
||||
}
|
||||
|
||||
public static float transformNormalX(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m00(), x, fma(matrix.m10(), y, matrix.m20() * z));
|
||||
}
|
||||
|
||||
public static float transformNormalY(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m01(), x, fma(matrix.m11(), y, matrix.m21() * z));
|
||||
}
|
||||
|
||||
public static float transformNormalZ(Matrix3f matrix, float x, float y, float z) {
|
||||
return fma(matrix.m02(), x, fma(matrix.m12(), y, matrix.m22() * z));
|
||||
}
|
||||
|
||||
public static void write(Matrix4f matrix, ByteBuffer buf) {
|
||||
matrix.get(buf);
|
||||
}
|
||||
|
||||
public static void writeUnsafe(Matrix4f matrix, long ptr) {
|
||||
MemoryUtil.memPutFloat(ptr, matrix.m00());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m03());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m11());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m13());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 36, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 40, matrix.m22());
|
||||
MemoryUtil.memPutFloat(ptr + 44, matrix.m23());
|
||||
MemoryUtil.memPutFloat(ptr + 48, matrix.m30());
|
||||
MemoryUtil.memPutFloat(ptr + 52, matrix.m31());
|
||||
MemoryUtil.memPutFloat(ptr + 56, matrix.m32());
|
||||
MemoryUtil.memPutFloat(ptr + 60, matrix.m33());
|
||||
}
|
||||
|
||||
public static void write(Matrix3f matrix, ByteBuffer buf) {
|
||||
matrix.get(buf);
|
||||
}
|
||||
|
||||
public static void writeUnsafe(Matrix3f matrix, long ptr) {
|
||||
MemoryUtil.memPutFloat(ptr, matrix.m00());
|
||||
MemoryUtil.memPutFloat(ptr + 4, matrix.m01());
|
||||
MemoryUtil.memPutFloat(ptr + 8, matrix.m02());
|
||||
MemoryUtil.memPutFloat(ptr + 12, matrix.m10());
|
||||
MemoryUtil.memPutFloat(ptr + 16, matrix.m11());
|
||||
MemoryUtil.memPutFloat(ptr + 20, matrix.m12());
|
||||
MemoryUtil.memPutFloat(ptr + 24, matrix.m20());
|
||||
MemoryUtil.memPutFloat(ptr + 28, matrix.m21());
|
||||
MemoryUtil.memPutFloat(ptr + 32, matrix.m22());
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the greatest scale factor across all axes from the given matrix.
|
||||
*
|
||||
* @param matrix The matrix to extract the scale from.
|
||||
* @return The greatest scale factor across all axes.
|
||||
*/
|
||||
public static float extractScale(Matrix4f matrix) {
|
||||
float scaleSqrX = matrix.m00() * matrix.m00() + matrix.m10() * matrix.m10() + matrix.m20() * matrix.m20();
|
||||
float scaleSqrY = matrix.m01() * matrix.m01() + matrix.m11() * matrix.m11() + matrix.m21() * matrix.m21();
|
||||
float scaleSqrZ = matrix.m02() * matrix.m02() + matrix.m12() * matrix.m12() + matrix.m22() * matrix.m22();
|
||||
return Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ));
|
||||
}
|
||||
}
|
|
@ -1,16 +1,17 @@
|
|||
package com.jozufozu.flywheel.lib.math;
|
||||
|
||||
import org.joml.Math;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
|
||||
public final class MoreMath {
|
||||
private MoreMath() {
|
||||
}
|
||||
|
||||
public static int align16(int numToRound) {
|
||||
return (numToRound + 16 - 1) & -16;
|
||||
}
|
||||
|
||||
public static int ceilingDiv(int numerator, int denominator) {
|
||||
return (numerator + denominator - 1) / denominator;
|
||||
}
|
||||
|
||||
public static int numDigits(int number) {
|
||||
// cursed but allegedly the fastest algorithm, taken from https://www.baeldung.com/java-number-of-digits-in-int
|
||||
if (number < 100000) {
|
||||
|
@ -51,126 +52,4 @@ public final class MoreMath {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float nextFloat(RandomSource rs, float min, float max) {
|
||||
return rs.nextFloat() * (max - min) + min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the frustum planes of the given projection matrix to the given buffer.<p>
|
||||
* Uses a different format that is friendly towards an optimized instruction-parallel
|
||||
* implementation of sphere-frustum intersection.<p>
|
||||
* The format is as follows:<p>
|
||||
* {@code vec4(nxX, pxX, nyX, pyX)}<br>
|
||||
* {@code vec4(nxY, pxY, nyY, pyY)}<br>
|
||||
* {@code vec4(nxZ, pxZ, nyZ, pyZ)}<br>
|
||||
* {@code vec4(nxW, pxW, nyW, pyW)}<br>
|
||||
* {@code vec2(nzX, pzX)}<br>
|
||||
* {@code vec2(nzY, pzY)}<br>
|
||||
* {@code vec2(nzZ, pzZ)}<br>
|
||||
* {@code vec2(nzW, pzW)}<br>
|
||||
* <p>
|
||||
* Writes 96 bytes to the buffer.
|
||||
*
|
||||
* @param ptr The buffer to write the planes to.
|
||||
* @param m The projection matrix to compute the frustum planes for.
|
||||
*/
|
||||
public static void writePackedFrustumPlanes(long ptr, Matrix4f m) {
|
||||
float nxX, nxY, nxZ, nxW;
|
||||
float pxX, pxY, pxZ, pxW;
|
||||
float nyX, nyY, nyZ, nyW;
|
||||
float pyX, pyY, pyZ, pyW;
|
||||
float nzX, nzY, nzZ, nzW;
|
||||
float pzX, pzY, pzZ, pzW;
|
||||
|
||||
float invl;
|
||||
nxX = m.m03() + m.m00();
|
||||
nxY = m.m13() + m.m10();
|
||||
nxZ = m.m23() + m.m20();
|
||||
nxW = m.m33() + m.m30();
|
||||
invl = Math.invsqrt(nxX * nxX + nxY * nxY + nxZ * nxZ);
|
||||
nxX *= invl;
|
||||
nxY *= invl;
|
||||
nxZ *= invl;
|
||||
nxW *= invl;
|
||||
|
||||
pxX = m.m03() - m.m00();
|
||||
pxY = m.m13() - m.m10();
|
||||
pxZ = m.m23() - m.m20();
|
||||
pxW = m.m33() - m.m30();
|
||||
invl = Math.invsqrt(pxX * pxX + pxY * pxY + pxZ * pxZ);
|
||||
pxX *= invl;
|
||||
pxY *= invl;
|
||||
pxZ *= invl;
|
||||
pxW *= invl;
|
||||
|
||||
nyX = m.m03() + m.m01();
|
||||
nyY = m.m13() + m.m11();
|
||||
nyZ = m.m23() + m.m21();
|
||||
nyW = m.m33() + m.m31();
|
||||
invl = Math.invsqrt(nyX * nyX + nyY * nyY + nyZ * nyZ);
|
||||
nyX *= invl;
|
||||
nyY *= invl;
|
||||
nyZ *= invl;
|
||||
nyW *= invl;
|
||||
|
||||
pyX = m.m03() - m.m01();
|
||||
pyY = m.m13() - m.m11();
|
||||
pyZ = m.m23() - m.m21();
|
||||
pyW = m.m33() - m.m31();
|
||||
invl = Math.invsqrt(pyX * pyX + pyY * pyY + pyZ * pyZ);
|
||||
pyX *= invl;
|
||||
pyY *= invl;
|
||||
pyZ *= invl;
|
||||
pyW *= invl;
|
||||
|
||||
nzX = m.m03() + m.m02();
|
||||
nzY = m.m13() + m.m12();
|
||||
nzZ = m.m23() + m.m22();
|
||||
nzW = m.m33() + m.m32();
|
||||
invl = Math.invsqrt(nzX * nzX + nzY * nzY + nzZ * nzZ);
|
||||
nzX *= invl;
|
||||
nzY *= invl;
|
||||
nzZ *= invl;
|
||||
nzW *= invl;
|
||||
|
||||
pzX = m.m03() - m.m02();
|
||||
pzY = m.m13() - m.m12();
|
||||
pzZ = m.m23() - m.m22();
|
||||
pzW = m.m33() - m.m32();
|
||||
invl = Math.invsqrt(pzX * pzX + pzY * pzY + pzZ * pzZ);
|
||||
pzX *= invl;
|
||||
pzY *= invl;
|
||||
pzZ *= invl;
|
||||
pzW *= invl;
|
||||
|
||||
MemoryUtil.memPutFloat(ptr, nxX);
|
||||
MemoryUtil.memPutFloat(ptr + 4, pxX);
|
||||
MemoryUtil.memPutFloat(ptr + 8, nyX);
|
||||
MemoryUtil.memPutFloat(ptr + 12, pyX);
|
||||
MemoryUtil.memPutFloat(ptr + 16, nxY);
|
||||
MemoryUtil.memPutFloat(ptr + 20, pxY);
|
||||
MemoryUtil.memPutFloat(ptr + 24, nyY);
|
||||
MemoryUtil.memPutFloat(ptr + 28, pyY);
|
||||
MemoryUtil.memPutFloat(ptr + 32, nxZ);
|
||||
MemoryUtil.memPutFloat(ptr + 36, pxZ);
|
||||
MemoryUtil.memPutFloat(ptr + 40, nyZ);
|
||||
MemoryUtil.memPutFloat(ptr + 44, pyZ);
|
||||
MemoryUtil.memPutFloat(ptr + 48, nxW);
|
||||
MemoryUtil.memPutFloat(ptr + 52, pxW);
|
||||
MemoryUtil.memPutFloat(ptr + 56, nyW);
|
||||
MemoryUtil.memPutFloat(ptr + 60, pyW);
|
||||
MemoryUtil.memPutFloat(ptr + 64, nzX);
|
||||
MemoryUtil.memPutFloat(ptr + 68, pzX);
|
||||
MemoryUtil.memPutFloat(ptr + 72, nzY);
|
||||
MemoryUtil.memPutFloat(ptr + 76, pzY);
|
||||
MemoryUtil.memPutFloat(ptr + 80, nzZ);
|
||||
MemoryUtil.memPutFloat(ptr + 84, pzZ);
|
||||
MemoryUtil.memPutFloat(ptr + 88, nzW);
|
||||
MemoryUtil.memPutFloat(ptr + 92, pzW);
|
||||
}
|
||||
|
||||
public static int ceilingDiv(int numerator, int denominator) {
|
||||
return (numerator + denominator - 1) / denominator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package com.jozufozu.flywheel.lib.math;
|
||||
|
||||
import net.minecraftforge.client.model.lighting.QuadLighter;
|
||||
|
||||
public final class RenderMath {
|
||||
private RenderMath() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a signed byte into a signed, normalized float.
|
||||
*/
|
||||
|
@ -29,23 +34,17 @@ public final class RenderMath {
|
|||
return (byte) (int) (f * 255);
|
||||
}
|
||||
|
||||
public static int nextPowerOf2(int a) {
|
||||
int h = Integer.highestOneBit(a);
|
||||
return (h == a) ? h : (h << 1);
|
||||
}
|
||||
|
||||
public static float diffuseLight(float x, float y, float z, boolean shaded) {
|
||||
if (!shaded) {
|
||||
return 1f;
|
||||
}
|
||||
// FIXME: once we compile make sure this is correct.
|
||||
return Math.min(x * x + y * y * (3f + y) + z, 1f);
|
||||
return QuadLighter.calculateShade(x, y, z, false);
|
||||
}
|
||||
|
||||
public static float diffuseLightNether(float x, float y, float z, boolean shaded) {
|
||||
if (!shaded) {
|
||||
return 0.9f;
|
||||
}
|
||||
return Math.min(x * x * 0.6f + y * y * 0.9f + z * z * 0.8f, 1f);
|
||||
return QuadLighter.calculateShade(x, y, z, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import com.jozufozu.flywheel.lib.memory.MemoryBlock;
|
|||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder.DrawState;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -57,16 +56,12 @@ public final class ModelUtil {
|
|||
return dispatcher;
|
||||
}
|
||||
|
||||
public static boolean isVanillaBufferEmpty(BufferBuilder.RenderedBuffer renderedBuffer) {
|
||||
return renderedBuffer.drawState().vertexCount() == 0;
|
||||
}
|
||||
|
||||
public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer renderedBuffer, VertexType vertexType) {
|
||||
DrawState drawState = renderedBuffer.drawState();
|
||||
public static MemoryBlock convertVanillaBuffer(BufferBuilder.RenderedBuffer buffer, VertexType vertexType) {
|
||||
DrawState drawState = buffer.drawState();
|
||||
int vertexCount = drawState.vertexCount();
|
||||
VertexFormat srcFormat = drawState.format();
|
||||
|
||||
ByteBuffer src = renderedBuffer.vertexBuffer();
|
||||
ByteBuffer src = buffer.vertexBuffer();
|
||||
MemoryBlock dst = MemoryBlock.malloc((long) vertexCount * vertexType.getLayout().getStride());
|
||||
long srcPtr = MemoryUtil.memAddress(src);
|
||||
long dstPtr = dst.ptr();
|
||||
|
|
|
@ -33,10 +33,10 @@ public final class Models {
|
|||
|
||||
private static PoseStack createRotation(Direction facing) {
|
||||
PoseStack stack = new PoseStack();
|
||||
TransformStack.cast(stack)
|
||||
.centre()
|
||||
TransformStack.of(stack)
|
||||
.center()
|
||||
.rotateToFace(facing.getOpposite())
|
||||
.unCentre();
|
||||
.uncenter();
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
package com.jozufozu.flywheel.lib.model.baked;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder.DrawState;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder.RenderedBuffer;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.block.ModelBlockRenderer;
|
||||
|
@ -27,7 +23,6 @@ import net.minecraft.world.level.block.RenderShape;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import net.minecraftforge.client.ChunkRenderTypeSet;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
|
||||
public final class BakedModelBufferer {
|
||||
|
@ -44,17 +39,15 @@ public final class BakedModelBufferer {
|
|||
if (poseStack == null) {
|
||||
poseStack = objects.identityPoseStack;
|
||||
}
|
||||
var random = objects.random;
|
||||
RandomSource random = objects.random;
|
||||
BufferBuilder[] buffers = objects.shadedBuffers;
|
||||
|
||||
var renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
modelData = model.getModelData(renderWorld, BlockPos.ZERO, state, modelData);
|
||||
random.setSeed(42L);
|
||||
ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
|
||||
for (int layerIndex = 0; layerIndex < CHUNK_LAYER_AMOUNT; layerIndex++) {
|
||||
RenderType renderType = CHUNK_LAYERS[layerIndex];
|
||||
|
||||
if (!renderTypes.contains(renderType)) {
|
||||
continue;
|
||||
}
|
||||
for (RenderType renderType : renderTypes) {
|
||||
int layerIndex = renderType.getChunkLayerId();
|
||||
|
||||
BufferBuilder buffer = buffers[layerIndex];
|
||||
buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
|
||||
|
@ -63,9 +56,9 @@ public final class BakedModelBufferer {
|
|||
blockRenderer.tesselateBlock(renderWorld, model, state, BlockPos.ZERO, poseStack, buffer, false, random, 42L, OverlayTexture.NO_OVERLAY, modelData, renderType);
|
||||
poseStack.popPose();
|
||||
|
||||
buffer.end();
|
||||
var data = buffer.end();
|
||||
RenderedBuffer data = buffer.end();
|
||||
resultConsumer.accept(renderType, data);
|
||||
data.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,19 +67,17 @@ public final class BakedModelBufferer {
|
|||
if (poseStack == null) {
|
||||
poseStack = objects.identityPoseStack;
|
||||
}
|
||||
var random = objects.random;
|
||||
RandomSource random = objects.random;
|
||||
ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper;
|
||||
BufferBuilder[] shadedBuffers = objects.shadedBuffers;
|
||||
BufferBuilder[] unshadedBuffers = objects.unshadedBuffers;
|
||||
|
||||
var renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
modelData = model.getModelData(renderWorld, BlockPos.ZERO, state, modelData);
|
||||
random.setSeed(42L);
|
||||
ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
|
||||
for (int layerIndex = 0; layerIndex < CHUNK_LAYER_AMOUNT; layerIndex++) {
|
||||
RenderType renderType = CHUNK_LAYERS[layerIndex];
|
||||
|
||||
if (!renderTypes.contains(renderType)) {
|
||||
continue;
|
||||
}
|
||||
for (RenderType renderType : renderTypes) {
|
||||
int layerIndex = renderType.getChunkLayerId();
|
||||
|
||||
BufferBuilder shadedBuffer = shadedBuffers[layerIndex];
|
||||
BufferBuilder unshadedBuffer = unshadedBuffers[layerIndex];
|
||||
|
@ -98,12 +89,12 @@ public final class BakedModelBufferer {
|
|||
blockRenderer.tesselateBlock(renderWorld, model, state, BlockPos.ZERO, poseStack, shadeSeparatingWrapper, false, random, 42L, OverlayTexture.NO_OVERLAY, modelData, renderType);
|
||||
poseStack.popPose();
|
||||
|
||||
shadedBuffer.end();
|
||||
unshadedBuffer.end();
|
||||
var shadedData = shadedBuffer.end();
|
||||
var unshadedData = unshadedBuffer.end();
|
||||
RenderedBuffer shadedData = shadedBuffer.end();
|
||||
RenderedBuffer unshadedData = unshadedBuffer.end();
|
||||
resultConsumer.accept(renderType, true, shadedData);
|
||||
shadedData.release();
|
||||
resultConsumer.accept(renderType, false, unshadedData);
|
||||
unshadedData.release();
|
||||
}
|
||||
|
||||
shadeSeparatingWrapper.clear();
|
||||
|
@ -130,7 +121,7 @@ public final class BakedModelBufferer {
|
|||
if (poseStack == null) {
|
||||
poseStack = objects.identityPoseStack;
|
||||
}
|
||||
var random = objects.random;
|
||||
RandomSource random = objects.random;
|
||||
|
||||
BufferBuilder[] buffers = objects.shadedBuffers;
|
||||
for (BufferBuilder buffer : buffers) {
|
||||
|
@ -147,19 +138,16 @@ public final class BakedModelBufferer {
|
|||
continue;
|
||||
}
|
||||
|
||||
BakedModel model = renderDispatcher.getBlockModel(state);
|
||||
BlockPos pos = blockInfo.pos();
|
||||
long seed = state.getSeed(pos);
|
||||
BakedModel model = renderDispatcher.getBlockModel(state);
|
||||
ModelData modelData = modelDataMap.getOrDefault(pos, ModelData.EMPTY);
|
||||
modelData = model.getModelData(renderWorld, pos, state, modelData);
|
||||
random.setSeed(seed);
|
||||
ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
|
||||
var renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
|
||||
for (int layerIndex = 0; layerIndex < CHUNK_LAYER_AMOUNT; layerIndex++) {
|
||||
RenderType renderType = CHUNK_LAYERS[layerIndex];
|
||||
|
||||
if (!renderTypes.contains(renderType)) {
|
||||
continue;
|
||||
}
|
||||
for (RenderType renderType : renderTypes) {
|
||||
int layerIndex = renderType.getChunkLayerId();
|
||||
|
||||
BufferBuilder buffer = buffers[layerIndex];
|
||||
|
||||
|
@ -175,9 +163,9 @@ public final class BakedModelBufferer {
|
|||
for (int layerIndex = 0; layerIndex < CHUNK_LAYER_AMOUNT; layerIndex++) {
|
||||
RenderType renderType = CHUNK_LAYERS[layerIndex];
|
||||
BufferBuilder buffer = buffers[layerIndex];
|
||||
buffer.end();
|
||||
var data = buffer.end();
|
||||
RenderedBuffer data = buffer.end();
|
||||
resultConsumer.accept(renderType, data);
|
||||
data.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +174,7 @@ public final class BakedModelBufferer {
|
|||
if (poseStack == null) {
|
||||
poseStack = objects.identityPoseStack;
|
||||
}
|
||||
var random = objects.random;
|
||||
RandomSource random = objects.random;
|
||||
ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper;
|
||||
|
||||
BufferBuilder[] shadedBuffers = objects.shadedBuffers;
|
||||
|
@ -208,19 +196,16 @@ public final class BakedModelBufferer {
|
|||
continue;
|
||||
}
|
||||
|
||||
BakedModel model = renderDispatcher.getBlockModel(state);
|
||||
BlockPos pos = blockInfo.pos();
|
||||
long seed = state.getSeed(pos);
|
||||
BakedModel model = renderDispatcher.getBlockModel(state);
|
||||
ModelData modelData = modelDataMap.getOrDefault(pos, ModelData.EMPTY);
|
||||
modelData = model.getModelData(renderWorld, pos, state, modelData);
|
||||
random.setSeed(seed);
|
||||
ChunkRenderTypeSet renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
|
||||
var renderTypes = model.getRenderTypes(state, random, modelData);
|
||||
|
||||
for (int layerIndex = 0; layerIndex < CHUNK_LAYER_AMOUNT; layerIndex++) {
|
||||
RenderType renderType = CHUNK_LAYERS[layerIndex];
|
||||
|
||||
if (!renderTypes.contains(renderType)) {
|
||||
continue;
|
||||
}
|
||||
for (RenderType renderType : renderTypes) {
|
||||
int layerIndex = renderType.getChunkLayerId();
|
||||
|
||||
shadeSeparatingWrapper.prepare(shadedBuffers[layerIndex], unshadedBuffers[layerIndex]);
|
||||
|
||||
|
@ -239,26 +224,26 @@ public final class BakedModelBufferer {
|
|||
RenderType renderType = CHUNK_LAYERS[layerIndex];
|
||||
BufferBuilder shadedBuffer = shadedBuffers[layerIndex];
|
||||
BufferBuilder unshadedBuffer = unshadedBuffers[layerIndex];
|
||||
shadedBuffer.end();
|
||||
unshadedBuffer.end();
|
||||
var shadedData = shadedBuffer.end();
|
||||
var unshadedData = unshadedBuffer.end();
|
||||
RenderedBuffer shadedData = shadedBuffer.end();
|
||||
RenderedBuffer unshadedData = unshadedBuffer.end();
|
||||
resultConsumer.accept(renderType, true, shadedData);
|
||||
shadedData.release();
|
||||
resultConsumer.accept(renderType, false, unshadedData);
|
||||
unshadedData.release();
|
||||
}
|
||||
}
|
||||
|
||||
public interface ResultConsumer {
|
||||
void accept(RenderType renderType, BufferBuilder.RenderedBuffer data);
|
||||
void accept(RenderType renderType, RenderedBuffer data);
|
||||
}
|
||||
|
||||
public interface ShadeSeparatedResultConsumer {
|
||||
void accept(RenderType renderType, boolean shaded, BufferBuilder.RenderedBuffer data);
|
||||
void accept(RenderType renderType, boolean shaded, RenderedBuffer data);
|
||||
}
|
||||
|
||||
private static class ThreadLocalObjects {
|
||||
public final PoseStack identityPoseStack = new PoseStack();
|
||||
public final RandomSource random = RandomSource.create();
|
||||
public final RandomSource random = RandomSource.createNewThreadLocalInstance();
|
||||
|
||||
public final ShadeSeparatingVertexConsumer shadeSeparatingWrapper = new ShadeSeparatingVertexConsumer();
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class BakedModelBuilder {
|
|||
|
||||
if (shadeSeparated) {
|
||||
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
||||
if (!ModelUtil.isVanillaBufferEmpty(data)) {
|
||||
if (!data.isEmpty()) {
|
||||
Material material = materialFunc.apply(renderType, shaded);
|
||||
if (material != null) {
|
||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
||||
|
@ -92,7 +92,7 @@ public class BakedModelBuilder {
|
|||
BakedModelBufferer.bufferSingleShadeSeparated(ModelUtil.VANILLA_RENDERER.getModelRenderer(), renderWorld, bakedModel, blockState, poseStack, modelData, resultConsumer);
|
||||
} else {
|
||||
ResultConsumer resultConsumer = (renderType, data) -> {
|
||||
if (!ModelUtil.isVanillaBufferEmpty(data)) {
|
||||
if (!data.isEmpty()) {
|
||||
Material material = materialFunc.apply(renderType, true);
|
||||
if (material != null) {
|
||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class BlockModelBuilder {
|
|||
private boolean shadeSeparated = true;
|
||||
private BlockAndTintGetter renderWorld;
|
||||
private PoseStack poseStack;
|
||||
private ModelData modelData = ModelData.EMPTY;
|
||||
private ModelData modelData;
|
||||
private BiFunction<RenderType, Boolean, Material> materialFunc;
|
||||
|
||||
public BlockModelBuilder(BlockState state) {
|
||||
|
@ -70,7 +70,7 @@ public class BlockModelBuilder {
|
|||
|
||||
if (shadeSeparated) {
|
||||
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
||||
if (!ModelUtil.isVanillaBufferEmpty(data)) {
|
||||
if (!data.isEmpty()) {
|
||||
Material material = materialFunc.apply(renderType, shaded);
|
||||
if (material != null) {
|
||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
||||
|
@ -81,7 +81,7 @@ public class BlockModelBuilder {
|
|||
BakedModelBufferer.bufferBlockShadeSeparated(ModelUtil.VANILLA_RENDERER, renderWorld, state, poseStack, modelData, resultConsumer);
|
||||
} else {
|
||||
ResultConsumer resultConsumer = (renderType, data) -> {
|
||||
if (!ModelUtil.isVanillaBufferEmpty(data)) {
|
||||
if (!data.isEmpty()) {
|
||||
Material material = materialFunc.apply(renderType, true);
|
||||
if (material != null) {
|
||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class MultiBlockModelBuilder {
|
|||
|
||||
if (shadeSeparated) {
|
||||
ShadeSeparatedResultConsumer resultConsumer = (renderType, shaded, data) -> {
|
||||
if (!ModelUtil.isVanillaBufferEmpty(data)) {
|
||||
if (!data.isEmpty()) {
|
||||
Material material = materialFunc.apply(renderType, shaded);
|
||||
if (material != null) {
|
||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
||||
|
@ -85,7 +85,7 @@ public class MultiBlockModelBuilder {
|
|||
BakedModelBufferer.bufferMultiBlockShadeSeparated(blocks, ModelUtil.VANILLA_RENDERER, renderWorld, poseStack, modelDataMap, resultConsumer);
|
||||
} else {
|
||||
ResultConsumer resultConsumer = (renderType, data) -> {
|
||||
if (!ModelUtil.isVanillaBufferEmpty(data)) {
|
||||
if (!data.isEmpty()) {
|
||||
Material material = materialFunc.apply(renderType, true);
|
||||
if (material != null) {
|
||||
MemoryBlock meshData = ModelUtil.convertVanillaBuffer(data, VertexTypes.BLOCK);
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.jozufozu.flywheel.lib.model.baked;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.jozufozu.flywheel.lib.model.baked;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
|
@ -22,13 +20,12 @@ import net.minecraft.world.level.block.state.BlockState;
|
|||
import net.minecraft.world.level.chunk.DataLayer;
|
||||
import net.minecraft.world.level.chunk.LightChunk;
|
||||
import net.minecraft.world.level.chunk.LightChunkGetter;
|
||||
import net.minecraft.world.level.lighting.ChunkSkyLightSources;
|
||||
import net.minecraft.world.level.lighting.LayerLightEventListener;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
|
||||
public interface VirtualEmptyBlockGetter extends BlockAndTintGetter, LightChunk {
|
||||
public interface VirtualEmptyBlockGetter extends BlockAndTintGetter {
|
||||
public static final VirtualEmptyBlockGetter INSTANCE = new StaticLightImpl(0, 15);
|
||||
public static final VirtualEmptyBlockGetter FULL_BRIGHT = new StaticLightImpl(15, 15);
|
||||
public static final VirtualEmptyBlockGetter FULL_DARK = new StaticLightImpl(0, 0);
|
||||
|
@ -38,6 +35,7 @@ public interface VirtualEmptyBlockGetter extends BlockAndTintGetter, LightChunk
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
default BlockEntity getBlockEntity(BlockPos pos) {
|
||||
return null;
|
||||
}
|
||||
|
@ -73,21 +71,15 @@ public interface VirtualEmptyBlockGetter extends BlockAndTintGetter, LightChunk
|
|||
return resolver.getColor(plainsBiome, pos.getX(), pos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
default void findBlockLightSources(BiConsumer<BlockPos, BlockState> pOutput) {
|
||||
}
|
||||
|
||||
public static class StaticLightImpl implements VirtualEmptyBlockGetter {
|
||||
private final LevelLightEngine lightEngine;
|
||||
private final ChunkSkyLightSources lightSources;
|
||||
|
||||
public StaticLightImpl(int blockLight, int skyLight) {
|
||||
lightEngine = new LevelLightEngine(new LightChunkGetter() {
|
||||
|
||||
|
||||
@Override
|
||||
public LightChunk getChunkForLighting(int p_63023_, int p_63024_) {
|
||||
return StaticLightImpl.this;
|
||||
@Nullable
|
||||
public LightChunk getChunkForLighting(int x, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,8 +95,6 @@ public interface VirtualEmptyBlockGetter extends BlockAndTintGetter, LightChunk
|
|||
return layer == LightLayer.BLOCK ? blockListener : skyListener;
|
||||
}
|
||||
};
|
||||
|
||||
lightSources = new ChunkSkyLightSources(this);
|
||||
}
|
||||
|
||||
private static LayerLightEventListener createStaticListener(int light) {
|
||||
|
@ -113,28 +103,26 @@ public interface VirtualEmptyBlockGetter extends BlockAndTintGetter, LightChunk
|
|||
public void checkBlock(BlockPos pos) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int runLightUpdates() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightEnabled(ChunkPos pChunkPos, boolean pLightEnabled) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propagateLightSources(ChunkPos pChunkPos) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLightWork() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSectionStatus(SectionPos pos, boolean isQueueEmpty) {
|
||||
public int runLightUpdates() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSectionStatus(SectionPos pos, boolean isSectionEmpty) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightEnabled(ChunkPos pos, boolean lightEnabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propagateLightSources(ChunkPos pos) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -153,10 +141,5 @@ public interface VirtualEmptyBlockGetter extends BlockAndTintGetter, LightChunk
|
|||
public LevelLightEngine getLightEngine() {
|
||||
return lightEngine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkSkyLightSources getSkyLightSources() {
|
||||
return lightSources;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package com.jozufozu.flywheel.lib.model.baked;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.jozufozu.flywheel.api.model.Model;
|
||||
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
import net.minecraftforge.client.model.data.ModelProperty;
|
||||
|
||||
/**
|
||||
* This model data instance is passed whenever a model is rendered without
|
||||
* available in-world context. BakedModel#getModelData can react accordingly
|
||||
* and avoid looking for model data itself.
|
||||
**/
|
||||
public class VirtualEmptyModelData {
|
||||
// TODO: Remove? Doesn't seem necessary anymore
|
||||
public static final ModelData INSTANCE = ModelData.EMPTY;
|
||||
|
||||
public static boolean is(ModelData data) {
|
||||
return data == INSTANCE;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.jozufozu.flywheel.lib.task;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.jozufozu.flywheel.api.task.Plan;
|
||||
|
||||
public interface SimplyComposedPlan<C> extends Plan<C> {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.jozufozu.flywheel.lib.task;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.jozufozu.flywheel.api.task.Plan;
|
||||
import com.jozufozu.flywheel.api.task.TaskExecutor;
|
||||
|
||||
|
|
|
@ -4,77 +4,114 @@ import org.joml.AxisAngle4f;
|
|||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.mojang.math.Axis;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
public interface Rotate<Self> {
|
||||
Self multiply(Quaternionf quaternion);
|
||||
public interface Rotate<Self extends Rotate<Self>> {
|
||||
Self rotate(Quaternionf quaternion);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotate(Direction axis, float radians) {
|
||||
if (radians == 0)
|
||||
return (Self) this;
|
||||
return multiplyRadians(axis.step(), radians);
|
||||
}
|
||||
|
||||
default Self rotate(double angle, Direction.Axis axis) {
|
||||
Axes.Axis vec = switch (axis) {
|
||||
case X -> Axes.XP;
|
||||
case Y -> Axes.YP;
|
||||
case Z -> Axes.ZP;
|
||||
};
|
||||
return multiply(vec.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateX(double angle) {
|
||||
return multiply(Axes.XP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateY(double angle) {
|
||||
return multiply(Axes.YP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateZ(double angle) {
|
||||
return multiply(Axes.ZP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateXRadians(double angle) {
|
||||
return multiplyRadians(Axes.XP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateYRadians(double angle) {
|
||||
return multiplyRadians(Axes.YP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateZRadians(double angle) {
|
||||
return multiplyRadians(Axes.ZP.vec(), angle);
|
||||
default Self rotate(AxisAngle4f axisAngle) {
|
||||
return rotate(new Quaternionf(axisAngle));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self multiply(Vector3fc axis, double angle) {
|
||||
if (angle == 0)
|
||||
default Self rotate(float radians, Vector3fc axis) {
|
||||
if (radians == 0) {
|
||||
return (Self) this;
|
||||
return multiplyRadians(axis, Math.toRadians(angle));
|
||||
}
|
||||
return rotate(new Quaternionf().setAngleAxis(radians, axis.x(), axis.y(), axis.z()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self multiplyRadians(Vector3fc axis, double angle) {
|
||||
if (angle == 0)
|
||||
default Self rotate(float radians, Axis axis) {
|
||||
if (radians == 0) {
|
||||
return (Self) this;
|
||||
return multiply(new Quaternionf(new AxisAngle4f((float) angle, axis)));
|
||||
}
|
||||
return rotate(axis.rotation(radians));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotate(float radians, Direction axis) {
|
||||
if (radians == 0) {
|
||||
return (Self) this;
|
||||
}
|
||||
return rotate(radians, axis.step());
|
||||
}
|
||||
|
||||
default Self rotate(float radians, Direction.Axis axis) {
|
||||
return switch (axis) {
|
||||
case X -> rotateX(radians);
|
||||
case Y -> rotateY(radians);
|
||||
case Z -> rotateZ(radians);
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateDegrees(float degrees, Vector3fc axis) {
|
||||
if (degrees == 0) {
|
||||
return (Self) this;
|
||||
}
|
||||
return rotate((float) Math.toRadians(degrees), axis);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateDegrees(float degrees, Axis axis) {
|
||||
if (degrees == 0) {
|
||||
return (Self) this;
|
||||
}
|
||||
return rotate(axis.rotationDegrees(degrees));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateDegrees(float degrees, Direction axis) {
|
||||
if (degrees == 0) {
|
||||
return (Self) this;
|
||||
}
|
||||
return rotate((float) Math.toRadians(degrees), axis);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateDegrees(float degrees, Direction.Axis axis) {
|
||||
if (degrees == 0) {
|
||||
return (Self) this;
|
||||
}
|
||||
return rotate((float) Math.toRadians(degrees), axis);
|
||||
}
|
||||
|
||||
default Self rotateX(float radians) {
|
||||
return rotate(radians, Axis.XP);
|
||||
}
|
||||
|
||||
default Self rotateY(float radians) {
|
||||
return rotate(radians, Axis.YP);
|
||||
}
|
||||
|
||||
default Self rotateZ(float radians) {
|
||||
return rotate(radians, Axis.ZP);
|
||||
}
|
||||
|
||||
default Self rotateXDegrees(float degrees) {
|
||||
return rotateDegrees(degrees, Axis.XP);
|
||||
}
|
||||
|
||||
default Self rotateYDegrees(float degrees) {
|
||||
return rotateDegrees(degrees, Axis.YP);
|
||||
}
|
||||
|
||||
default Self rotateZDegrees(float degrees) {
|
||||
return rotateDegrees(degrees, Axis.ZP);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateToFace(Direction facing) {
|
||||
switch (facing) {
|
||||
case SOUTH -> multiply(Axes.YP.rotationDegrees(180));
|
||||
case WEST -> multiply(Axes.YP.rotationDegrees(90));
|
||||
case NORTH -> multiply(Axes.YP.rotationDegrees(0));
|
||||
case EAST -> multiply(Axes.YP.rotationDegrees(270));
|
||||
case UP -> multiply(Axes.XP.rotationDegrees(90));
|
||||
case DOWN -> multiply(Axes.XN.rotationDegrees(90));
|
||||
}
|
||||
return (Self) this;
|
||||
return switch (facing) {
|
||||
case DOWN -> rotateXDegrees(-90);
|
||||
case UP -> rotateXDegrees(90);
|
||||
case NORTH -> (Self) this;
|
||||
case SOUTH -> rotateYDegrees(180);
|
||||
case WEST -> rotateYDegrees(90);
|
||||
case EAST -> rotateYDegrees(270);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.jozufozu.flywheel.lib.transform;
|
||||
|
||||
public interface Scale<Self> {
|
||||
public interface Scale<Self extends Scale<Self>> {
|
||||
Self scale(float factorX, float factorY, float factorZ);
|
||||
|
||||
default Self scale(float factor) {
|
||||
|
|
|
@ -5,10 +5,11 @@ import org.joml.Matrix4f;
|
|||
import org.joml.Quaternionf;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
public interface Transform<Self extends Transform<Self>> extends Translate<Self>, Rotate<Self>, Scale<Self> {
|
||||
public interface Transform<Self extends Transform<Self>> extends Scale<Self>, Rotate<Self>, Translate<Self> {
|
||||
Self mulPose(Matrix4f pose);
|
||||
|
||||
Self mulNormal(Matrix3f normal);
|
||||
|
@ -24,16 +25,23 @@ public interface Transform<Self extends Transform<Self>> extends Translate<Self>
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateCentered(Direction axis, float radians) {
|
||||
translate(.5f, .5f, .5f).rotate(axis, radians)
|
||||
.translate(-.5f, -.5f, -.5f);
|
||||
default Self rotateCentered(Quaternionf q) {
|
||||
center().rotate(q)
|
||||
.uncenter();
|
||||
return (Self) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateCentered(Quaternionf q) {
|
||||
translate(.5f, .5f, .5f).multiply(q)
|
||||
.translate(-.5f, -.5f, -.5f);
|
||||
default Self rotateCentered(float radians, Axis axis) {
|
||||
center().rotate(radians, axis)
|
||||
.uncenter();
|
||||
return (Self) this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self rotateCentered(float radians, Direction axis) {
|
||||
center().rotate(radians, axis)
|
||||
.uncenter();
|
||||
return (Self) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ public interface TransformStack extends Transform<TransformStack> {
|
|||
|
||||
TransformStack popPose();
|
||||
|
||||
static TransformStack cast(PoseStack stack) {
|
||||
static TransformStack of(PoseStack stack) {
|
||||
return (TransformStack) stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,18 +5,10 @@ import org.joml.Vector3f;
|
|||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public interface Translate<Self> {
|
||||
public interface Translate<Self extends Translate<Self>> {
|
||||
Self translate(double x, double y, double z);
|
||||
|
||||
default Self centre() {
|
||||
return translateAll(0.5);
|
||||
}
|
||||
|
||||
default Self unCentre() {
|
||||
return translateAll(-0.5);
|
||||
}
|
||||
|
||||
default Self translateAll(double v) {
|
||||
default Self translate(double v) {
|
||||
return translate(v, v, v);
|
||||
}
|
||||
|
||||
|
@ -36,24 +28,40 @@ public interface Translate<Self> {
|
|||
return translate(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
default Self translate(Vec3 vec) {
|
||||
return translate(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
default Self translate(Vector3f vec) {
|
||||
return translate(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
default Self translateBack(Vec3 vec) {
|
||||
return translate(-vec.x, -vec.y, -vec.z);
|
||||
default Self translate(Vec3 vec) {
|
||||
return translate(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
default Self translateBack(double x, double y, double z) {
|
||||
return translate(-x, -y, -z);
|
||||
}
|
||||
|
||||
default Self translateBack(double v) {
|
||||
return translate(-v);
|
||||
}
|
||||
|
||||
default Self translateBack(Vec3i vec) {
|
||||
return translate(-vec.getX(), -vec.getY(), -vec.getZ());
|
||||
return translateBack(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
default Self translateBack(Vector3f vec) {
|
||||
return translateBack(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
default Self translateBack(Vec3 vec) {
|
||||
return translateBack(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
default Self center() {
|
||||
return translate(0.5);
|
||||
}
|
||||
|
||||
default Self uncenter() {
|
||||
return translate(-0.5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,8 +10,7 @@ import com.jozufozu.flywheel.api.event.BeginFrameEvent;
|
|||
import com.jozufozu.flywheel.api.event.RenderContext;
|
||||
import com.jozufozu.flywheel.api.uniform.ShaderUniforms;
|
||||
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixUtil;
|
||||
import com.jozufozu.flywheel.lib.math.MoreMath;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
@ -88,7 +87,7 @@ public class FlwShaderUniforms implements ShaderUniforms {
|
|||
viewProjection.set(context.viewProjection());
|
||||
viewProjection.translate(-camX, -camY, -camZ);
|
||||
|
||||
MatrixUtil.writeUnsafe(viewProjection, ptr + 32);
|
||||
MatrixMath.writeUnsafe(viewProjection, ptr + 32);
|
||||
MemoryUtil.memPutFloat(ptr + 96, camX);
|
||||
MemoryUtil.memPutFloat(ptr + 100, camY);
|
||||
MemoryUtil.memPutFloat(ptr + 104, camZ);
|
||||
|
@ -96,7 +95,7 @@ public class FlwShaderUniforms implements ShaderUniforms {
|
|||
MemoryUtil.memPutInt(ptr + 112, getConstantAmbientLightFlag(context));
|
||||
|
||||
if (!FRUSTUM_PAUSED || FRUSTUM_CAPTURE) {
|
||||
MoreMath.writePackedFrustumPlanes(ptr + 128, viewProjection);
|
||||
MatrixMath.writePackedFrustumPlanes(ptr + 128, viewProjection);
|
||||
FRUSTUM_CAPTURE = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package com.jozufozu.flywheel.lib.util;
|
||||
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
public class Axes {
|
||||
|
||||
public static Axis XP = new Axis(new Vector3f(1, 0, 0));
|
||||
public static Axis YP = new Axis(new Vector3f(0, 1, 0));
|
||||
public static Axis ZP = new Axis(new Vector3f(0, 0, 1));
|
||||
public static Axis XN = new Axis(new Vector3f(-1, 0, 0));
|
||||
public static Axis YN = new Axis(new Vector3f(0, -1, 0));
|
||||
public static Axis ZN = new Axis(new Vector3f(0, 0, -1));
|
||||
|
||||
public record Axis(Vector3fc vec) {
|
||||
public Quaternionf rotation(float radians) {
|
||||
return new Quaternionf().setAngleAxis(radians, vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
public Quaternionf rotationDegrees(float degrees) {
|
||||
return rotation((float) Math.toRadians(degrees));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,8 +5,6 @@ import java.util.Collections;
|
|||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public final class FlwUtil {
|
||||
|
@ -21,19 +19,6 @@ public final class FlwUtil {
|
|||
return Collections.newSetFromMap(new WeakHashMap<>());
|
||||
}
|
||||
|
||||
public static PoseStack copyPoseStack(PoseStack stack) {
|
||||
PoseStack copy = new PoseStack();
|
||||
copy.last()
|
||||
.pose()
|
||||
.set(stack.last()
|
||||
.pose());
|
||||
copy.last()
|
||||
.normal()
|
||||
.set(stack.last()
|
||||
.normal());
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static int[] initArray(int size, int fill) {
|
||||
var out = new int[size];
|
||||
Arrays.fill(out, fill);
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
package com.jozufozu.flywheel.lib.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class ResourceUtil {
|
||||
// Match the complement of alphanumeric and underscore.
|
||||
private static final Pattern UNSAFE_CHARS = Pattern.compile("[^a-zA-Z0-9_]");
|
||||
|
||||
public static ResourceLocation defaultToFlywheelNamespace(String location) {
|
||||
String namespace = Flywheel.ID;
|
||||
String path = location;
|
||||
|
@ -24,28 +19,4 @@ public class ResourceUtil {
|
|||
|
||||
return new ResourceLocation(namespace, path);
|
||||
}
|
||||
|
||||
public static ResourceLocation subPath(ResourceLocation root, String subPath) {
|
||||
return new ResourceLocation(root.getNamespace(), root.getPath() + subPath);
|
||||
}
|
||||
|
||||
public static ResourceLocation removePrefixUnchecked(ResourceLocation full, String root) {
|
||||
return new ResourceLocation(full.getNamespace(), full.getPath()
|
||||
.substring(root.length()));
|
||||
}
|
||||
|
||||
public static ResourceLocation trim(ResourceLocation loc, String prefix, String suffix) {
|
||||
String path = loc.getPath();
|
||||
return new ResourceLocation(loc.getNamespace(), path.substring(prefix.length(), path.length() - suffix.length()));
|
||||
}
|
||||
|
||||
public static String toSafeString(ResourceLocation rl) {
|
||||
return UNSAFE_CHARS.matcher(rl.toString())
|
||||
.replaceAll("_");
|
||||
}
|
||||
|
||||
public static ResourceLocation prefixed(String basePath, ResourceLocation resourceLocation) {
|
||||
String path = resourceLocation.getPath();
|
||||
return new ResourceLocation(resourceLocation.getNamespace(), basePath + path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.joml.Matrix3f;
|
|||
import org.joml.Matrix4f;
|
||||
|
||||
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixUtil;
|
||||
import com.jozufozu.flywheel.lib.math.MatrixMath;
|
||||
|
||||
public final class VertexTransformations {
|
||||
private VertexTransformations() {
|
||||
|
@ -14,9 +14,9 @@ public final class VertexTransformations {
|
|||
float x = vertexList.x(index);
|
||||
float y = vertexList.y(index);
|
||||
float z = vertexList.z(index);
|
||||
vertexList.x(index, MatrixUtil.transformPositionX(matrix, x, y, z));
|
||||
vertexList.y(index, MatrixUtil.transformPositionY(matrix, x, y, z));
|
||||
vertexList.z(index, MatrixUtil.transformPositionZ(matrix, x, y, z));
|
||||
vertexList.x(index, MatrixMath.transformPositionX(matrix, x, y, z));
|
||||
vertexList.y(index, MatrixMath.transformPositionY(matrix, x, y, z));
|
||||
vertexList.z(index, MatrixMath.transformPositionZ(matrix, x, y, z));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,9 +26,9 @@ public final class VertexTransformations {
|
|||
float nx = vertexList.normalX(index);
|
||||
float ny = vertexList.normalY(index);
|
||||
float nz = vertexList.normalZ(index);
|
||||
float tnx = MatrixUtil.transformNormalX(matrix, nx, ny, nz);
|
||||
float tny = MatrixUtil.transformNormalY(matrix, nx, ny, nz);
|
||||
float tnz = MatrixUtil.transformNormalZ(matrix, nx, ny, nz);
|
||||
float tnx = MatrixMath.transformNormalX(matrix, nx, ny, nz);
|
||||
float tny = MatrixMath.transformNormalY(matrix, nx, ny, nz);
|
||||
float tnz = MatrixMath.transformNormalZ(matrix, nx, ny, nz);
|
||||
// seems to be the case that sqrLength is always ~1.0
|
||||
// float sqrLength = fma(tnx, tnx, fma(tny, tny, tnz * tnz));
|
||||
// if (sqrLength != 0) {
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.jetbrains.annotations.ApiStatus;
|
|||
|
||||
import com.jozufozu.flywheel.Flywheel;
|
||||
import com.jozufozu.flywheel.api.vertex.VertexType;
|
||||
import com.jozufozu.flywheel.lib.util.ResourceUtil;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
|
@ -20,8 +19,8 @@ public final class VertexTypes {
|
|||
}
|
||||
|
||||
public static final class Files {
|
||||
public static final ResourceLocation BLOCK_LAYOUT = ResourceUtil.subPath(Names.BLOCK, ".vert");
|
||||
public static final ResourceLocation POS_TEX_NORMAL_LAYOUT = ResourceUtil.subPath(Names.POS_TEX_NORMAL, ".vert");
|
||||
public static final ResourceLocation BLOCK_LAYOUT = Names.BLOCK.withSuffix(".vert");
|
||||
public static final ResourceLocation POS_TEX_NORMAL_LAYOUT = Names.POS_TEX_NORMAL.withSuffix(".vert");
|
||||
}
|
||||
|
||||
public static final class Names {
|
||||
|
|
|
@ -64,14 +64,13 @@ public class LevelRendererMixin {
|
|||
MinecraftForge.EVENT_BUS.post(new ReloadRenderersEvent(level));
|
||||
}
|
||||
|
||||
// // after the game renders the breaking overlay normally
|
||||
// @Inject(method = "renderLevel",
|
||||
// at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderBuffers;crumblingBufferSource()Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;", ordinal = 2, shift = Shift.BY, by = 2))
|
||||
// private void flywheel$renderCrumbling(CallbackInfo ci) {
|
||||
// if (flywheel$renderContext != null) {
|
||||
// // TODO: Crumbling
|
||||
// }
|
||||
// }
|
||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=destroyProgress"))
|
||||
private void flywheel$beforeRenderCrumbling(CallbackInfo ci) {
|
||||
var manager = VisualizationManagerImpl.get(level);
|
||||
if (manager != null) {
|
||||
manager.renderCrumbling(flywheel$renderContext, destructionProgress);
|
||||
}
|
||||
}
|
||||
|
||||
// STAGE DISPATCHING
|
||||
|
||||
|
@ -151,12 +150,4 @@ public class LevelRendererMixin {
|
|||
private void flywheel$onStage$afterWeather(CallbackInfo ci) {
|
||||
flywheel$dispatch(RenderStage.AFTER_WEATHER);
|
||||
}
|
||||
|
||||
@Inject(method = "renderLevel", at = @At(value = "INVOKE_STRING", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", args = "ldc=destroyProgress"))
|
||||
private void flywheel$crumbling(CallbackInfo ci) {
|
||||
var vm = VisualizationManagerImpl.get(level);
|
||||
if (vm != null) {
|
||||
vm.renderCrumbling(flywheel$renderContext, destructionProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.jozufozu.flywheel.mixin.matrix;
|
||||
package com.jozufozu.flywheel.mixin;
|
||||
|
||||
import org.joml.Quaternionf;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
@ -8,18 +8,6 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
|||
|
||||
@Mixin(PoseStack.class)
|
||||
public abstract class PoseStackMixin implements TransformStack {
|
||||
@Override
|
||||
public TransformStack multiply(Quaternionf quaternion) {
|
||||
((PoseStack) (Object) this).mulPose(quaternion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack scale(float factorX, float factorY, float factorZ) {
|
||||
((PoseStack) (Object) this).scale(factorX, factorY, factorZ);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack pushPose() {
|
||||
((PoseStack) (Object) this).pushPose();
|
||||
|
@ -32,6 +20,18 @@ public abstract class PoseStackMixin implements TransformStack {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack scale(float factorX, float factorY, float factorZ) {
|
||||
((PoseStack) (Object) this).scale(factorX, factorY, factorZ);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack rotate(Quaternionf quaternion) {
|
||||
((PoseStack) (Object) this).mulPose(quaternion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformStack translate(double x, double y, double z) {
|
||||
((PoseStack) (Object) this).translate(x, y, z);
|
|
@ -17,10 +17,10 @@ public class FixNormalScalingMixin {
|
|||
* applied, which negates the matrix again, resulting in the matrix being the
|
||||
* same as in the beginning.
|
||||
*/
|
||||
// @Inject(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lcom/mojang/math/Matrix3f;mul(F)V", shift = Shift.AFTER), cancellable = true)
|
||||
// private void flywheel$returnAfterNegate(float x, float y, float z, CallbackInfo ci) {
|
||||
// ci.cancel();
|
||||
// }
|
||||
@Inject(method = "scale(FFF)V", at = @At(value = "INVOKE", target = "Lorg/joml/Matrix3f;scale(F)Lorg/joml/Matrix3f;", shift = Shift.AFTER), cancellable = true)
|
||||
private void flywheel$returnAfterNegate(float x, float y, float z, CallbackInfo ci) {
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Minecraft takes the inverse cube root of the product of all scales to provide a
|
||||
|
|
|
@ -6,18 +6,18 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
|||
|
||||
import com.jozufozu.flywheel.impl.visualization.VisualizationHelper;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.tasks.ChunkRenderRebuildTask;
|
||||
import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
@Mixin(value = ChunkRenderRebuildTask.class, remap = false)
|
||||
public class ChunkRenderRebuildTaskMixin {
|
||||
@Redirect(method = "performBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;getRenderer(Lnet/minecraft/world/level/block/entity/BlockEntity;)Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderer;"))
|
||||
@Mixin(value = ChunkBuilderMeshingTask.class, remap = false)
|
||||
public class ChunkBuilderMeshingTaskMixin {
|
||||
@Redirect(method = "execute", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderDispatcher;getRenderer(Lnet/minecraft/world/level/block/entity/BlockEntity;)Lnet/minecraft/client/renderer/blockentity/BlockEntityRenderer;", remap = true))
|
||||
private BlockEntityRenderer<?> flywheel$redirectGetRenderer(BlockEntityRenderDispatcher dispatcher, BlockEntity blockEntity) {
|
||||
if (VisualizationHelper.tryAddBlockEntity(blockEntity)) {
|
||||
return null;
|
||||
}
|
||||
return dispatcher.getRenderer(blockEntity);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,43 +1,21 @@
|
|||
package com.jozufozu.flywheel.mixin.visualmanage;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Coerce;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.impl.visualization.VisualizationHelper;
|
||||
|
||||
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
|
||||
import net.minecraft.client.renderer.chunk.RenderChunkRegion;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask")
|
||||
public class ChunkRebuildHooksMixin {
|
||||
|
||||
// FIXME: use this instead of the redirect if there's a clean way to reference the CompileResults
|
||||
// @Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
|
||||
// private <E extends BlockEntity> void flywheel$tryAddBlockEntity(Object pCompileResults, E pBlockEntity, CallbackInfo ci) {
|
||||
// if (VisualizationHelper.tryAddBlockEntity(pBlockEntity)) {
|
||||
// ci.cancel();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Redirect(method = "compile", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/RenderChunkRegion;getBlockEntity(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/entity/BlockEntity;"))
|
||||
private BlockEntity flywheel$interceptGetBlockEntity(RenderChunkRegion region, BlockPos pos) {
|
||||
BlockEntity blockEntity = region.getBlockEntity(pos);
|
||||
|
||||
if (blockEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
|
||||
private void flywheel$tryAddBlockEntity(@Coerce Object compileResults, BlockEntity blockEntity, CallbackInfo ci) {
|
||||
if (VisualizationHelper.tryAddBlockEntity(blockEntity)) {
|
||||
return null;
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
return blockEntity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import com.jozufozu.flywheel.lib.material.Materials;
|
|||
import com.jozufozu.flywheel.lib.model.ModelCache;
|
||||
import com.jozufozu.flywheel.lib.model.SimpleModel;
|
||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.jozufozu.flywheel.lib.util.Pair;
|
||||
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual;
|
||||
|
||||
|
@ -134,20 +133,16 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
|
||||
lid.loadIdentity()
|
||||
.translate(getVisualPosition())
|
||||
.centre()
|
||||
.multiply(baseRotation)
|
||||
.unCentre()
|
||||
.rotateCentered(baseRotation)
|
||||
.translate(0, 9f / 16f, 1f / 16f)
|
||||
.rotateXRadians(angleX)
|
||||
.rotateX(angleX)
|
||||
.translate(0, -9f / 16f, -1f / 16f);
|
||||
|
||||
lock.loadIdentity()
|
||||
.translate(getVisualPosition())
|
||||
.centre()
|
||||
.multiply(baseRotation)
|
||||
.unCentre()
|
||||
.rotateCentered(baseRotation)
|
||||
.translate(0, 8f / 16f, 0)
|
||||
.rotateXRadians(angleX)
|
||||
.rotateX(angleX)
|
||||
.translate(0, -8f / 16f, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ import com.jozufozu.flywheel.lib.model.ModelHolder;
|
|||
import com.jozufozu.flywheel.lib.model.Models;
|
||||
import com.jozufozu.flywheel.lib.model.SimpleModel;
|
||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.jozufozu.flywheel.lib.visual.AbstractEntityVisual;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.util.Mth;
|
||||
|
@ -143,8 +143,8 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
}
|
||||
|
||||
stack.translate(0.0D, 0.375D, 0.0D);
|
||||
stack.mulPose(Axes.YP.rotationDegrees(180 - yaw));
|
||||
stack.mulPose(Axes.ZP.rotationDegrees(-pitch));
|
||||
stack.mulPose(Axis.YP.rotationDegrees(180 - yaw));
|
||||
stack.mulPose(Axis.ZP.rotationDegrees(-pitch));
|
||||
|
||||
float hurtTime = entity.getHurtTime() - partialTick;
|
||||
float damage = entity.getDamage() - partialTick;
|
||||
|
@ -154,7 +154,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
}
|
||||
|
||||
if (hurtTime > 0) {
|
||||
stack.mulPose(Axes.XP.rotationDegrees(Mth.sin(hurtTime) * hurtTime * damage / 10.0F * (float) entity.getHurtDir()));
|
||||
stack.mulPose(Axis.XP.rotationDegrees(Mth.sin(hurtTime) * hurtTime * damage / 10.0F * (float) entity.getHurtDir()));
|
||||
}
|
||||
|
||||
int displayOffset = entity.getDisplayOffset();
|
||||
|
@ -162,7 +162,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
stack.pushPose();
|
||||
stack.scale(0.75F, 0.75F, 0.75F);
|
||||
stack.translate(-0.5D, (float) (displayOffset - 8) / 16, 0.5D);
|
||||
stack.mulPose(Axes.YP.rotationDegrees(90));
|
||||
stack.mulPose(Axis.YP.rotationDegrees(90));
|
||||
contents.setTransform(stack);
|
||||
stack.popPose();
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ import com.jozufozu.flywheel.lib.model.ModelCache;
|
|||
import com.jozufozu.flywheel.lib.model.SimpleModel;
|
||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
|
||||
import com.jozufozu.flywheel.lib.transform.TransformStack;
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
|
@ -59,11 +59,11 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
|||
|
||||
var rotation = getDirection().getRotation();
|
||||
|
||||
TransformStack tstack = TransformStack.cast(stack);
|
||||
TransformStack tstack = TransformStack.of(stack);
|
||||
tstack.translate(getVisualPosition())
|
||||
.translateAll(0.5)
|
||||
.translate(0.5)
|
||||
.scale(0.9995f)
|
||||
.multiply(rotation)
|
||||
.rotate(rotation)
|
||||
.scale(1, -1, -1)
|
||||
.translateY(-1);
|
||||
|
||||
|
@ -103,12 +103,12 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
|||
}
|
||||
lastProgress = progress;
|
||||
|
||||
Quaternionf spin = Axes.YP.rotationDegrees(270.0f * progress);
|
||||
Quaternionf spin = Axis.YP.rotationDegrees(270.0f * progress);
|
||||
|
||||
TransformStack.cast(stack)
|
||||
TransformStack.of(stack)
|
||||
.pushPose()
|
||||
.translateY(-progress * 0.5f)
|
||||
.multiply(spin);
|
||||
.rotate(spin);
|
||||
|
||||
lid.setTransform(stack);
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
|||
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
||||
import com.jozufozu.flywheel.lib.instance.InstanceTypes;
|
||||
import com.jozufozu.flywheel.lib.instance.TransformedInstance;
|
||||
import com.jozufozu.flywheel.lib.math.MoreMath;
|
||||
import com.jozufozu.flywheel.lib.model.Models;
|
||||
import com.jozufozu.flywheel.lib.task.ForEachPlan;
|
||||
|
||||
|
@ -89,9 +88,9 @@ public class ExampleEffect implements Effect {
|
|||
|
||||
Vec3 playerPos = player.position();
|
||||
|
||||
var x = (float) (playerPos.x + MoreMath.nextFloat(level.random, -20, 20));
|
||||
var y = (float) (playerPos.y + MoreMath.nextFloat(level.random, 0, 5));
|
||||
var z = (float) (playerPos.z + MoreMath.nextFloat(level.random, -20, 20));
|
||||
var x = (float) (playerPos.x + Mth.nextFloat(level.random, -20, 20));
|
||||
var y = (float) (playerPos.y + Mth.nextFloat(level.random, 0, 5));
|
||||
var z = (float) (playerPos.z + Mth.nextFloat(level.random, -20, 20));
|
||||
|
||||
ExampleEffect effect = new ExampleEffect(level, new Vector3f(x, y, z));
|
||||
ALL_EFFECTS.add(effect);
|
||||
|
@ -112,9 +111,9 @@ public class ExampleEffect implements Effect {
|
|||
this.boids = new ArrayList<>(VISUAL_COUNT);
|
||||
|
||||
for (int i = 0; i < VISUAL_COUNT; i++) {
|
||||
var x = targetPoint.x + MoreMath.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var y = targetPoint.y + MoreMath.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var z = targetPoint.z + MoreMath.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var x = targetPoint.x + Mth.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var y = targetPoint.y + Mth.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var z = targetPoint.z + Mth.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
|
||||
Boid boid = new Boid(x, y, z);
|
||||
boids.add(boid);
|
||||
|
|
|
@ -11,7 +11,7 @@ displayName = "Flywheel"
|
|||
logoFile = "logo.png"
|
||||
displayURL = "https://www.curseforge.com/minecraft/mc-mods/flywheel"
|
||||
updateJSONURL = "https://api.modrinth.com/updates/flywheel/forge_updates.json"
|
||||
authors = "Jozufozu"
|
||||
authors = "Jozufozu, PepperCode1"
|
||||
description = '''
|
||||
A modern engine for modded minecraft.'''
|
||||
|
||||
|
@ -28,3 +28,10 @@ mandatory = true
|
|||
versionRange = "[1.20.1,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
|
||||
[[dependencies.flywheel]]
|
||||
modId = "rubidium"
|
||||
mandatory = false
|
||||
versionRange = "[0.7.0,)"
|
||||
ordering = "NONE"
|
||||
side = "CLIENT"
|
||||
|
|
|
@ -16,4 +16,4 @@ void flw_instanceVertex(in FlwInstance i) {
|
|||
flw_vertexColor = i.color;
|
||||
flw_vertexLight = i.light / 15.0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
"GlStateManagerMixin",
|
||||
"LevelRendererMixin",
|
||||
"LightUpdateMixin",
|
||||
"PoseStackMixin",
|
||||
"RenderTypeMixin",
|
||||
"VertexFormatMixin",
|
||||
"fix.FixFabulousDepthMixin",
|
||||
"fix.FixNormalScalingMixin",
|
||||
"matrix.PoseStackMixin",
|
||||
"visualmanage.ChunkRebuildHooksMixin",
|
||||
"visualmanage.VisualAddMixin",
|
||||
"visualmanage.VisualRemoveMixin",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"refmap": "flywheel.refmap.json",
|
||||
"plugin": "com.jozufozu.flywheel.compat.SodiumMixinPlugin",
|
||||
"client": [
|
||||
"ChunkRenderRebuildTaskMixin"
|
||||
"ChunkBuilderMeshingTaskMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"pack": {
|
||||
"description": "Flywheel resources",
|
||||
"pack_format": 18
|
||||
"pack_format": 18
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue