Skip to content

Commit

Permalink
Make celestial notes check for IScribeTools on items instead of just …
Browse files Browse the repository at this point in the history
…the specific Thaumcraft item (#43)
  • Loading branch information
TheCodex6824 committed Sep 3, 2024
1 parent 3d352ea commit f4c20de
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void initTransformers() {
transformers.add(ResearchTransformers.PARSE_PAGE_FIRST_PASS.get());
transformers.add(ResearchTransformers.RESEARCH_GAIN_EVENT_CLIENT.get());
transformers.add(ResearchTransformers.RESEARCH_PATCHER.get());
transformers.add(ResearchTransformers.SCAN_SKY_SCRIBE_CHECK.get());
transformers.add(SoundTransformers.SOUND_FIX_FOCAL_MANIPULATOR_CONTAINER.get());
transformers.add(TheorycraftTransformers.CARD_ANALYZE_CATEGORIES.get());
transformers.add(TheorycraftTransformers.CARD_CURIO_CATEGORIES.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

import com.google.common.collect.Iterables;
import com.google.gson.JsonObject;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import thaumcraft.api.capabilities.IPlayerKnowledge.EnumKnowledgeType;
import thaumcraft.api.items.IScribeTools;
import thaumcraft.api.items.ItemsTC;
import thaumcraft.api.research.ResearchCategory;
import thaumcraft.api.research.ResearchEntry;
import thecodex6824.coremodlib.LocalVariableDefinition;
Expand Down Expand Up @@ -125,6 +129,20 @@ public static InputStream getFilesystemStream(InputStream stream, ResourceLocati
return stream;
}

public static boolean isPlayerCarryingScribingTools(ItemStack isCarrying, boolean ore, boolean original, EntityPlayer player) {
if (original || isCarrying.getItem() != ItemsTC.scribingTools) {
return original;
}

for (ItemStack stack : Iterables.concat(player.inventory.offHandInventory, player.inventory.mainInventory)) {
if (!stack.isEmpty() && stack.getItem() instanceof IScribeTools) {
return true;
}
}

return false;
}

}

private static final String HOOKS = Type.getInternalName(Hooks.class);
Expand Down Expand Up @@ -361,4 +379,38 @@ public static InputStream getFilesystemStream(InputStream stream, ResourceLocati
);
};

public static final Supplier<ITransformer> SCAN_SKY_SCRIBE_CHECK = () -> {
return new GenericStateMachineTransformer(
PatchStateMachine.builder(
new MethodDefinition(
"thaumcraft/common/lib/research/ScanSky",
false,
"onSuccess",
Type.VOID_TYPE,
Types.ENTITY_PLAYER, Types.OBJECT
)
)
.findNextMethodCall(new MethodDefinition(
"thaumcraft/common/lib/utils/InventoryUtils",
false,
"isPlayerCarryingAmount",
Type.BOOLEAN_TYPE,
Types.ENTITY_PLAYER, Types.ITEM_STACK, Type.BOOLEAN_TYPE
))
.insertInstructionsSurrounding()
.before(new InsnNode(Opcodes.DUP2_X1))
.after(
new VarInsnNode(Opcodes.ALOAD, 1),
new MethodInsnNode(Opcodes.INVOKESTATIC,
HOOKS,
"isPlayerCarryingScribingTools",
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Types.ITEM_STACK, Type.BOOLEAN_TYPE, Type.BOOLEAN_TYPE, Types.ENTITY_PLAYER),
false
)
)
.endAction()
.build() // needs to repeat multiple times
);
};

}

0 comments on commit f4c20de

Please sign in to comment.