Search in sources :

Example 6 with SyncMaterialData

use of uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData 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

SyncMaterialData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMaterialData)6 ItemStack (net.minecraft.item.ItemStack)2 SyncFreeDevRecipeData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncFreeDevRecipeData)2 SyncRecipeData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncRecipeData)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Material (uk.co.wehavecookies56.kk.api.materials.Material)1 Recipe (uk.co.wehavecookies56.kk.api.recipes.Recipe)1 SynthesisMaterialCapability (uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability)1 ItemKeychain (uk.co.wehavecookies56.kk.common.item.base.ItemKeychain)1 ItemSynthesisMaterial (uk.co.wehavecookies56.kk.common.item.base.ItemSynthesisMaterial)1 SyncMunnyData (uk.co.wehavecookies56.kk.common.network.packet.client.SyncMunnyData)1 OpenSynthesis (uk.co.wehavecookies56.kk.common.network.packet.server.OpenSynthesis)1