Clean up ic2 support

This commit is contained in:
modmuss50 2018-12-08 20:48:21 +00:00
parent 7db621fbed
commit bb5a3e2647
14 changed files with 116 additions and 110 deletions

View file

@ -32,10 +32,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ModFixs;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.common.event.*;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -51,6 +48,7 @@ import reborncore.common.multiblock.MultiblockServerTickHandler;
import reborncore.common.network.RegisterPacketEvent;
import reborncore.common.util.LogHelper;
import reborncore.common.util.Torus;
import techreborn.utils.UnspportedIc2Exception;
import techreborn.api.TechRebornAPI;
import techreborn.blocks.cable.EnumCableType;
import techreborn.client.GuiHandler;
@ -120,11 +118,14 @@ public class Core {
ModFixs dataFixes = FMLCommonHandler.instance().getDataFixer().init(ModInfo.MOD_ID, 1);
ModTileEntities.initDataFixer(dataFixes);
CompatManager.isIC2Loaded = Loader.isModLoaded("ic2");
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.preInit(event);
}
if(TechRebornAPI.ic2Helper == null && Loader.isModLoaded("ic2")){
throw new UnspportedIc2Exception();
}
//Ore Dictionary
OreDict.init();
proxy.preInit(event);

View file

@ -0,0 +1,18 @@
package techreborn.api;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.List;
public interface IC2Helper {
public void initDuplicates();
public boolean extractSap(EntityPlayer player, World world, BlockPos pos, EnumFacing side, IBlockState state, List<ItemStack> stacks);
}

View file

