2018-02-28 21:06:33 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2018 malte0811
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-08-27 22:45:52 +02:00
|
|
|
package malte0811.industrialWires.compat;
|
|
|
|
|
|
|
|
import blusunrize.immersiveengineering.api.ApiUtils;
|
|
|
|
import blusunrize.immersiveengineering.api.tool.ToolboxHandler;
|
2018-05-14 18:51:42 +02:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
2017-08-27 22:45:52 +02:00
|
|
|
import crafttweaker.CraftTweakerAPI;
|
2018-05-14 18:51:42 +02:00
|
|
|
import ic2.api.energy.event.EnergyTileLoadEvent;
|
|
|
|
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
|
|
|
import ic2.api.energy.tile.IEnergyTile;
|
2017-08-27 22:45:52 +02:00
|
|
|
import ic2.api.item.IBoxable;
|
|
|
|
import ic2.api.item.IC2Items;
|
2018-05-14 18:51:42 +02:00
|
|
|
import malte0811.industrialWires.converter.MechPartCommutator;
|
2017-08-29 22:01:51 +02:00
|
|
|
import malte0811.industrialWires.hv.MarxOreHandler;
|
2017-08-27 22:45:52 +02:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-05-14 18:51:42 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.fml.common.Loader;
|
2017-08-27 22:45:52 +02:00
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
2018-05-14 18:51:42 +02:00
|
|
|
import java.util.Map;
|
2017-08-29 22:01:51 +02:00
|
|
|
import java.util.function.Consumer;
|
2017-08-27 22:45:52 +02:00
|
|
|
|
|
|
|
public class Compat {
|
2018-05-14 18:51:42 +02:00
|
|
|
static Consumer<MarxOreHandler.OreInfo> addMarx = (o) -> {
|
|
|
|
};
|
|
|
|
static Consumer<MarxOreHandler.OreInfo> removeMarx = (o) -> {
|
|
|
|
};
|
|
|
|
public static Consumer<TileEntity> loadIC2Tile = te -> {
|
|
|
|
};
|
|
|
|
public static Consumer<TileEntity> unloadIC2Tile = te -> {
|
|
|
|
};
|
|
|
|
private static Map<String, Class<? extends CompatModule>> modules = ImmutableMap.of("ic2", CompatIC2.class,
|
|
|
|
"crafttweaker", CompatCT.class);
|
2017-08-27 22:45:52 +02:00
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
private static Method preInit;
|
|
|
|
private static Method init;
|
|
|
|
|
|
|
|
static {
|
|
|
|
try {
|
|
|
|
preInit = CompatModule.class.getMethod("preInit");
|
|
|
|
CompatModule.class.getMethod("init");
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2017-08-29 21:31:22 +02:00
|
|
|
}
|
2018-05-14 18:51:42 +02:00
|
|
|
|
|
|
|
public static void preInit() {
|
|
|
|
for (Map.Entry<String, Class<? extends CompatModule>> e:modules.entrySet()) {
|
|
|
|
if (Loader.isModLoaded(e.getKey())) {
|
|
|
|
try {
|
|
|
|
preInit.invoke(e.getValue().newInstance());
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-29 21:31:22 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
public static void init() {
|
|
|
|
for (Map.Entry<String, Class<? extends CompatModule>> e:modules.entrySet()) {
|
|
|
|
if (Loader.isModLoaded(e.getKey())) {
|
2017-08-27 22:45:52 +02:00
|
|
|
try {
|
2018-05-14 18:51:42 +02:00
|
|
|
init.invoke(e.getValue().newInstance());
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e1) {
|
|
|
|
e1.printStackTrace();
|
2017-08-27 22:45:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
static abstract class CompatModule {
|
|
|
|
public void preInit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class CompatCT extends CompatModule {
|
|
|
|
@Override
|
|
|
|
public void preInit() {
|
2017-08-29 21:31:22 +02:00
|
|
|
CraftTweakerAPI.registerClass(CTMarxGenerator.class);
|
|
|
|
}
|
2017-08-27 22:45:52 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
private static class CompatIC2 extends CompatModule {
|
|
|
|
public void init() {
|
2017-08-29 21:31:22 +02:00
|
|
|
Item tinnedFood = IC2Items.getItem("filled_tin_can").getItem();
|
|
|
|
ItemStack emptyMug = IC2Items.getItem("mug", "empty");
|
|
|
|
ToolboxHandler.addFoodType((s) -> s.getItem() == tinnedFood);
|
|
|
|
ToolboxHandler.addFoodType((s) ->
|
|
|
|
s.getItem() == emptyMug.getItem() && !ItemStack.areItemStacksEqual(emptyMug, ApiUtils.copyStackWithAmount(s, 1))
|
|
|
|
);
|
|
|
|
Item cable = IC2Items.getItem("cable", "type:copper,insulation:0").getItem();
|
|
|
|
ToolboxHandler.addWiringType((s, w) -> s.getItem() == cable);
|
|
|
|
ToolboxHandler.addToolType((s) -> {
|
|
|
|
Item a = s.getItem();
|
|
|
|
return a instanceof IBoxable && ((IBoxable) a).canBeStoredInToolbox(s);
|
|
|
|
});
|
2018-05-14 18:51:42 +02:00
|
|
|
MechPartCommutator.originalStack = IC2Items.getItem("te", "kinetic_generator");
|
|
|
|
loadIC2Tile = (te) -> MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) te));
|
|
|
|
unloadIC2Tile = (te) -> MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) te));
|
2017-08-29 21:31:22 +02:00
|
|
|
}
|
2017-08-27 22:45:52 +02:00
|
|
|
}
|
2017-08-29 21:31:22 +02:00
|
|
|
}
|