Skip to content

Commit

Permalink
Fix collector enchantment and others having dupe issues with block dr…
Browse files Browse the repository at this point in the history
…ops (#3)
  • Loading branch information
TheCodex6824 committed Jun 27, 2024
1 parent 5cf8d22 commit aada89f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private void initTransformers() {
transformers.add(EntityTransformers.OWNED_CONSTRUCT_ZERO_DROP_CHANCES.get());
transformers.add(ItemTransformers.COMPARE_TAGS_RELAXED_NULL_CHECK.get());
transformers.add(ItemTransformers.FOCUS_COLOR_NBT.get());
transformers.add(ItemTransformers.INFUSION_ENCHANTMENT_DROPS_PRIORITY.get());
transformers.add(ItemTransformers.PRIMORDIAL_PEARL_ANVIL_DUPE_DURABILITY_BAR.get());
transformers.add(ItemTransformers.PRIMORDIAL_PEARL_ANVIL_DUPE_EVENT.get());
transformers.add(ItemTransformers.PRIMORDIAL_PEARL_ANVIL_DUPE_PROPS.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.objectweb.asm.tree.VarInsnNode;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import baubles.api.cap.BaublesCapabilities;
import it.unimi.dsi.fastutil.ints.IntRBTreeSet;
Expand All @@ -50,6 +51,7 @@
import thaumcraft.common.items.casters.ItemFocus;
import thecodex6824.coremodlib.MethodDefinition;
import thecodex6824.coremodlib.PatchStateMachine;
import thecodex6824.thaumcraftfix.core.transformer.custom.ChangeEventPriorityTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.PrimordialPearlAnvilEventTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.PrimordialPearlDurabilityBarTransformer;
import thecodex6824.thaumcraftfix.core.transformer.custom.ThrowingTransformerWrapper;
Expand Down Expand Up @@ -211,6 +213,15 @@ public static void fixPrimordialPearlItem(Item pearl) {
);
};

public static final Supplier<ITransformer> INFUSION_ENCHANTMENT_DROPS_PRIORITY = () -> {
return new ChangeEventPriorityTransformer(Types.TOOL_EVENTS, ImmutableMap.of(
new MethodDefinition(Types.TOOL_EVENTS.getInternalName(), false, "harvestBlockEvent",
Type.VOID_TYPE, Type.getType("Lnet/minecraftforge/event/world/BlockEvent$HarvestDropsEvent;")), "LOWEST",
new MethodDefinition(Types.TOOL_EVENTS.getInternalName(), false, "livingDrops",
Type.VOID_TYPE, Type.getType("Lnet/minecraftforge/event/entity/living/LivingDropsEvent;")), "LOWEST"
));
};

public static final Supplier<ITransformer> PRIMORDIAL_PEARL_ANVIL_DUPE_DURABILITY_BAR = () -> new ThrowingTransformerWrapper(
new PrimordialPearlDurabilityBarTransformer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ private Types() {}
public static final Type I_CASTER = Type.getType("Lthaumcraft/api/casters/ICaster;");
public static final Type ITEM_CASTER = Type.getType("Lthaumcraft/common/items/casters/ItemCaster;");

public static final Type TOOL_EVENTS = Type.getType("Lthaumcraft/common/lib/events/ToolEvents;");

public static final Type TILE_FOCAL_MANIPULATOR = Type.getType("Lthaumcraft/common/tiles/crafting/TileFocalManipulator;");

public static final Type SOUND_EVENT = Type.getType("Lnet/minecraft/util/SoundEvent;");

public static final Type RESEARCH_TABLE_DATA = Type.getType("Lthaumcraft/api/research/theorycraft/ResearchTableData;");

public static final Type SUBSCRIBE_EVENT = Type.getType("Lnet/minecraftforge/fml/common/eventhandler/SubscribeEvent;");
public static final Type EVENT_PRIORITY = Type.getType("Lnet/minecraftforge/fml/common/eventhandler/EventPriority;");

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package thecodex6824.thaumcraftfix.core.transformer.custom;

import java.util.ArrayList;
import java.util.Map;

import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

import com.google.common.collect.ImmutableMap;

import thecodex6824.coremodlib.MethodDefinition;
import thecodex6824.thaumcraftfix.core.transformer.ITransformer;
import thecodex6824.thaumcraftfix.core.transformer.TransformUtil;
import thecodex6824.thaumcraftfix.core.transformer.Types;

public class ChangeEventPriorityTransformer implements ITransformer {

private String internalNameWithDots;
private Map<MethodDefinition, String> priorities;

public ChangeEventPriorityTransformer(Type owner, Map<MethodDefinition, String> newPriorities) {
internalNameWithDots = owner.getInternalName().replace('/', '.');
priorities = ImmutableMap.copyOf(newPriorities);
}

@Override
public boolean isTransformationNeeded(String transformedName) {
return internalNameWithDots.equals(transformedName);
}

@Override
public boolean transform(ClassNode classNode, String name, String transformedName) {
boolean allFound = true;
for (Map.Entry<MethodDefinition, String> entry : priorities.entrySet()) {
MethodNode method = TransformUtil.findMethod(classNode, entry.getKey());
if (method != null) {
boolean found = false;
for (AnnotationNode annotation : method.visibleAnnotations) {
if (annotation.desc.equals(Types.SUBSCRIBE_EVENT.getDescriptor())) {
int priorityIndex = -1;
if (annotation.values == null) {
annotation.values = new ArrayList<Object>();
}
else {
priorityIndex = annotation.values.indexOf("priority");
}

String[] priorityValue = new String[] {
Types.EVENT_PRIORITY.getDescriptor(),
entry.getValue()
};
if (priorityIndex != -1) {
annotation.values.set(priorityIndex + 1, priorityValue);
}
else {
annotation.values.add("priority");
annotation.values.add(priorityValue);
}
found = true;
break;
}
}

allFound &= found;
}
else {
allFound = false;
}
}

return allFound;
}

}

0 comments on commit aada89f

Please sign in to comment.