Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Thermal Expansion support? #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions stanhebben/minetweaker/mods/te/actions/ThermalExpansionAction.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package stanhebben.minetweaker.mods.te.actions;

import java.lang.reflect.Method;
import java.util.logging.Level;

import net.minecraft.nbt.NBTTagCompound;
import stanhebben.minetweaker.api.IUndoableAction;
import stanhebben.minetweaker.api.Tweaker;

import com.google.common.collect.ImmutableList;

import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;

public class ThermalExpansionAction implements IUndoableAction {
private final String key;
Expand All @@ -18,6 +27,17 @@ public ThermalExpansionAction(String key, NBTTagCompound nbt, String description
@Override
public void apply() {
FMLInterModComms.sendMessage("ThermalExpansion", key, nbt);
// Do some hackery because IMCMessages need to be retrieved manually after they've
// been sent out automatically the first time between init and post-init events.
try {
Class imcHandlerClass = Class.forName("thermalexpansion.util.IMCHandler");
Method handleIMCMethod = imcHandlerClass.getMethod("handleIMC", IMCEvent.class);
Object imcHandlerInstance = imcHandlerClass.getField("instance").get(null);
handleIMCMethod.invoke(imcHandlerInstance, new CustumIMCEvent());
} catch (Exception e) {
Tweaker.log(Level.WARNING, "Error adding Thermal Expansion recipe.");
System.out.println(e);
}
}

@Override
Expand All @@ -39,4 +59,15 @@ public String describe() {
public String describeUndo() {
return "Removing a " + key + " for " + description;
}

private class CustumIMCEvent extends IMCEvent {
private ImmutableList<IMCMessage> messages;

@Override
public ImmutableList<IMCMessage> getMessages() {
if (messages == null)
messages = FMLInterModComms.fetchRuntimeMessages("ThermalExpansion");
return messages;
}
}
}