Search in sources :

Example 6 with Material

use of uk.co.wehavecookies56.kk.api.materials.Material in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class CreateFromSynthesisRecipe method process.

@Override
public void process(EntityPlayer player, Side side) {
    boolean freeDev = false;
    if (FreeDevRecipeRegistry.isFreeDevRecipeRegistered(name)) {
        freeDev = true;
    }
    if (!freeDev) {
        if (RecipeRegistry.get(name).getResult().getItem() instanceof ItemKeychain)
            player.inventory.addItemStackToInventory(RecipeRegistry.get(name).getResult());
        Recipe r = RecipeRegistry.get(name);
        SynthesisMaterialCapability.ISynthesisMaterial MATS = player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null);
        Iterator it = r.getRequirements().entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Material, Integer> pair = (Map.Entry<Material, Integer>) it.next();
            MATS.removeMaterial(pair.getKey(), pair.getValue());
        }
    } else {
        player.inventory.addItemStackToInventory(FreeDevRecipeRegistry.get(name).getResult());
        Recipe r = FreeDevRecipeRegistry.get(name);
        SynthesisMaterialCapability.ISynthesisMaterial MATS = player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null);
        Iterator it = r.getRequirements().entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Material, Integer> pair = (Map.Entry<Material, Integer>) it.next();
            MATS.removeMaterial(pair.getKey(), pair.getValue());
        }
    }
    PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
}
Also used : SynthesisMaterialCapability(uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability) ItemKeychain(uk.co.wehavecookies56.kk.common.item.base.ItemKeychain) Recipe(uk.co.wehavecookies56.kk.api.recipes.Recipe) Iterator(java.util.Iterator) Material(uk.co.wehavecookies56.kk.api.materials.Material) Map(java.util.Map) SyncMaterialData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)

Example 7 with Material

use of uk.co.wehavecookies56.kk.api.materials.Material in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class DepositMaterialsFromBag method removeMaterial.

public void removeMaterial(IItemHandler bag, EntityPlayer player, int i) {
    for (int j = 0; j < bag.getSlots(); j++) {
        ItemStack bagItem = bag.getStackInSlot(j);
        if (!ItemStack.areItemStacksEqual(bagItem, ItemStack.EMPTY)) {
            if (bagItem.hasTagCompound()) {
                String s = bagItem.getTagCompound().getString("material");
                if (MaterialRegistry.isMaterialRegistered(s)) {
                    player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(s), bag.getStackInSlot(j).getCount());
                }
                bag.extractItem(j, bag.getStackInSlot(j).getCount(), false);
            }
        } else if (MaterialRegistry.isMaterialRegistered(player.inventory.mainInventory.get(i).getItem().getUnlocalizedName())) {
            player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(player.inventory.mainInventory.get(i).getItem().getUnlocalizedName()), player.inventory.mainInventory.get(i).getCount());
            player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
        }
        PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) SyncMaterialData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)

Example 8 with Material

use of uk.co.wehavecookies56.kk.api.materials.Material in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class OpenMaterials method process.

@Override
public void process(EntityPlayer player, Side side) {
    for (int i = 0; i < 36; i++) {
        if (!ItemStack.areItemStacksEqual(player.inventory.mainInventory.get(i), ItemStack.EMPTY)) {
            if (player.inventory.mainInventory.get(i).getItem() instanceof ItemSynthesisMaterial) {
                if (player.inventory.mainInventory.get(i).hasTagCompound()) {
                    String s = player.inventory.mainInventory.get(i).getTagCompound().getString("material");
                    if (MaterialRegistry.isMaterialRegistered(s)) {
                        player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(s), player.inventory.mainInventory.get(i).getCount());
                    }
                    player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                }
            } else if (MaterialRegistry.isMaterialRegistered(player.inventory.mainInventory.get(i).getItem().getUnlocalizedName().toString())) {
                player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(player.inventory.mainInventory.get(i).getItem().getUnlocalizedName()), player.inventory.mainInventory.get(i).getCount());
                player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
            }
            PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
        }
    }
/*for (int i = 0; i < 36; i++)
            if (player.inventory.mainInventory[i] != null) if (player.inventory.mainInventory[i].getItem() instanceof ItemSynthesisMaterial) {
                if (player.inventory.mainInventory[i].hasTagCompound()) {
                    String s = player.inventory.mainInventory[i].getTagCompound().getString("material");
                    if (MaterialRegistry.isMaterialRegistered(s)) player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(s), player.inventory.mainInventory[i].stackSize);
                    player.inventory.setInventorySlotContents(i, null);
                }

            } else if (MaterialRegistry.isMaterialRegistered(player.inventory.mainInventory[i].getItem().getUnlocalizedName().toString())) {
                player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).addMaterial(MaterialRegistry.get(player.inventory.mainInventory[i].getItem().getUnlocalizedName()), player.inventory.mainInventory[i].stackSize);
                player.inventory.setInventorySlotContents(i, null);
            }
        PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
        */
}
Also used : ItemSynthesisMaterial(uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial) SyncMaterialData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)