@ -39,6 +39,8 @@ public final class TechRebornAPI {
public static ISubItemRetriever subItemRetriever;
public static IC2Helper ic2Helper;
public static void addRollingOreMachinceRecipe(ResourceLocation resourceLocation, ItemStack output, Object... components) {
RollingMachineRecipe.instance.addShapedOreRecipe(resourceLocation, output, components);
}

View file

@ -38,12 +38,10 @@ import java.util.ArrayList;
public class CompatManager {
public static CompatManager INSTANCE = new CompatManager();
public static boolean isIC2Loaded = false;
public static boolean isQuantumStorageLoaded = false;
public ArrayList<ICompatModule> compatModules = new ArrayList<>();
public CompatManager() {
isIC2Loaded = Loader.isModLoaded("ic2");
isQuantumStorageLoaded = Loader.isModLoaded("quantumstorage");
}

View file

@ -22,7 +22,7 @@
* SOFTWARE.
*/
package techreborn.init;
package techreborn.compat.ic2;
import ic2.core.block.BlockIC2Fence;
import ic2.core.block.BlockTexGlass;
@ -40,6 +40,7 @@ import reborncore.api.recipe.RecipeHandler;
import reborncore.common.util.OreUtil;
import techreborn.Core;
import techreborn.api.recipe.machines.ExtractorRecipe;
import techreborn.init.IC2Duplicates;
import techreborn.items.ingredients.ItemParts;
/**
@ -47,7 +48,6 @@ import techreborn.items.ingredients.ItemParts;
*/
public class IC2Dict {
//TODO IC2
public static void init() {
IC2Duplicates.GRINDER.setIc2Stack(BlockName.te.getItemStack(TeBlock.macerator.getName()));

View file

@ -25,9 +25,15 @@
package techreborn.compat.ic2;
import ic2.api.item.IC2Items;
import ic2.core.item.tool.ItemTreetap;
import ic2.core.ref.ItemName;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@ -36,12 +42,16 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import reborncore.api.recipe.RecipeHandler;
import reborncore.common.registration.RebornRegistry;
import reborncore.common.util.RebornCraftingHelper;
import techreborn.api.IC2Helper;
import techreborn.api.TechRebornAPI;
import techreborn.api.recipe.machines.ChemicalReactorRecipe;
import techreborn.api.recipe.machines.CompressorRecipe;
import techreborn.api.recipe.machines.ExtractorRecipe;
import techreborn.api.recipe.machines.GrinderRecipe;
import techreborn.compat.ICompatModule;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.init.recipes.ChemicalReactorRecipes;
import techreborn.init.recipes.RecipeMethods;
import techreborn.items.ingredients.ItemParts;
import techreborn.lib.ModInfo;
@ -52,14 +62,15 @@ import java.util.List;
/**
* Created by Mark on 06/06/2016.
*/
@RebornRegistry(modOnly = "ic2", modID = ModInfo.MOD_ID)
public class RecipesIC2 implements ICompatModule {
@RebornRegistry(modOnly = "ic2,!ic2-classic-spmod", modID = ModInfo.MOD_ID)
public class IC2Module implements ICompatModule, IC2Helper {
List<RecipeDuplicate> recipeDuplicateList = new ArrayList<>();
@Override
public void preInit(FMLPreInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
TechRebornAPI.ic2Helper = this;
}
// LOW is used as we want it to tick as late as possible, but before crafttweaker
@ -89,6 +100,19 @@ public class RecipesIC2 implements ICompatModule {
RecipeHandler.addRecipe(new ExtractorRecipe(ItemName.filled_tin_can.getItemStack(),
ItemName.crafting.getItemStack("tin_can"), 300, 16));
ItemStack f = IC2Items.getItem("crop_res", "fertilizer");
ChemicalReactorRecipes.register(RecipeMethods.getMaterial("calcite", RecipeMethods.Type.DUST), RecipeMethods.getMaterial("sulfur", RecipeMethods.Type.DUST), f, 40);
}
@Override
public void initDuplicates() {
IC2Dict.init();
}
@Override
public boolean extractSap(EntityPlayer player, World world, BlockPos pos, EnumFacing side, IBlockState state, List<ItemStack> stacks) {
return ItemTreetap.attemptExtract(player, world, pos, side, state, null);
}
public class RecipeDuplicate {

View file

@ -25,6 +25,7 @@
package techreborn.init;
import net.minecraft.item.ItemStack;
import techreborn.api.TechRebornAPI;
import techreborn.blocks.cable.EnumCableType;
import techreborn.compat.CompatManager;
import techreborn.config.ConfigTechReborn;
@ -82,15 +83,15 @@ public enum IC2Duplicates {
}
public static boolean deduplicate() {
if (!CompatManager.isIC2Loaded) {
if (TechRebornAPI.ic2Helper == null) {
return false;
}
return ConfigTechReborn.REMOVE_DUPLICATES;
}
public ItemStack getIc2Stack() {
if (!CompatManager.isIC2Loaded) {
throw new RuntimeException("IC2 isnt loaded");
if (TechRebornAPI.ic2Helper == null) {
throw new RuntimeException("IC2 API isnt populated");
}
if (ic2Stack.isEmpty()) {
throw new RuntimeException("IC2 stack wasnt set ");

View file

@ -29,9 +29,8 @@ import com.google.common.collect.ImmutableList;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Loader;
import reborncore.common.util.OreUtil;
import techreborn.Core;
import techreborn.api.TechRebornAPI;
import techreborn.blocks.BlockMachineFrames;
import techreborn.blocks.cable.BlockCable;
import techreborn.items.ingredients.ItemDusts;
@ -52,9 +51,8 @@ public class OreDict {
);
public static void init() {
if (Loader.isModLoaded("ic2")) {
Core.logHelper.info("IC2 installed, enabling integration");
IC2Dict.init();
if(TechRebornAPI.ic2Helper != null){
TechRebornAPI.ic2Helper.initDuplicates();
}
OreUtil.registerOre("reBattery", ModItems.RE_BATTERY);

View file

@ -24,7 +24,6 @@
package techreborn.init.recipes;
import ic2.api.item.IC2Items;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@ -57,21 +56,14 @@ public class ChemicalReactorRecipes extends RecipeMethods {
register(getMaterial("compressedair", Type.CELL), getMaterial("hydrogen", 2, Type.CELL), getMaterial("water", Type.CELL), 400);
register(getMaterial("compressedair", 2, Type.CELL), getMaterial("nitrogen", Type.CELL), getMaterial("nitrogenDioxide", Type.CELL), 400);
register(getMaterial("oil", Type.CELL), getMaterial("nitrogen", Type.CELL), getMaterial("nitrofuel", 2, Type.CELL), 800);
//Dusts
if (techreborn.compat.CompatManager.isIC2Loaded){
ItemStack f = IC2Items.getItem("crop_res", "fertilizer");
register(getMaterial("calcite", Type.DUST), getMaterial("sulfur", Type.DUST), f, 40);
//There is no recipe for phosphorous yet.
//register(getMaterial("calcite", Type.DUST), getMaterial("phosphorous", Type.DUST), f, 40);
}
}
static void register(ItemStack in1, ItemStack in2, ItemStack out, int tickTime, int euPerTick){
public static void register(ItemStack in1, ItemStack in2, ItemStack out, int tickTime, int euPerTick){
RecipeHandler.addRecipe(new ChemicalReactorRecipe(in1, in2, out, tickTime, euPerTick));
}
static void register (ItemStack in1, ItemStack in2, ItemStack out, int tickTime){
public static void register (ItemStack in1, ItemStack in2, ItemStack out, int tickTime){
register(in1, in2, out, tickTime, 30);
}

View file

@ -24,7 +24,6 @@
package techreborn.items.tools;
import ic2.core.item.tool.ItemTreetap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
@ -47,7 +46,7 @@ import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.PoweredItemContainerProvider;
import reborncore.common.powerSystem.forge.ForgePowerItemManager;
import reborncore.common.util.ItemUtils;
import techreborn.compat.CompatManager;
import techreborn.api.TechRebornAPI;
import techreborn.init.ModItems;
import techreborn.items.ItemTR;
@ -73,11 +72,12 @@ public class ItemElectricTreetap extends ItemTR implements IEnergyItemInfo {
IBlockState state = worldIn.getBlockState(pos);
Block block = state.getBlock();
IEnergyStorage capEnergy = playerIn.getHeldItem(hand).getCapability(CapabilityEnergy.ENERGY, null);
if (CompatManager.isIC2Loaded && block == Block.getBlockFromName("ic2:rubber_wood") && capEnergy.getEnergyStored() >= cost)
if (ItemTreetap.attemptExtract(playerIn, worldIn, pos, side, state, null) && !worldIn.isRemote) {
if(TechRebornAPI.ic2Helper != null && capEnergy.getEnergyStored() >= cost){
if(TechRebornAPI.ic2Helper.extractSap(playerIn, worldIn, pos, side, state, null) && !worldIn.isRemote){
capEnergy.extractEnergy(cost, false);
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}

View file

@ -24,7 +24,6 @@
package techreborn.items.tools;
import ic2.core.item.tool.ItemTreetap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@ -35,7 +34,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import techreborn.compat.CompatManager;
import techreborn.api.TechRebornAPI;
import techreborn.events.TRRecipeHandler;
import techreborn.items.ItemTR;
@ -51,15 +50,16 @@ public class ItemTreeTap extends ItemTR {
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
IBlockState state = worldIn.getBlockState(pos);
Block block = state.getBlock();
if (CompatManager.isIC2Loaded && block == Block.getBlockFromName("ic2:rubber_wood")) {
ItemTreetap.attemptExtract(playerIn, worldIn, pos, side, state, null);
if (!worldIn.isRemote) {
playerIn.getHeldItem(hand).damageItem(1, playerIn);
if(TechRebornAPI.ic2Helper != null){
if(TechRebornAPI.ic2Helper.extractSap(playerIn, worldIn, pos, side, state, null)){
if (!worldIn.isRemote) {
playerIn.getHeldItem(hand).damageItem(1, playerIn);
}
if (playerIn instanceof EntityPlayerMP) {
TRRecipeHandler.unlockTRRecipes((EntityPlayerMP) playerIn);
}
return EnumActionResult.SUCCESS;
}
if (playerIn instanceof EntityPlayerMP) {
TRRecipeHandler.unlockTRRecipes((EntityPlayerMP) playerIn);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}

View file

@ -39,7 +39,6 @@ import reborncore.api.IToolHandler;
import reborncore.common.util.RebornPermissions;
import techreborn.compat.CompatManager;
import techreborn.items.ItemTR;
import techreborn.utils.IC2WrenchHelper;
/**
* Created by modmuss50 on 26/02/2016.
@ -57,12 +56,6 @@ public class ItemWrench extends ItemTR implements IToolHandler {
if (!world.isRemote && !PermissionAPI.hasPermission(player.getGameProfile(), RebornPermissions.WRENCH_BLOCK, new BlockPosContext(player, pos, world.getBlockState(pos), facing))) {
return EnumActionResult.PASS;
}
if (CompatManager.isIC2Loaded) {
EnumActionResult result = IC2WrenchHelper.onItemUse(player.getHeldItem(hand), player, world, pos, hand, facing, hitX, hitY, hitZ);
if (result == EnumActionResult.SUCCESS) {
return result;
}
}
return EnumActionResult.PASS;
}

View file

@ -1,58 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
//import ic2.core.item.tool.ItemToolWrench;
//TODO IC2
public class IC2WrenchHelper {
//static ItemToolWrench wrench;
public static EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos,
EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
// if (wrench == null) {
// wrench = (ItemToolWrench) IC2Items.getItem("wrench").getItem();
// }
// return wrench.onItemUseFirst(stack, player, world, pos, side, hitX, hitY, hitZ, hand);
return EnumActionResult.FAIL;
}
public static EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
// if (wrench == null) {
// wrench = (ItemToolWrench) IC2Items.getItem("wrench").getItem();
// }
// return wrench.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
return EnumActionResult.FAIL;
}
}

View file

@ -0,0 +1,37 @@
package techreborn.utils;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiErrorScreen;
import net.minecraftforge.fml.client.CustomModLoadingErrorDisplayException;
import net.minecraftforge.fml.client.IDisplayableError;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.awt.*;
public class UnspportedIc2Exception extends CustomModLoadingErrorDisplayException implements IDisplayableError {
@Override
public String getMessage() {
return "IC2 is installed, but no supported helper was setup";
}
@SideOnly(Side.CLIENT)
@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
}
@SideOnly(Side.CLIENT)
@Override
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
errorScreen.drawCenteredString(fontRenderer, "IC2 is installed, but no supported helper was setup", errorScreen.width / 2, 10, Color.RED.getRGB());
errorScreen.drawCenteredString(fontRenderer, "This can happen due to unoffical versions of ic2.", errorScreen.width / 2, 50, 0xEEEEEE);
errorScreen.drawCenteredString(fontRenderer, "If you are using offical ic2 please open an issue @ https://github.com/TechReborn/TechReborn/issues", errorScreen.width / 2, 60, 0xEEEEEE);
if(Loader.isModLoaded("ic2-classic-spmod")){
errorScreen.drawCenteredString(fontRenderer, "If you are using IC2 Classic please contact the mod author and ask for compatbility to be fixed", errorScreen.width / 2, 100, Color.GREEN.getRGB());
}
}
}