forked from Sk1erLLC/Patcher
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ev chang <[email protected]>
- Loading branch information
1 parent
58ac567
commit 397b146
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/club/sk1er/patcher/hooks/TRSRTransformationHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package club.sk1er.patcher.hooks; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
|
||
import net.minecraft.client.renderer.block.model.ItemTransformVec3f; | ||
import net.minecraft.client.resources.model.ModelRotation; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraftforge.client.ForgeHooksClient; | ||
import net.minecraftforge.client.model.TRSRTransformation; | ||
|
||
import static net.minecraftforge.client.model.TRSRTransformation.identity; | ||
|
||
public class TRSRTransformationHook { | ||
@SuppressWarnings("deprecation") | ||
public static TRSRTransformation from(ItemTransformVec3f transform) { | ||
return transform.equals(ItemTransformVec3f.DEFAULT) ? identity() : new TRSRTransformation(transform); | ||
} | ||
|
||
public static TRSRTransformation from(ModelRotation rotation) { | ||
return Cache.get(rotation); | ||
} | ||
|
||
public static TRSRTransformation from(EnumFacing facing) { | ||
return Cache.get(getRotation(facing)); | ||
} | ||
|
||
public static ModelRotation getRotation(EnumFacing facing) { | ||
switch (facing) { | ||
case DOWN: return ModelRotation.X90_Y0; | ||
case UP: return ModelRotation.X270_Y0; | ||
case NORTH: return ModelRotation.X0_Y0; | ||
case SOUTH: return ModelRotation.X0_Y180; | ||
case WEST: return ModelRotation.X0_Y270; | ||
case EAST: return ModelRotation.X0_Y90; | ||
} | ||
throw new IllegalArgumentException(String.valueOf(facing)); | ||
} | ||
|
||
private static final class Cache { | ||
private static final Map<ModelRotation, TRSRTransformation> rotations = new EnumMap<>(ModelRotation.class); | ||
|
||
static { | ||
rotations.put(ModelRotation.X0_Y0, identity()); | ||
} | ||
|
||
static TRSRTransformation get(ModelRotation rotation) { | ||
return rotations.computeIfAbsent(rotation, r -> new TRSRTransformation(ForgeHooksClient.getMatrix(r))); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...lub/sk1er/patcher/mixins/performance/forge/ForgeBlockStateV1Mixin_OptimizeTransforms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package club.sk1er.patcher.mixins.performance.forge; | ||
|
||
import club.sk1er.patcher.hooks.TRSRTransformationHook; | ||
import net.minecraft.client.resources.model.ModelRotation; | ||
import net.minecraftforge.client.model.ForgeBlockStateV1; | ||
import net.minecraftforge.client.model.TRSRTransformation; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(value = ForgeBlockStateV1.Variant.Deserializer.class, remap = false) | ||
public class ForgeBlockStateV1Mixin_OptimizeTransforms { | ||
//#if MC==10809 | ||
@Redirect(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraftforge/client/model/ForgeBlockStateV1$Variant;", at = @At(value = "NEW", target = "net/minecraftforge/client/model/TRSRTransformation")) | ||
private TRSRTransformation patcher$from(ModelRotation rotation) { | ||
return TRSRTransformationHook.from(rotation); | ||
} | ||
//#endif | ||
} |
20 changes: 20 additions & 0 deletions
20
...club/sk1er/patcher/mixins/performance/forge/ForgeHooksClientMixin_OptimizeTransforms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package club.sk1er.patcher.mixins.performance.forge; | ||
|
||
import club.sk1er.patcher.hooks.TRSRTransformationHook; | ||
import net.minecraft.client.renderer.block.model.ItemTransformVec3f; | ||
import net.minecraftforge.client.ForgeHooksClient; | ||
import net.minecraftforge.client.model.TRSRTransformation; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(value = ForgeHooksClient.class, remap = false) | ||
public abstract class ForgeHooksClientMixin_OptimizeTransforms { | ||
//#if MC==10809 | ||
@SuppressWarnings("deprecation") | ||
@Redirect(method = "applyTransform(Lnet/minecraft/client/renderer/block/model/ItemTransformVec3f;Lcom/google/common/base/Optional;)Lcom/google/common/base/Optional;", at = @At(value = "NEW", target = "net/minecraftforge/client/model/TRSRTransformation")) | ||
private static TRSRTransformation patcher$from(ItemTransformVec3f transform) { | ||
return TRSRTransformationHook.from(transform); | ||
} | ||
//#endif | ||
} |
42 changes: 42 additions & 0 deletions
42
...ub/sk1er/patcher/mixins/performance/forge/TRSRTransformationMixin_OptimizeTransforms.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package club.sk1er.patcher.mixins.performance.forge; | ||
|
||
import net.minecraftforge.client.model.TRSRTransformation; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(value = TRSRTransformation.class, remap = false) | ||
public class TRSRTransformationMixin_OptimizeTransforms { | ||
//#if MC==10809 | ||
@Shadow | ||
@Final | ||
private static TRSRTransformation identity; | ||
|
||
@Inject(method = "compose", at = @At("HEAD"), cancellable = true) | ||
private void patcher$earlyExitCompose(TRSRTransformation b, CallbackInfoReturnable<TRSRTransformation> cir) { | ||
TRSRTransformation thiz = (TRSRTransformation) (Object) this; | ||
if (thiz == identity) { | ||
cir.setReturnValue(b); | ||
} else if (b == identity) { | ||
cir.setReturnValue(thiz); | ||
} | ||
} | ||
|
||
@Inject(method = "blockCenterToCorner", at = @At("HEAD"), cancellable = true) | ||
private static void patcher$earlyExitBlockCenter(TRSRTransformation transform, CallbackInfoReturnable<TRSRTransformation> cir) { | ||
if (transform == identity) { | ||
cir.setReturnValue(transform); | ||
} | ||
} | ||
|
||
@Inject(method = "blockCornerToCenter", at = @At("HEAD"), cancellable = true) | ||
private static void patcher$earlyExitBlockCorner(TRSRTransformation transform, CallbackInfoReturnable<TRSRTransformation> cir) { | ||
if (transform == identity) { | ||
cir.setReturnValue(transform); | ||
} | ||
} | ||
//#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters