Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/20.1/forge' into 19.2/forge
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed May 1, 2024
2 parents 6c8f76c + 7b59de8 commit d9542fc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,39 @@
import com.mojang.math.Vector3f;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import net.minecraft.client.renderer.block.model.BlockElement;
import org.embeddedt.embeddium.model.EpsilonizableBlockElement;
import org.embeddedt.embeddium.util.PlatformUtil;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BlockElement.class)
public class BlockElementMixin {
@ModifyVariable(method = "<init>",
at = @At("HEAD"), argsOnly = true, index = 1)
private static Vector3f epsilonizeFrom(Vector3f vector) {
return embeddium$epsilonize(vector);
}
public class BlockElementMixin implements EpsilonizableBlockElement {
@Shadow
@Final
public Vector3f from;
@Shadow
@Final
public Vector3f to;

@ModifyVariable(method = "<init>",
at = @At("HEAD"), argsOnly = true, index = 2)
private static Vector3f epsilonizeTo(Vector3f vector) {
return embeddium$epsilonize(vector);
}
private boolean embeddium$hasEpsilonized;

private static Vector3f embeddium$epsilonize(Vector3f v) {
if (v == null || !PlatformUtil.isLoadValid() || !SodiumClientMod.options().performance.useCompactVertexFormat) {
return v;
@Override
public synchronized void embeddium$epsilonize() {
if(!embeddium$hasEpsilonized) {
embeddium$hasEpsilonized = true;
if (!PlatformUtil.isLoadValid() || !SodiumClientMod.options().performance.useCompactVertexFormat) {
return;
}
embeddium$epsilonize(from);
embeddium$epsilonize(to);
}
}

private static void embeddium$epsilonize(Vector3f v) {
v.setX(embeddium$epsilonize(v.x()));
v.setY(embeddium$epsilonize(v.y()));
v.setZ(embeddium$epsilonize(v.z()));
return v;
}

private static final float EMBEDDIUM$MINIMUM_EPSILON = 0.008f;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.jellysquid.mods.sodium.mixin.features.model;

import net.minecraft.client.renderer.block.model.BlockElement;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.resources.ResourceLocation;
import org.embeddedt.embeddium.model.EpsilonizableBlockElement;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ModelBakery.class)
public class ModelBakeryMixin {
@Inject(method = "loadBlockModel", at = @At("RETURN"))
private void epsilonizeBlockModel(ResourceLocation pLocation, CallbackInfoReturnable<BlockModel> cir) {
if(pLocation.getPath().startsWith("block/")) {
BlockModel bm = cir.getReturnValue();
if(bm != null) {
for(BlockElement vanillaElement : bm.getElements()) {
((EpsilonizableBlockElement)vanillaElement).embeddium$epsilonize();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.embeddedt.embeddium.model;

public interface EpsilonizableBlockElement {
void embeddium$epsilonize();
}

0 comments on commit d9542fc

Please sign in to comment.