diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/BlockElementMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/BlockElementMixin.java index 81b8d7798..859267b1c 100644 --- a/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/BlockElementMixin.java +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/BlockElementMixin.java @@ -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 = "", - 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 = "", - 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; diff --git a/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/ModelBakeryMixin.java b/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/ModelBakeryMixin.java new file mode 100644 index 000000000..ff673b6c5 --- /dev/null +++ b/src/main/java/me/jellysquid/mods/sodium/mixin/features/model/ModelBakeryMixin.java @@ -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 cir) { + if(pLocation.getPath().startsWith("block/")) { + BlockModel bm = cir.getReturnValue(); + if(bm != null) { + for(BlockElement vanillaElement : bm.getElements()) { + ((EpsilonizableBlockElement)vanillaElement).embeddium$epsilonize(); + } + } + } + } +} diff --git a/src/main/java/org/embeddedt/embeddium/model/EpsilonizableBlockElement.java b/src/main/java/org/embeddedt/embeddium/model/EpsilonizableBlockElement.java new file mode 100644 index 000000000..f9590e668 --- /dev/null +++ b/src/main/java/org/embeddedt/embeddium/model/EpsilonizableBlockElement.java @@ -0,0 +1,5 @@ +package org.embeddedt.embeddium.model; + +public interface EpsilonizableBlockElement { + void embeddium$epsilonize(); +}