Skip to content

Commit

Permalink
CTM mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
ALongStringOfNumbers committed Dec 13, 2023
1 parent accb431 commit 26fedc5
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 54 deletions.
10 changes: 4 additions & 6 deletions src/main/java/gregtech/asm/GregTechTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import gregtech.asm.util.ObfMapping;
import gregtech.asm.util.TargetClassVisitor;
import gregtech.asm.visitors.AbstractCTMBakedModelVisitor;
import gregtech.asm.visitors.EnchantmentCanApplyVisitor;
import gregtech.asm.visitors.JEIVisitor;
import gregtech.asm.visitors.LittleTilesVisitor;
import gregtech.asm.visitors.ModelCTMVisitor;

import net.minecraft.launchwrapper.IClassTransformer;

Expand Down Expand Up @@ -117,20 +115,20 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
* return classWriter.toByteArray();
* }
*/
case ModelCTMVisitor.TARGET_CLASS_NAME: {
/*case ModelCTMVisitor.TARGET_CLASS_NAME: {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classReader.accept(
new TargetClassVisitor(classWriter, ModelCTMVisitor.TARGET_METHOD, ModelCTMVisitor::new), 0);
return classWriter.toByteArray();
}
case AbstractCTMBakedModelVisitor.TARGET_CLASS_NAME: {
} */
/* case AbstractCTMBakedModelVisitor.TARGET_CLASS_NAME: {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classReader.accept(new TargetClassVisitor(classWriter, AbstractCTMBakedModelVisitor.TARGET_METHOD,
AbstractCTMBakedModelVisitor::new), 0);
return classWriter.toByteArray();
}
} */
case LittleTilesVisitor.TARGET_CLASS_NAME: {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/gregtech/mixins/ctm/AbstractCTMBakedModelMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gregtech.mixins.ctm;

import gregtech.asm.hooks.CTMHooks;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;

import com.llamalad7.mixinextras.sugar.Local;
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;
import team.chisel.ctm.client.model.AbstractCTMBakedModel;

import java.util.List;

//TODO, I don't think this works. Might need to wrap the return for the list of quads
@Mixin(AbstractCTMBakedModel.class)
public class AbstractCTMBakedModelMixin {

@Inject(method = "getQuads", at = @At(value = "TAIL"), remap = false)
public void getQuadsWithOptifine(IBlockState state, EnumFacing side, long rand,
CallbackInfoReturnable<List<BakedQuad>> cir, @Local BlockRenderLayer layer,
@Local Object ret) {
CTMHooks.getQuadsWithOptiFine((List<BakedQuad>) ret, layer, (IBakedModel) this, state, side, rand);
}
}
40 changes: 21 additions & 19 deletions src/main/java/gregtech/mixins/ctm/CTMRenderInLayerMixin.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package gregtech.mixins.ctm;

import gregtech.asm.hooks.CTMModHooks;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.util.BlockRenderLayer;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import team.chisel.ctm.client.asm.CTMCoreMethods;
import team.chisel.ctm.client.model.AbstractCTMBakedModel;

@Mixin(CTMCoreMethods.class)
public class CTMRenderInLayerMixin {

/*
* @ModifyExpressionValue(method = "canRenderInLayer", at = @At(value = "INVOKE_ASSIGN", target =
* "Lteam/chisel/ctm/api/model/IModelCTM;canRenderInLayer(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/util/BlockRenderLayer;)Z"
* ), remap = false)
* private static boolean renderInLayer(boolean originalResult, @Nonnull IBlockState state, @Nonnull
* BlockRenderLayer layer) {
*
* byte layers = ((ModelCTMLayersAccessor) ModelCTM.getInstance()).getLayers();
* if (model instanceof ModelCTM && layers != null) {
* try {
* return CTMHooks.checkLayerWithOptiFine(originalResult, layers.getByte(model), layer);
* } catch (Exception ignored) {
* layers = null;
* GTLog.logger.error("CTMModHooks Field error");
* }
* }
* return originalResult;
* }
*/
@ModifyExpressionValue(method = "canRenderInLayer",
at = @At(value = "INVOKE_ASSIGN",
target = "Lteam/chisel/ctm/api/model/IModelCTM;canRenderInLayer(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/util/BlockRenderLayer;)Z"
),
remap = false)
private static Boolean checkRenderInLayer(Boolean originalResult, @NotNull IBlockState state, @NotNull
BlockRenderLayer layer, @Local IBakedModel model) {
return CTMModHooks.canRenderInLayer(((AbstractCTMBakedModel) model).getModel(), state, layer);
}

}
12 changes: 0 additions & 12 deletions src/main/java/gregtech/mixins/ctm/ModelCTMLayersAccessor.java

This file was deleted.

39 changes: 24 additions & 15 deletions src/main/java/gregtech/mixins/jei/JEITooltipMixin.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
package gregtech.mixins.jei;

import gregtech.api.util.FluidTooltipUtil;

import net.minecraftforge.fluids.FluidStack;

import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.startup.ForgeModIdHelper;
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;

import java.util.List;

// TODO, Needs to apply to the fluid items in JEI
@Mixin(ForgeModIdHelper.class)
public class JEITooltipMixin {

/*
* @Inject(method = "addModNameToIngredientTooltip", at = @At("HEAD"), remap = false)
* public void addTooltip(List<String> tooltip, Object ingredient, IIngredientHelper<Object> ingredientHelper,
* CallbackInfoReturnable<List<String>> cir) {
* if (ingredient instanceof FluidStack) {
* List<String> formula = FluidTooltipUtil.getFluidTooltip((FluidStack) ingredient);
* if (formula != null) {
* for (String s : formula) {
* if (s.isEmpty()) continue;
* tooltip.add(s);
* }
* }
* }
* }
*/
@Inject(method = "addModNameToIngredientTooltip", at = @At("HEAD"), remap = false)
public void addTooltip(List<String> tooltip, Object ingredient, IIngredientHelper<Object> ingredientHelper,
CallbackInfoReturnable<List<String>> cir) {
if (ingredient instanceof FluidStack) {
List<String> formula = FluidTooltipUtil.getFluidTooltip((FluidStack) ingredient);
if (formula != null) {
for (String s : formula) {
if (s.isEmpty()) continue;
tooltip.add(s);
}
}
}
}

}
4 changes: 2 additions & 2 deletions src/main/resources/mixins.gregtech.ctm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"minVersion" : "0.8",
"compatibilityLevel" : "JAVA_8",
"mixins" : [
"CTMRenderInLayerMixin",
"ModelCTMLayersAccessor"
"AbstractCTMBakedModelMixin",
"CTMRenderInLayerMixin"
],
"client" : [],
"server" : []
Expand Down

0 comments on commit 26fedc5

Please sign in to comment.