Example 9 with Material

use of uk.co.wehavecookies56.kk.api.materials.Material in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class SyncMaterialData method process.

@Override
public void process(EntityPlayer player, Side side) {
    final ISynthesisMaterial material = player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null);
    Iterator<Entry<String, Integer>> it = materials.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Integer> pair = (Map.Entry<String, Integer>) it.next();
        material.setMaterial(MaterialRegistry.get(pair.getKey().toString()), pair.getValue());
    }
}
Also used : Entry(java.util.Map.Entry) Map(java.util.Map) HashMap(java.util.HashMap) ISynthesisMaterial(uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability.ISynthesisMaterial)

Example 10 with Material

use of uk.co.wehavecookies56.kk.api.materials.Material in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class TakeMaterials method process.

@Override
public void process(EntityPlayer player, Side side) {
    if (amount > player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).getMaterialAmount(MaterialRegistry.get(materialName)))
        amount = player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).getMaterialAmount(MaterialRegistry.get(materialName));
    if (materialName.startsWith("sm.")) {
        ItemStack material = new ItemStack(ModItems.SynthesisMaterial, amount);
        material.setTagCompound(new NBTTagCompound());
        material.getTagCompound().setString("material", materialName);
        if (materialName.endsWith("shard"))
            material.getTagCompound().setString("rank", "sm.rank.c");
        else if (materialName.endsWith("stone"))
            material.getTagCompound().setString("rank", "sm.rank.b");
        else if (materialName.endsWith("gem") || materialName.equals(Strings.SM_ManifestIllusion) || materialName.equals(Strings.SM_Orichalcum))
            material.getTagCompound().setString("rank", "sm.rank.a");
        else if (materialName.endsWith("crystal") || materialName.equals(Strings.SM_LostIllusion) || materialName.equals(Strings.SM_OrichalcumPlus))
            material.getTagCompound().setString("rank", "sm.rank.s");
        player.inventory.addItemStackToInventory(material);
        player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).removeMaterial(MaterialRegistry.get(materialName), amount);
    } else if (materialName.startsWith("item.")) {
        if (ForgeRegistries.ITEMS.getValue(new ResourceLocation(Reference.MODID, materialName.replace("item.", ""))) != null) {
            player.inventory.addItemStackToInventory(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Reference.MODID, materialName.replace("item.", ""))), amount));
            player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).removeMaterial(MaterialRegistry.get(materialName), amount);
        } else {
            // VANILLA ITEMS HERE
            if (materialName.equals(Items.WOODEN_SWORD.getUnlocalizedName())) {
                player.inventory.addItemStackToInventory(new ItemStack(Items.WOODEN_SWORD, amount));
                player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).removeMaterial(MaterialRegistry.get(materialName), amount);
            }
            if (materialName.equals(Items.STICK.getUnlocalizedName())) {
                player.inventory.addItemStackToInventory(new ItemStack(Items.STICK, amount));
                player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).removeMaterial(MaterialRegistry.get(materialName), amount);
            }
        }
    } else if (materialName.startsWith("tile."))
        if (ForgeRegistries.BLOCKS.getValue(new ResourceLocation(Reference.MODID, materialName.replace("tile.", ""))) != null) {
            player.inventory.addItemStackToInventory(new ItemStack(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(Reference.MODID, materialName.replace("tile.", ""))), amount));
            player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null).removeMaterial(MaterialRegistry.get(materialName), amount);
        } else {
        // VANILLA BLOCKS HERE
        }
    PacketDispatcher.sendTo(new SyncMaterialData(player.getCapability(ModCapabilities.SYNTHESIS_MATERIALS, null)), (EntityPlayerMP) player);
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) SyncMaterialData(uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)

Aggregations

Material (uk.co.wehavecookies56.kk.api.materials.Material)7 Map (java.util.Map)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 SynthesisMaterialCapability (uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability)6 Iterator (java.util.Iterator)5 ItemStack (net.minecraft.item.ItemStack)5 ArrayList (java.util.ArrayList)4 SyncMaterialData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)4 Recipe (uk.co.wehavecookies56.kk.api.recipes.Recipe)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ISynthesisMaterial (uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability.ISynthesisMaterial)2 SynthesisRecipeCapability (uk.co.wehavecookies56.kk.common.capability.SynthesisRecipeCapability)2 ItemSynthesisMaterial (uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial)2 CreateFromSynthesisRecipe (uk.co.wehavecookies56.kk.common.network.packet.server.CreateFromSynthesisRecipe)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Item (net.minecraft.item.Item)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 VillagerRegistry (net.minecraftforge.fml.common.registry.VillagerRegistry)1 GuiHandler (uk.co.wehavecookies56.kk.common.core.handler.GuiHandler)1