General porting stuffs
This commit is contained in:
parent
edfeca8a94
commit
d62e1bbf6c
8 changed files with 143 additions and 377 deletions
|
|
@ -5,10 +5,8 @@ import com.oitsjustjose.tinkers_addons.lib.Lib;
|
|||
import com.oitsjustjose.tinkers_addons.lib.LibItems;
|
||||
import com.oitsjustjose.tinkers_addons.lib.LibModifiers;
|
||||
import com.oitsjustjose.tinkers_addons.modifiers.ModAutoRepair;
|
||||
import com.oitsjustjose.tinkers_addons.util.ClientProxy;
|
||||
import com.oitsjustjose.tinkers_addons.util.CommonProxy;
|
||||
import com.oitsjustjose.tinkers_addons.util.Recipes;
|
||||
|
||||
import com.oitsjustjose.tinkers_addons.util.ClientRegistry;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
|
|
@ -24,37 +22,22 @@ public class TinkersAddons
|
|||
@Instance(Lib.MODID)
|
||||
public static TinkersAddons instance;
|
||||
|
||||
@SidedProxy(clientSide = Lib.CLIENT_PROXY, serverSide = Lib.COMMON_PROXY, modId = Lib.MODID)
|
||||
public static CommonProxy proxy;
|
||||
public static Config modConfig;
|
||||
public static LibItems modItems;
|
||||
public static LibModifiers modModifiers;
|
||||
public Recipes recipes;
|
||||
public static ClientRegistry clientRegistry;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
CommonProxy.preInit();
|
||||
|
||||
modConfig = new Config(event.getSuggestedConfigurationFile());
|
||||
modItems = new LibItems();
|
||||
modModifiers = new LibModifiers();
|
||||
clientRegistry = new ClientRegistry();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(modConfig);
|
||||
MinecraftForge.EVENT_BUS.register(new ModAutoRepair());
|
||||
MinecraftForge.EVENT_BUS.register(clientRegistry);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
if (event.getSide().isClient())
|
||||
ClientProxy.init();
|
||||
recipes = new Recipes();
|
||||
}
|
||||
}
|
||||
|
|
@ -14,35 +14,36 @@ import net.minecraftforge.fml.client.config.GuiConfig;
|
|||
|
||||
public class ConfigGUI extends GuiConfig
|
||||
{
|
||||
public ConfigGUI(GuiScreen guiScreen)
|
||||
{
|
||||
super(guiScreen, new ConfigElement(TinkersAddons.modConfig.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), Lib.MODID, false, true, GuiConfig.getAbridgedConfigPath(TinkersAddons.modConfig.config.toString()));
|
||||
}
|
||||
public ConfigGUI(GuiScreen guiScreen)
|
||||
{
|
||||
super(guiScreen, new ConfigElement(TinkersAddons.modConfig.config.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), Lib.MODID, false, true, GuiConfig.getAbridgedConfigPath(TinkersAddons.modConfig.config.toString()));
|
||||
}
|
||||
|
||||
public static class GUIFactory implements IModGuiFactory
|
||||
{
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance)
|
||||
{
|
||||
|
||||
}
|
||||
public static class GUIFactory implements IModGuiFactory
|
||||
{
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance)
|
||||
{
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass()
|
||||
{
|
||||
return ConfigGUI.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean hasConfigGui()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiScreen createConfigGui(GuiScreen parentScreen)
|
||||
{
|
||||
return new ConfigGUI(parentScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,18 @@ package com.oitsjustjose.tinkers_addons.items;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.oitsjustjose.tinkers_addons.TinkersAddons;
|
||||
import com.oitsjustjose.tinkers_addons.lib.Lib;
|
||||
|
||||
import com.oitsjustjose.tinkers_addons.util.ClientRegistry;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
|
@ -18,56 +22,68 @@ import slimeknights.tconstruct.library.TinkerRegistry;
|
|||
@SuppressWarnings("deprecation")
|
||||
public class ItemModifier extends Item
|
||||
{
|
||||
private final String[] TYPES = new String[] { "AMELIORATION_TOME", "IRON_TOOLKIT", "GOLD_TOOLKIT", "DIAMOND_TOOLKIT", "ENDER_TOOLKIT" };
|
||||
private final String[] TYPES = new String[]{"AMELIORATION_TOME", "IRON_TOOLKIT", "GOLD_TOOLKIT", "DIAMOND_TOOLKIT", "ENDER_TOOLKIT"};
|
||||
|
||||
public ItemModifier()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
this.setCreativeTab(TinkerRegistry.tabGeneral);
|
||||
GameRegistry.register(this, new ResourceLocation(Lib.MODID.toLowerCase(), "modifier_item"));
|
||||
Lib.MOD_ITEMS.add(this);
|
||||
}
|
||||
public ItemModifier()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
this.setCreativeTab(TinkerRegistry.tabGeneral);
|
||||
this.setRegistryName(new ResourceLocation(Lib.MODID.toLowerCase(), "modifier_item"));
|
||||
ForgeRegistries.ITEMS.register(this);
|
||||
this.registerModels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasEffect(ItemStack itemstack)
|
||||
{
|
||||
return itemstack.getItemDamage() == 0;
|
||||
}
|
||||
private void registerModels()
|
||||
{
|
||||
for (int i = 0; i < this.TYPES.length; i++)
|
||||
TinkersAddons.clientRegistry.register(new ItemStack(this, 1, i), new ResourceLocation(this.getRegistryName().toString() + "_" + this.TYPES[i]), "inventory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return "item." + Lib.MODID + "." + TYPES[itemStack.getItemDamage()];
|
||||
}
|
||||
@Override
|
||||
public boolean hasEffect(ItemStack itemstack)
|
||||
{
|
||||
return itemstack.getItemDamage() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> list)
|
||||
{
|
||||
for (int i = 0; i < TYPES.length; i++)
|
||||
list.add(new ItemStack(item, 1, i));
|
||||
}
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
return "item." + Lib.MODID + "." + TYPES[itemStack.getItemDamage()];
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
|
||||
{
|
||||
switch (stack.getItemDamage())
|
||||
{
|
||||
case 0:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.AMELIORATION_TOME.description"));
|
||||
return;
|
||||
case 1:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.IRON_TOOLKIT.description"));
|
||||
return;
|
||||
case 2:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.GOLD_TOOLKIT.description"));
|
||||
return;
|
||||
case 3:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.DIAMOND_TOOLKIT.description"));
|
||||
return;
|
||||
case 4:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.ENDER_TOOLKIT.description"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
|
||||
{
|
||||
for (int i = 0; i < TYPES.length; i++)
|
||||
{
|
||||
if (this.isInCreativeTab(tab))
|
||||
{
|
||||
items.add(new ItemStack(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
|
||||
{
|
||||
switch (stack.getItemDamage())
|
||||
{
|
||||
case 0:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.AMELIORATION_TOME.description"));
|
||||
return;
|
||||
case 1:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.IRON_TOOLKIT.description"));
|
||||
return;
|
||||
case 2:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.GOLD_TOOLKIT.description"));
|
||||
return;
|
||||
case 3:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.DIAMOND_TOOLKIT.description"));
|
||||
return;
|
||||
case 4:
|
||||
tooltip.add(I18n.translateToLocal("item.TinkersAddons.ENDER_TOOLKIT.description"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,13 +9,7 @@ public class Lib
|
|||
public static final String MODID = "TinkersAddons";
|
||||
public static final String NAME = "Tinkers' Addons";
|
||||
public static final String VERSION = "@VERSION@";
|
||||
public static final String CLIENT_PROXY = "com.oitsjustjose.tinkers_addons.util.ClientProxy";
|
||||
public static final String COMMON_PROXY = "com.oitsjustjose.tinkers_addons.util.CommonProxy";
|
||||
public static final String GUI_FACTORY = "com.oitsjustjose.tinkers_addons.gui.ConfigGUI$GUIFactory";
|
||||
|
||||
public static final String TAG_AUTO_REPAIR = "Auto-Repair";
|
||||
public static final String TAG_AUTO_REPAIR_COOLDOWN = "Last Auto-Repair";
|
||||
public static final String TAG_REDSTONE_FLUX = "Redstone Flux";
|
||||
|
||||
public static final ArrayList<Item> MOD_ITEMS = new ArrayList<Item>();
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
package com.oitsjustjose.tinkers_addons.util;
|
||||
|
||||
/**
|
||||
* @author oitsjustjose with asiekierka's help (and others)
|
||||
*
|
||||
* This code is free to be used to help you out. Just change the assignment of the variables
|
||||
* MODID and tab to be your proper MODID and CreativeTab, then this class will work for you!
|
||||
*
|
||||
* NOTE: It is assumed that you initialize your items' / blocks' unlocalized names using
|
||||
* .setUnlocalizedName(MODID + ".<youDesiredNameHere>"); - this is critical for function below
|
||||
*
|
||||
* Item models will need to be placed in assets/<your_modid_all_lowercase_no_spaces>/models/items
|
||||
* Block models will need to be placed in assets/<your_modid_all_lowercase_no_spaces>/models/blocks
|
||||
* Block models will need BlockState files too, in assets/<your_modid_all_lowercase_no_spaces>/blockstates
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.oitsjustjose.tinkers_addons.lib.Lib;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.tconstruct.library.TinkerRegistry;
|
||||
import slimeknights.tconstruct.library.client.model.ModifierModelLoader;
|
||||
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
static CreativeTabs tab = TinkerRegistry.tabParts;
|
||||
static String MODID = Lib.MODID;
|
||||
static ModifierModelLoader modifierLoader;
|
||||
|
||||
/**
|
||||
* Grabs all the items from my stored arraylist and registers them Super convenient, I'd suggest doing similar things, and adding a similar block variant if you need it (I didn't)
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void init()
|
||||
{
|
||||
ArrayList<Item> items = Lib.MOD_ITEMS;
|
||||
|
||||
for (Item i : items)
|
||||
register(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* The Item to register a model registry for. You still have to make the model file, but now MC will know where to look
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void register(Item item)
|
||||
{
|
||||
int meta = 0;
|
||||
|
||||
List<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
item.getSubItems(item, tab, subItems);
|
||||
for (ItemStack sub : subItems)
|
||||
{
|
||||
String name = item.getUnlocalizedName(sub).substring(MODID.length() + 6).toLowerCase();
|
||||
ModelBakery.registerItemVariants(item, new ResourceLocation(MODID.toLowerCase(), name));
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, meta, new ModelResourceLocation(MODID.toLowerCase() + ":" + name, "inventory"));
|
||||
meta++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param block
|
||||
* The Item to register a model registry for. You still have to make the model file, but now MC will know where to look
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void register(Block block)
|
||||
{
|
||||
int meta = 0;
|
||||
Item itemBlock = Item.getItemFromBlock(block);
|
||||
// Checks if the block has metadata / subtypes
|
||||
if (itemBlock.getHasSubtypes())
|
||||
{
|
||||
List<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
itemBlock.getSubItems(itemBlock, tab, subItems);
|
||||
for (ItemStack sub : subItems)
|
||||
{
|
||||
String name = itemBlock.getUnlocalizedName(sub).toLowerCase().replace(MODID.toLowerCase() + ".", "").replace("tile.", "");
|
||||
ModelBakery.registerItemVariants(itemBlock, new ResourceLocation(MODID.toLowerCase(), name));
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemBlock, meta, new ModelResourceLocation(MODID.toLowerCase() + ":" + name, "inventory"));
|
||||
meta++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemBlock, 0, new ModelResourceLocation(MODID.toLowerCase() + ":" + block.getUnlocalizedName().substring(MODID.length() + 6).toLowerCase(), "inventory"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.oitsjustjose.tinkers_addons.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ClientRegistry
|
||||
{
|
||||
private HashMap<ItemStack, ModelResourceLocation> LOCATIONS = new HashMap();
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void handleModels(ModelRegistryEvent event)
|
||||
{
|
||||
for (Map.Entry<ItemStack, ModelResourceLocation> entry : LOCATIONS.entrySet())
|
||||
{
|
||||
ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void register(Block block, String variant)
|
||||
{
|
||||
LOCATIONS.put(new ItemStack(block), new ModelResourceLocation(block.getRegistryName(), variant));
|
||||
}
|
||||
|
||||
public void register(ItemStack itemstack, ResourceLocation resLoc, String variant)
|
||||
{
|
||||
LOCATIONS.put(itemstack, new ModelResourceLocation(resLoc, variant));
|
||||
}
|
||||
|
||||
public void register(ItemStack stack, String variant)
|
||||
{
|
||||
LOCATIONS.put(stack, new ModelResourceLocation(stack.getItem().getRegistryName(), variant));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.oitsjustjose.tinkers_addons.util;
|
||||
|
||||
public class CommonProxy
|
||||
{
|
||||
public static void preInit()
|
||||
{
|
||||
};
|
||||
|
||||
public static void init()
|
||||
{
|
||||
};
|
||||
}
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
package com.oitsjustjose.tinkers_addons.util;
|
||||
|
||||
import com.oitsjustjose.tinkers_addons.TinkersAddons;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import slimeknights.tconstruct.shared.TinkerCommons;
|
||||
import slimeknights.tconstruct.tools.TinkerMaterials;
|
||||
import slimeknights.tconstruct.tools.TinkerTools;
|
||||
|
||||
public class Recipes
|
||||
{
|
||||
public Recipes()
|
||||
{
|
||||
registerBonusModRecipes();
|
||||
}
|
||||
|
||||
public void registerBonusModRecipes()
|
||||
{
|
||||
ItemStack plateItem = null;
|
||||
ItemStack centerItem = null;
|
||||
|
||||
if (TinkersAddons.modConfig.enableAmelioration)
|
||||
{
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(TinkersAddons.modItems.materials, 1, 0), new Object[] { new ItemStack(TinkerCommons.materials, 1, 19), new ItemStack(TinkerCommons.materials, 1, 19), new ItemStack(TinkerCommons.materials, 1, 19), Items.BOOK }));
|
||||
}
|
||||
if (TinkersAddons.modConfig.enableExtraModifierLvl1)
|
||||
{
|
||||
plateItem = TinkerTools.largePlate.getItemstackWithMaterial(TinkerMaterials.iron);
|
||||
centerItem = TinkerCommons.blockPigIron;
|
||||
GameRegistry.addRecipe(new NBTShapedRecipe(3, 2, new ItemStack[] { plateItem, centerItem, plateItem, plateItem, plateItem, plateItem }, new ItemStack(TinkersAddons.modItems.materials, 1, 1)));
|
||||
}
|
||||
if (TinkersAddons.modConfig.enableExtraModifierLvl2)
|
||||
{
|
||||
plateItem = TinkerTools.largePlate.getItemstackWithMaterial(TinkerMaterials.ardite);
|
||||
centerItem = new ItemStack(Blocks.GOLD_BLOCK);
|
||||
GameRegistry.addRecipe(new NBTShapedRecipe(3, 2, new ItemStack[] { plateItem, centerItem, plateItem, plateItem, plateItem, plateItem }, new ItemStack(TinkersAddons.modItems.materials, 1, 2)));
|
||||
}
|
||||
if (TinkersAddons.modConfig.enableExtraModifierLvl3)
|
||||
{
|
||||
plateItem = TinkerTools.largePlate.getItemstackWithMaterial(TinkerMaterials.prismarine);
|
||||
centerItem = new ItemStack(Blocks.DIAMOND_BLOCK);
|
||||
GameRegistry.addRecipe(new NBTShapedRecipe(3, 2, new ItemStack[] { plateItem, centerItem, plateItem, plateItem, plateItem, plateItem }, new ItemStack(TinkersAddons.modItems.materials, 1, 3)));
|
||||
}
|
||||
if (TinkersAddons.modConfig.enableExtraModifierLvl4)
|
||||
{
|
||||
plateItem = TinkerTools.largePlate.getItemstackWithMaterial(TinkerMaterials.obsidian);
|
||||
centerItem = new ItemStack(Items.ENDER_PEARL);
|
||||
GameRegistry.addRecipe(new NBTShapedRecipe(3, 2, new ItemStack[] { plateItem, centerItem, plateItem, plateItem, plateItem, plateItem }, new ItemStack(TinkersAddons.modItems.materials, 1, 4)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BloodWorkXGaming : https://github.com/BloodWorkXGaming
|
||||
*
|
||||
* An inner class for adding NBT-Sensitive recipes. All credit to BloodWorkXGaming for finding and fixing this bug for me. ORIGINAL CLASS: https://github.com/AllTheMods/OreExcavationIntegration/blob/master/src/main/java/atm/bloodworkxgaming/oei/Crafting/NBTShapedRecipe.java
|
||||
*
|
||||
*/
|
||||
public class NBTShapedRecipe extends ShapedRecipes
|
||||
{
|
||||
|
||||
public NBTShapedRecipe(int width, int height, ItemStack[] IngredientArray, ItemStack output)
|
||||
{
|
||||
super(width, height, IngredientArray, output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if a recipe matches current crafting inventory
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inv, World worldIn)
|
||||
{
|
||||
for (int i = 0; i <= 3 - this.recipeWidth; ++i)
|
||||
{
|
||||
for (int j = 0; j <= 3 - this.recipeHeight; ++j)
|
||||
{
|
||||
if (this.checkMatch(inv, i, j, true))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.checkMatch(inv, i, j, false))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the region of a crafting inventory is match for the recipe.
|
||||
*/
|
||||
private boolean checkMatch(InventoryCrafting inventoryCrafting, int horizontal, int vertical, boolean p_77573_4_)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
int k = i - horizontal;
|
||||
int l = j - vertical;
|
||||
ItemStack itemStackRecipe = null;
|
||||
|
||||
if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight)
|
||||
{
|
||||
if (p_77573_4_)
|
||||
{
|
||||
itemStackRecipe = this.recipeItems[this.recipeWidth - k - 1 + l * this.recipeWidth];
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStackRecipe = this.recipeItems[k + l * this.recipeWidth];
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack input = inventoryCrafting.getStackInRowAndColumn(i, j);
|
||||
|
||||
if (input != null || itemStackRecipe != null)
|
||||
{
|
||||
if ((input == null) != (itemStackRecipe == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemStackRecipe.getItem() != input.getItem())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemStackRecipe.getMetadata() != 32767 && itemStackRecipe.getMetadata() != input.getMetadata())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (itemStackRecipe.hasTagCompound() && input.hasTagCompound())
|
||||
{
|
||||
if (!itemStackRecipe.getTagCompound().equals(input.getTagCompound()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue