Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How do I give a potion effect when wearing armor?


Recommended Posts

I want to be able to give the player a potion effect when it is wearing armor.

Also, a bit more specific, when it is wearing a specific piece.

So for example, when the player wears a helmet it gives him 2 hearts of absorption. When he wears the chestplate it gives him the same, but when he wears both it gives him 4 hearts of absorption.

 

How would I go about doing this when I have this armor class:

 

package assets.caves_of_millarki.common;

 

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.EnumArmorMaterial;

import net.minecraft.item.ItemArmor;

import net.minecraft.item.ItemStack;

import net.minecraft.util.DamageSource;

 

public class PureStoneArmor extends ItemArmor 

{

public PureStoneArmor(int i, EnumArmorMaterial enumarmormaterial, int j, int k)

{

super(i, enumarmormaterial, j, k);

}

@Override

public void registerIcons(IconRegister iconRegister)

{

if(itemID == Mainclass.PureStoneHelm.itemID)

{

itemIcon = iconRegister.registerIcon("caves_of_millarki:purestonehelm");

}

if(itemID == Mainclass.PureStoneChest.itemID)

{

itemIcon = iconRegister.registerIcon("caves_of_millarki:purestonechest");

}

if(itemID == Mainclass.PureStoneLegs.itemID)

{

itemIcon = iconRegister.registerIcon("caves_of_millarki:purestonelegs");

}

if(itemID == Mainclass.PureStoneBoots.itemID)

{

itemIcon = iconRegister.registerIcon("caves_of_millarki:purestoneboots");

}

}

 

 

 

@Override

public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer)

{

if(itemID == Mainclass.PureStoneHelm.itemID || itemID == Mainclass.PureStoneChest.itemID || itemID == Mainclass.PureStoneBoots.itemID)

{

return CommonProxy.PURESTONE_1;

}

if(itemID == Mainclass.PureStoneLegs.itemID)

{

return CommonProxy.PURESTONE_2;

}

else return null;

}

 

   

    public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)

    {

        return Mainclass.PureGarnet.itemID == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);

    }

 

 

}

 

 

 

 

Also, I created a custom crafting table, but the recipes don't work. In 1.5 they did, what am I doing wrong now?

 

Block:

 

package assets.caves_of_millarki.common;

 

import assets.caves_of_millarki.common.Mainclass;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.util.Icon;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class BoneBench extends Block

{

 

@SideOnly(Side.CLIENT)

private Icon field_94385_a;

@SideOnly(Side.CLIENT)

private Icon field_94384_b;

 

public BoneBench(int par1)

{

        super(par1, Material.wood);

        //blockIndexInTexture = 59;

        this.setCreativeTab(Mainclass.MillarkiTab);

}

 

 

/**

        * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata

        */

@Override

public Icon getIcon(int par1, int par2)

{

if(par2 == 0)

par2 = 3;

        return par1 == 1 ? this.field_94385_a : (par1 == 0 ? Mainclass.BoneBlock.getBlockTextureFromSide(par1) : (par1 != 2 && par1 != 4 ? this.blockIcon : this.field_94384_b));

}

 

@SideOnly(Side.CLIENT)

 

/*** When this method is called, your block should register all the icons it needs with the given IconRegister. This

*is the only chance you get to register icons.

        */

@Override

public void registerIcons(IconRegister par1IconRegister)

{

    this.blockIcon = par1IconRegister.registerIcon("caves_of_millarki:bonebench_side");

    this.field_94385_a = par1IconRegister.registerIcon("caves_of_millarki:bonebench_top");

    this.field_94384_b = par1IconRegister.registerIcon("caves_of_millarki:bonebench_front");

}

 

public boolean onBlockActivated(World var1, int var2, int var3, int var4, EntityPlayer player, int var6, float var7, float var8, float var9)

{

        if (!player.isSneaking())

{

player.openGui(Mainclass.instance, 1, var1, var2, var3, var4);

return true;

}

else

{

return false;

}

 

}

 

}

 

Crafting Manager:

 

package assets.caves_of_millarki.common;

 

import java.util.ArrayList;

import java.util.Collections;

import java.util.HashMap;

import java.util.List;

 

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraft.block.Block;

import net.minecraft.inventory.InventoryCrafting;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.IRecipe;

import net.minecraft.item.crafting.ShapedRecipes;

import net.minecraft.item.crafting.ShapelessRecipes;

import net.minecraft.world.World;

 

public class BoneBenchCraftingManager

{

/** The static instance of this class */

private static final BoneBenchCraftingManager instance = new BoneBenchCraftingManager();

 

/** A list of all the recipes added */

private List recipes = new ArrayList();

 

/**

        * Returns the static instance of this class

        */

public static final BoneBenchCraftingManager getInstance()

{

        return instance;

}

 

private BoneBenchCraftingManager()

{

 

 

ItemStack bone = new ItemStack(Item.bone);

ItemStack rough = new ItemStack(Mainclass.RoughStone);

 

        recipes = new ArrayList();

        this.addRecipe(new ItemStack(Mainclass.RoughBonePickaxe), "RRR", " B ", " B ",

        'B', bone, 'R', rough);

        this.addRecipe(new ItemStack(Mainclass.BonePickaxe, 1), new Object[] {"XXX", " B ", " B ", Character.valueOf('B'), Item.bone, Character.valueOf('X'), Mainclass.BoneBlock});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneSword, 1), new Object[] {"R", "R", "B", Character.valueOf('B'), Item.bone, Character.valueOf('R'), Mainclass.RoughStone});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneAxe, 1), new Object[] {"RR ", "RB ", " B ", Character.valueOf('B'), Item.bone, Character.valueOf('R'), Mainclass.RoughStone});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneShovel, 1), new Object[] {"R", "B", "B", Character.valueOf('B'), Item.bone, Character.valueOf('R'), Mainclass.RoughStone});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneHoe, 1), new Object[] {"RR ", " B ", " B ", Character.valueOf('B'), Item.bone, Character.valueOf('R'), Mainclass.RoughStone});

 

        this.addRecipe(new ItemStack(Mainclass.PurifierIdle, 1), new Object[] {"RRR", "RGR", "RRR", Character.valueOf('G'), Mainclass.Garnet, Character.valueOf('R'), Mainclass.RoughStone});

 

        this.addRecipe(new ItemStack(Mainclass.PureBonePickaxe, 1), new Object[] {"GGG", " B ", " B ", Character.valueOf('B'), Item.bone, Character.valueOf('G'), Mainclass.PureGarnet});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneSword, 1), new Object[] {"G", "G", "B", Character.valueOf('B'), Item.bone, Character.valueOf('G'), Mainclass.PureGarnet});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneAxe, 1), new Object[] {"GG ", "GB ", " B ", Character.valueOf('B'), Item.bone, Character.valueOf('G'), Mainclass.PureGarnet});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneShovel, 1), new Object[] {"G", "B", "B", Character.valueOf('B'), Item.bone, Character.valueOf('G'), Mainclass.PureGarnet});

        this.addRecipe(new ItemStack(Mainclass.RoughBoneHoe, 1), new Object[] {"GG ", " B ", " B ", Character.valueOf('B'), Item.bone, Character.valueOf('G'), Mainclass.PureGarnet});

        this.addRecipe(new ItemStack(Mainclass.PureStoneHelm, 1), new Object[] {"SSS", "G G", "  ", Character.valueOf('G'), Mainclass.PureGarnet, Character.valueOf('S'), Mainclass.PureStone});

        this.addRecipe(new ItemStack(Mainclass.PureStoneHelm, 1), new Object[] {"  ", "SSS", "G G", Character.valueOf('G'), Mainclass.PureGarnet, Character.valueOf('S'), Mainclass.PureStone});

        this.addRecipe(new ItemStack(Mainclass.PureStoneChest, 1), new Object[] {"SGS", "SSS", "SSS", Character.valueOf('G'), Mainclass.PureGarnet, Character.valueOf('S'), Mainclass.PureStone});

        this.addRecipe(new ItemStack(Mainclass.PureStoneLegs, 1), new Object[] {"SSS", "G G", "S S", Character.valueOf('G'), Mainclass.PureGarnet, Character.valueOf('S'), Mainclass.PureStone});

        this.addRecipe(new ItemStack(Mainclass.PureStoneBoots, 1), new Object[] {"S S", "G G", "  ", Character.valueOf('G'), Mainclass.PureGarnet, Character.valueOf('S'), Mainclass.PureStone});

        this.addRecipe(new ItemStack(Mainclass.PureStoneBoots, 1), new Object[] {"  ", "S S", "G G", Character.valueOf('G'), Mainclass.PureGarnet, Character.valueOf('S'), Mainclass.PureStone});

 

        this.addRecipe(new ItemStack(Mainclass.DarkPickaxe, 1), new Object[] {"DDD", " S ", " S ", Character.valueOf('S'), Mainclass.DarkStick, Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkSword, 1), new Object[] {"D", "D", "S", Character.valueOf('S'), Mainclass.DarkStick, Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkAxe, 1), new Object[] {"DD ", "DS ", " S ", Character.valueOf('S'), Mainclass.DarkStick, Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkShovel, 1), new Object[] {"D", "S", "S", Character.valueOf('S'), Mainclass.DarkStick, Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkHoe, 1), new Object[] {"DD ", " S ", " S ", Character.valueOf('S'), Mainclass.DarkStick, Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkHelm, 1), new Object[] {"DDD", "D D", "  ", Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkHelm, 1), new Object[] {"  ", "DDD", "D D", Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkChest, 1), new Object[] {"D D", "DDD", "DDD", Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkLegs, 1), new Object[] {"DDD", "D D", "D D", Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkBoots, 1), new Object[] {"D D", "D D", "  ", Character.valueOf('D'), Mainclass.DarkGem});

        this.addRecipe(new ItemStack(Mainclass.DarkBoots, 1), new Object[] {"  ", "D D", "D D", Character.valueOf('D'), Mainclass.DarkGem});

 

        this.addRecipe(new ItemStack(Mainclass.PreciousPickaxe, 1), new Object[] {"PPP", " S ", " S ", Character.valueOf('S'), Mainclass.PreciousStick, Character.valueOf('P'), Mainclass.PreciousIngot});

        this.addRecipe(new ItemStack(Mainclass.PreciousSword, 1), new Object[] {"P", "P", "S", Character.valueOf('S'), Mainclass.PreciousStick, Character.valueOf('P'), Mainclass.PreciousIngot});

        this.addRecipe(new ItemStack(Mainclass.PreciousAxe, 1), new Object[] {"PP ", "PS ", " S ", Character.valueOf('S'), Mainclass.PreciousStick, Character.valueOf('P'), Mainclass.PreciousIngot});

        this.addRecipe(new ItemStack(Mainclass.PreciousShovel, 1), new Object[] {"P", "S", "S", Character.valueOf('S'), Mainclass.PreciousStick, Character.valueOf('P'), Mainclass.PreciousIngot});

        this.addRecipe(new ItemStack(Mainclass.PreciousHoe, 1), new Object[] {"PP ", " S ", " S ", Character.valueOf('S'), Mainclass.PreciousStick, Character.valueOf('P'), Mainclass.PreciousIngot});

 

        this.addRecipe(new ItemStack(Mainclass.FlamePickaxe, 1), new Object[] {"FFF", " S ", " S ", Character.valueOf('S'), Mainclass.FlameStick, Character.valueOf('F'), Mainclass.FlameGem});

        this.addRecipe(new ItemStack(Mainclass.FlameSword, 1), new Object[] {"F", "F", "S", Character.valueOf('S'), Mainclass.FlameStick, Character.valueOf('F'), Mainclass.FlameGem});

        this.addRecipe(new ItemStack(Mainclass.FlameAxe, 1), new Object[] {"FF ", "FS ", " S ", Character.valueOf('S'), Mainclass.FlameStick, Character.valueOf('F'), Mainclass.FlameGem});

        this.addRecipe(new ItemStack(Mainclass.FlameShovel, 1), new Object[] {"F", "S", "S", Character.valueOf('S'), Mainclass.FlameStick, Character.valueOf('F'), Mainclass.FlameGem});

        this.addRecipe(new ItemStack(Mainclass.FlameHoe, 1), new Object[] {"FF ", " S ", " S ", Character.valueOf('S'), Mainclass.FlameStick, Character.valueOf('F'), Mainclass.FlameGem});

 

                Collections.sort(this.recipes, new BoneBenchRecipeSorter(this));

}

 

public ShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)

{

        String s = "";

        int i = 0;

        int j = 0;

        int k = 0;

 

        if (par2ArrayOfObj instanceof String[])

        {

                String[] astring = (String[])((String[])par2ArrayOfObj[i++]);

 

                for (int l = 0; l < astring.length; ++l)

                {

                        String s1 = astring[l];

                        ++k;

                        j = s1.length();

                        s = s + s1;

                }

        }

        else

        {

                while (par2ArrayOfObj instanceof String)

                {

                        String s2 = (String)par2ArrayOfObj[i++];

                        ++k;

                        j = s2.length();

                        s = s + s2;

                }

        }

 

        HashMap hashmap;

 

        for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)

        {

                Character character = (Character)par2ArrayOfObj;

                ItemStack itemstack1 = null;

 

                if (par2ArrayOfObj[i + 1] instanceof Item)

                {

                        itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);

                }

                else if (par2ArrayOfObj[i + 1] instanceof Block)

                {

                        itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);

                }

                else if (par2ArrayOfObj[i + 1] instanceof ItemStack)

                {

                        itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];

                }

 

                hashmap.put(character, itemstack1);

        }

 

        ItemStack[] aitemstack = new ItemStack[j * k];

 

        for (int i1 = 0; i1 < j * k; ++i1)

        {

                char c0 = s.charAt(i1);

 

                if (hashmap.containsKey(Character.valueOf(c0)))

                {

                        aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();

                }

                else

                {

                        aitemstack[i1] = null;

                }

        }

 

        ShapedRecipes shapedrecipes = new ShapedRecipes(j, k, aitemstack, par1ItemStack);

        this.recipes.add(shapedrecipes);

        return shapedrecipes;

}

 

public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)

{

        ArrayList arraylist = new ArrayList();

        Object[] aobject = par2ArrayOfObj;

        int i = par2ArrayOfObj.length;

 

        for (int j = 0; j < i; ++j)

        {

                Object object1 = aobject[j];

 

                if (object1 instanceof ItemStack)

                {

                        arraylist.add(((ItemStack)object1).copy());

                }

                else if (object1 instanceof Item)

                {

                        arraylist.add(new ItemStack((Item)object1));

                }

                else

                {

                        if (!(object1 instanceof Block))

                        {

                                throw new RuntimeException("Invalid shapeless recipy!");

                        }

 

                        arraylist.add(new ItemStack((Block)object1));

                }

        }

 

        this.recipes.add(new ShapelessRecipes(par1ItemStack, arraylist));

}

 

public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)

{

        int i = 0;

        ItemStack itemstack = null;

        ItemStack itemstack1 = null;

        int j;

 

        for (j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)

        {

                ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(j);

 

                if (itemstack2 != null)

                {

                        if (i == 0)

                        {

                                itemstack = itemstack2;

                        }

 

                        if (i == 1)

                        {

                                itemstack1 = itemstack2;

                        }

 

                        ++i;

                }

        }

 

        if (i == 2 && itemstack.itemID == itemstack1.itemID && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && Item.itemsList[itemstack.itemID].isRepairable())

        {

                Item item = Item.itemsList[itemstack.itemID];

                int k = item.getMaxDamage() - itemstack.getItemDamageForDisplay();

                int l = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();

                int i1 = k + l + item.getMaxDamage() * 5 / 100;

                int j1 = item.getMaxDamage() - i1;

 

                if (j1 < 0)

                {

                        j1 = 0;

                }

 

                return new ItemStack(itemstack.itemID, 1, j1);

        }

        else

        {

                for (j = 0; j < this.recipes.size(); ++j)

                {

                        IRecipe irecipe = (IRecipe)this.recipes.get(j);

 

                        if (irecipe.matches(par1InventoryCrafting, par2World))

                        {

                                return irecipe.getCraftingResult(par1InventoryCrafting);

                        }

                }

 

                return null;

        }

}

 

/**

        * returns the List<> of all recipes

        */

public List getRecipeList()

{

        return this.recipes;

}

}

 

Recipe Sorter:

 

package assets.caves_of_millarki.common;

 

import java.util.Comparator;

 

import assets.caves_of_millarki.common.Mainclass;

import net.minecraft.item.crafting.CraftingManager;

import net.minecraft.item.crafting.IRecipe;

import net.minecraft.item.crafting.ShapedRecipes;

import net.minecraft.item.crafting.ShapelessRecipes;

 

class BoneBenchRecipeSorter implements Comparator

{

final BoneBenchCraftingManager BoneBenchCraftingManager;

 

BoneBenchRecipeSorter(BoneBenchCraftingManager par1BoneBenchCraftingManager)

{

        this.BoneBenchCraftingManager = par1BoneBenchCraftingManager;

}

 

public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe)

{

        return par1IRecipe instanceof ShapelessRecipes && par2IRecipe instanceof ShapedRecipes ? 1 : (par2IRecipe instanceof ShapelessRecipes && par1IRecipe instanceof ShapedRecipes ? -1 : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize() ? -1 : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0)));

}

 

public int compare(Object par1Obj, Object par2Obj)

{

        return this.compareRecipes((IRecipe)par1Obj, (IRecipe)par2Obj);

}

}

 

Gui:

 

package assets.caves_of_millarki.common;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.client.resources.I18n;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.ContainerWorkbench;

import net.minecraft.util.ResourceLocation;

import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

 

@SideOnly(Side.CLIENT)

public class GuiBoneBench extends GuiContainer

{

    private static final ResourceLocation field_110422_t = new ResourceLocation("textures/gui/container/crafting_table.png");

 

    public GuiBoneBench(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)

    {

        super(new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5));

    }

 

    /**

    * Draw the foreground layer for the GuiContainer (everything in front of the items)

    */

    protected void drawGuiContainerForegroundLayer(int par1, int par2)

    {

        this.fontRenderer.drawString(I18n.func_135053_a("container.crafting"), 28, 6, 4210752);

        this.fontRenderer.drawString(I18n.func_135053_a("container.inventory"), 8, this.ySize - 96 + 2, 4210752);

    }

 

    /**

    * Draw the background layer for the GuiContainer (everything behind the items)

    */

    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)

    {

        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        this.mc.func_110434_K().func_110577_a(field_110422_t);

        int k = (this.width - this.xSize) / 2;

        int l = (this.height - this.ySize) / 2;

        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

    }

}

 

 

GuiHandler:

 

package assets.caves_of_millarki.common;

 

import net.minecraft.client.gui.inventory.GuiCrafting;

import net.minecraft.entity.player.EntityPlayer;

import assets.caves_of_millarki.common.Mainclass;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import cpw.mods.fml.common.network.IGuiHandler;

 

public class GuiHandler implements IGuiHandler{

 

@Override

public Object getServerGuiElement(int id, EntityPlayer player, World world,

int x, int y, int z) {

TileEntity tile_entity = world.getBlockTileEntity(x, y, z);

 

if (tile_entity instanceof TileEntityPurifier) {

return new ContainerPurifier(player.inventory,(TileEntityPurifier) tile_entity);

}

 

 

switch(id)

{

case 1: return id == 1 && world.getBlockId(x, y, z) == Mainclass.BoneBench.blockID ? new ContainerBoneBench(player.inventory, world, x, y, z) : null;

 

}

return null;

}

 

 

@Override

public Object  getClientGuiElement(int ID, EntityPlayer player, World world,

int x, int y, int z) {

TileEntity tile_entity = world.getBlockTileEntity(x, y, z);

if (tile_entity instanceof TileEntityPurifier) {

return new GuiPurifier(player.inventory,(TileEntityPurifier) tile_entity);

 

}

 

switch(ID)

{

case 1: return ID == 1 && world.getBlockId(x, y, z) == Mainclass.BoneBench.blockID ? new GuiBoneBench(player.inventory, world, x, y, z) : null;

}

return null;

}

 

}

 

 

Slot:

 

package assets.caves_of_millarki.common;

 

import cpw.mods.fml.common.registry.GameRegistry;

import net.minecraft.block.Block;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.Slot;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.stats.AchievementList;

 

import net.minecraftforge.common.ForgeHooks;

import net.minecraftforge.common.MinecraftForge;

import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;

 

public class SlotBoneBench extends Slot

{

    /** The craft matrix inventory linked to this result slot. */

    private final IInventory craftMatrix;

 

    /** The player that is using the GUI where this slot resides. */

    private EntityPlayer thePlayer;

 

    /**

    * The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.

    */

    private int amountCrafted;

 

    public SlotBoneBench(EntityPlayer par1EntityPlayer, IInventory par2IInventory, IInventory par3IInventory, int par4, int par5, int par6)

    {

        super(par3IInventory, par4, par5, par6);

        this.thePlayer = par1EntityPlayer;

        this.craftMatrix = par2IInventory;

    }

 

    /**

    * Check if the stack is a valid item for this slot. Always true beside for the armor slots.

    */

    public boolean isItemValid(ItemStack par1ItemStack)

    {

        return false;

    }

 

    /**

    * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new

    * stack.

    */

    public ItemStack decrStackSize(int par1)

    {

        if (this.getHasStack())

        {

            this.amountCrafted += Math.min(par1, this.getStack().stackSize);

        }

 

        return super.decrStackSize(par1);

    }

 

    /**

    * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an

    * internal count then calls onCrafting(item).

    */

    protected void onCrafting(ItemStack par1ItemStack, int par2)

    {

        this.amountCrafted += par2;

        this.onCrafting(par1ItemStack);

    }

 

    /**

    * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.

    */

    protected void onCrafting(ItemStack par1ItemStack)

    {

        par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted);

        this.amountCrafted = 0;

 

        if (par1ItemStack.itemID == Block.workbench.blockID)

        {

            this.thePlayer.addStat(AchievementList.buildWorkBench, 1);

        }

        else if (par1ItemStack.itemID == Item.pickaxeWood.itemID)

        {

            this.thePlayer.addStat(AchievementList.buildPickaxe, 1);

        }

        else if (par1ItemStack.itemID == Block.furnaceIdle.blockID)

        {

            this.thePlayer.addStat(AchievementList.buildFurnace, 1);

        }

        else if (par1ItemStack.itemID == Item.hoeWood.itemID)

        {

            this.thePlayer.addStat(AchievementList.buildHoe, 1);

        }

        else if (par1ItemStack.itemID == Item.bread.itemID)

        {

            this.thePlayer.addStat(AchievementList.makeBread, 1);

        }

        else if (par1ItemStack.itemID == Item.cake.itemID)

        {

            this.thePlayer.addStat(AchievementList.bakeCake, 1);

        }

        else if (par1ItemStack.itemID == Item.pickaxeStone.itemID)

        {

            this.thePlayer.addStat(AchievementList.buildBetterPickaxe, 1);

        }

        else if (par1ItemStack.itemID == Item.swordWood.itemID)

        {

            this.thePlayer.addStat(AchievementList.buildSword, 1);

        }

        else if (par1ItemStack.itemID == Block.enchantmentTable.blockID)

        {

            this.thePlayer.addStat(AchievementList.enchantments, 1);

        }

        else if (par1ItemStack.itemID == Block.bookShelf.blockID)

        {

            this.thePlayer.addStat(AchievementList.bookcase, 1);

        }

    }

 

    public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)

    {

        GameRegistry.onItemCrafted(par1EntityPlayer, par2ItemStack, craftMatrix);

        this.onCrafting(par2ItemStack);

 

        for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i)

        {

            ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);

 

            if (itemstack1 != null)

            {

                this.craftMatrix.decrStackSize(i, 1);

 

                if (itemstack1.getItem().hasContainerItem())

                {

                    ItemStack itemstack2 = itemstack1.getItem().getContainerItemStack(itemstack1);

 

                    if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage())

                    {

                        MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2));

                        itemstack2 = null;

                    }

 

                    if (itemstack2 != null && (!itemstack1.getItem().doesContainerItemLeaveCraftingGrid(itemstack1) || !this.thePlayer.inventory.addItemStackToInventory(itemstack2)))

                    {

                        if (this.craftMatrix.getStackInSlot(i) == null)

                        {

                            this.craftMatrix.setInventorySlotContents(i, itemstack2);

                        }

                        else

                        {

                            this.thePlayer.dropPlayerItem(itemstack2);

                        }

                    }

                }

            }

        }

    }

}

 

 

 

Thanks already :)

 

Link to post
Share on other sites

For your first question, what would absorption be ? Is it more defense ?

 

Second,

In GuiBoneBench:

public GuiBoneBench(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
    {
        super(new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5));
    }

In GuiHandler:

switch(id)
      {
         case 1: return id == 1 && world.getBlockId(x, y, z) == Mainclass.BoneBench.blockID ? new ContainerBoneBench(player.inventory, world, x, y, z) : null;
      
      } 

Looks strange to have two containers for the same Gui.

 

Also, SlotBoneBench and BoneBenchRecipeSorter look like identical copies of vanilla classes. Can't you use the original ones ?

Link to post
Share on other sites

Second,

In GuiBoneBench:

public GuiBoneBench(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
    {
        super(new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5));
    }

In GuiHandler:

switch(id)
      {
         case 1: return id == 1 && world.getBlockId(x, y, z) == Mainclass.BoneBench.blockID ? new ContainerBoneBench(player.inventory, world, x, y, z) : null;
      
      } 

Looks strange to have two containers for the same Gui.

 

Also, SlotBoneBench and BoneBenchRecipeSorter look like identical copies of vanilla classes. Can't you use the original ones ?

Thanks, that worked perfectly! Pretty much a derp from me :P

 

But I still need help with the armor

Link to post
Share on other sites

I have made some nice Armour Set Effects, this can easily be adapted to something where you can add something like in case only 1 piece is worn give 2 hearts, when theres 2 add 4. This is how i added my custom armour effects:


 

In order to use that you should have a CommonTickHandler setup (or whatever you want to call it)

 

 

package packagename

import whatever imports you need

public class YourCommonTickHandler implements ITickHandler
{
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
playerTick((EntityPlayer) tickData[0]);
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
// Nothing in here unless you want it to do something when the tick ends...
}

@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.PLAYER);
}

@Override
pblic String getLabel()
{
return null;
}

// This is the important method, that is where you put your armour effect code in.
public void playerTick(EntityPlayer player)
{
// Armour effect example
if(player.getCurrentArmor(0) != null)
{
if(player.getCurrentArmor(0).itemID == yourBoots.itemID)
{
player.addPotionEffect(new PotionEffect(potion.jump.getId(), 5, 4));
}
}
}

 

 

 

Hope it helped!

Link to post
Share on other sites

I have made some nice Armour Set Effects, this can easily be adapted to something where you can add something like in case only 1 piece is worn give 2 hearts, when theres 2 add 4. This is how i added my custom armour effects:


 

In order to use that you should have a CommonTickHandler setup (or whatever you want to call it)

 

 

package packagename

import whatever imports you need

public class YourCommonTickHandler implements ITickHandler
{
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
playerTick((EntityPlayer) tickData[0]);
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
// Nothing in here unless you want it to do something when the tick ends...
}

@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.PLAYER);
}

@Override
pblic String getLabel()
{
return null;
}

// This is the important method, that is where you put your armour effect code in.
public void playerTick(EntityPlayer player)
{
// Armour effect example
if(player.getCurrentArmor(0) != null)
{
if(player.getCurrentArmor(0).itemID == yourBoots.itemID)
{
player.addPotionEffect(new PotionEffect(potion.jump.getId(), 5, 4));
}
}
}

 

 

 

Hope it helped!

The first code doesnt have code :P

Link to post
Share on other sites

Oops, well thats not supposed to be there anyway xD, also i forgot to say that you have to register the handler in your main mod classs:

TickRegistry.registerTickHandler(new YourCommonTickHandler(), Side.SERVER);

Okay, so I got the boots to work, but when I try to do it so that when you also wear the leggings it gives you two more hearts it doesn't work.

Here's my code (the leggings are not working)

package assets.caves_of_millarki.client;

import java.util.EnumSet;

import assets.caves_of_millarki.common.Mainclass;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.PotionEffect;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;


public class MillarkiTickHandler implements ITickHandler
{
private static int absorption = 22;
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
playerTick((EntityPlayer) tickData[0]);
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
// Nothing in here unless you want it to do something when the tick ends...
}

@Override
public EnumSet<TickType> ticks()
{
return EnumSet.of(TickType.PLAYER);
}

@Override
public String getLabel()
{
return null;
}

// This is the important method, that is where you put your armour effect code in.
public void playerTick(EntityPlayer player)
{

// Armour effect example
if(player.getCurrentArmor(0) != null)
{
if(player.getCurrentArmor(0).itemID == Mainclass.PureStoneBoots.itemID)
{
player.addPotionEffect(new PotionEffect(absorption, 5, 0));
}
{
if(player.getCurrentArmor(0).itemID == Mainclass.PureStoneLegs.itemID)
{
player.addPotionEffect(new PotionEffect(absorption, 5, 0));
}
}
}}}

Link to post
Share on other sites

What it is doing right now is, it checks whether your boots is on -> then adds that potion effect. Then it checks whether your chestplate is on -> ads the same potion effect (they don't stack). So what you want to do is something like this:

// This is the important method, that is where you put your armour effect code in.
public void playerTick(EntityPlayer player)
{

// Armour effect example
if(player.getCurrentArmor(0) != null)
{
if(player.getCurrentArmor(0).itemID == Mainclass.PureStoneBoots.itemID)
{
player.addPotionEffect(new PotionEffect(absorption, 5, 0));
}
else if(player.getCurrentArmor(0).itemID == Mainclass.PureStoneBoots.itemID && player.getCurrentArmor(1).itemID == Mainclass.PureStoneLegs.itemID) // << notice that getCurrentArmor(0), the 0 is for boots, 1 is for leggings, 2 for chestplate and 3 for helmets.
{
player.addPotionEffect(new PotionEffect(absorption, 5, 1)); // So whenever you wear 1 more piece of armour, you raise its intensity.
}
}
}

Link to post
Share on other sites

What it is doing right now is, it checks whether your boots is on -> then adds that potion effect. Then it checks whether your chestplate is on -> ads the same potion effect (they don't stack). So what you want to do is something like this:

// This is the important method, that is where you put your armour effect code in.
public void playerTick(EntityPlayer player)
{

// Armour effect example
if(player.getCurrentArmor(0) != null)
{
if(player.getCurrentArmor(0).itemID == Mainclass.PureStoneBoots.itemID)
{
player.addPotionEffect(new PotionEffect(absorption, 5, 0));
}
else if(player.getCurrentArmor(0).itemID == Mainclass.PureStoneBoots.itemID && player.getCurrentArmor(1).itemID == Mainclass.PureStoneLegs.itemID) // << notice that getCurrentArmor(0), the 0 is for boots, 1 is for leggings, 2 for chestplate and 3 for helmets.
{
player.addPotionEffect(new PotionEffect(absorption, 5, 1)); // So whenever you wear 1 more piece of armour, you raise its intensity.
}
}
}

Ah, and in the end, the line will be with all 4 items, right?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • https://github.com/DefDaemon/Daemons_Horror_Moon/blob/02a0d917a9738e7f7076865abb4a74de0e97eb3c/src/main/java/com/defdaemon/horrormoon/lists/ToolMaterialList.java#L9 You cannot access your items here yet, the registration has not happened yet. Store the supplier instead of the item.
    • I have a problem about my game keep crashing because of my code. Code: package net.flexstudios.armorytests.items; import com.google.common.collect.Multimap; import net.minecraft.entity.ai.attributes.Attribute; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.*; public class PoweredChestplateItem extends ArmorItem { public PoweredChestplateItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) { super(materialIn, slot, builder); } @Override public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType equipmentSlot) { Multimap<Attribute, AttributeModifier> result = super.getAttributeModifiers(equipmentSlot); result.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Armor dmg", (double)4, AttributeModifier.Operation.ADDITION)); return result; } } A part of the crashing report: Description: Initializing game java.lang.UnsupportedOperationException: null at com.google.common.collect.ImmutableMultimap.put(ImmutableMultimap.java:427) ~[guava-21.0.jar:?] {} at net.flexstudios.armorytests.items.PoweredChestplateItem.func_111205_h(PoweredChestplateItem.java:19) ~[?:beta1.0.0] {re:classloading} at net.minecraftforge.common.extensions.IForgeItem.getAttributeModifiers(IForgeItem.java:77) ~[?:?] {re:classloading} at net.minecraft.item.ItemStack.func_111283_C(ItemStack.java:844) ~[?:?] {re:classloading} at net.minecraft.item.ItemStack.func_82840_a(ItemStack.java:614) ~[?:?] {re:classloading} at net.minecraft.client.Minecraft.lambda$populateSearchTreeManager$7(Minecraft.java:642) ~[?:?]  
    • Done..... https://github.com/DefDaemon/Daemons_Horror_Moon Thnx for the advise
    • First of all, do not use @OnlyIn. The Callable must be in a separate class.
    • Can you explain better? This is my class where i register the blocks and relative itemblocks: package com.ike.tenchest; import com.ike.tenchest.basechest.BaseChestItemStackRenderer; import com.ike.tenchest.colossalchest.ColossalChest; import com.ike.tenchest.colossalchest.ColossalChestPart; import com.ike.tenchest.drillchest.DrillChest; import com.ike.tenchest.invisiblechest.InvisibleChest; import com.ike.tenchest.lootchest.LootChest; import com.ike.tenchest.lootchest.LootChestTileEntity; import com.ike.tenchest.minichest.MiniChest; import com.ike.tenchest.monsterchest.MonsterChest; import com.ike.tenchest.pitfallchest.PitfallChest; import com.ike.tenchest.pocketdimensionchest.PocketDimensionChest; import com.ike.tenchest.pocketdimensionchest.PocketDimensionChestTileEntity; import com.ike.tenchest.smeltingchest.SmeltingChest; import com.ike.tenchest.smeltingchest.SmeltingChestTileEntity; import com.ike.tenchest.teleportchest.TeleportChest; import com.ike.tenchest.teleportchest.TeleportChestTileEntity; import com.ike.tenchest.trapchest.TrapChest; import net.minecraft.block.Block; import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.tileentity.ChestTileEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.IModBusEvent; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import java.util.concurrent.Callable; import java.util.function.Function; import java.util.function.Supplier; /** * @author Ike * @version 1.0A **/ @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Blocks implements IModBusEvent { public static final DeferredRegister<Block> BLOCKS; public static final DeferredRegister<Item> ITEMS; public static final RegistryObject<MiniChest> MINI_CHEST; public static final RegistryObject<SmeltingChest> SMELTING_CHEST; public static final RegistryObject<InvisibleChest> INVISIBLE_CHEST; public static final RegistryObject<TrapChest> TRAP_CHEST; public static final RegistryObject<PitfallChest> PITFALL_CHEST; public static final RegistryObject<DrillChest> DRILL_CHEST; public static final RegistryObject<TeleportChest> TELEPORT_CHEST; public static final RegistryObject<LootChest> LOOT_CHEST; public static final RegistryObject<MonsterChest> MONSTER_CHEST; public static final RegistryObject<PocketDimensionChest> POCKET_DIMENSION_CHEST; public static final RegistryObject<ColossalChest> COLOSSAL_CHEST; public static final RegistryObject<ColossalChestPart> COLOSSAL_CHEST_PART; static { BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, TenChest.MODID); ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, TenChest.MODID); MINI_CHEST = register("mini_chest", MiniChest::new, Blocks::baseChestRenderer); SMELTING_CHEST = register("smelting_chest", SmeltingChest::new, Blocks::smeltingChestRenderer); INVISIBLE_CHEST = register("invisible_chest", InvisibleChest::new, Blocks::baseChestRenderer); TRAP_CHEST = register("trap_chest", TrapChest::new, Blocks::baseChestRenderer); PITFALL_CHEST = register("pitfall_chest", PitfallChest::new, Blocks::baseChestRenderer); DRILL_CHEST = register("drill_chest", DrillChest::new, Blocks::baseChestRenderer); TELEPORT_CHEST = register("teleport_chest", TeleportChest::new, Blocks::teleportChestRenderer); LOOT_CHEST = register("loot_chest", LootChest::new, Blocks::lootChestRenderer); MONSTER_CHEST = register("monster_chest", MonsterChest::new, Blocks::baseChestRenderer); POCKET_DIMENSION_CHEST = register("pocket_dimension_chest", PocketDimensionChest::new, Blocks::pocketDimensionChestRenderer); COLOSSAL_CHEST_PART = register("colossal_chest_part", ColossalChestPart::new); COLOSSAL_CHEST = register("colossal_chest", ColossalChest::new, Blocks::baseChestRenderer); } @OnlyIn(Dist.CLIENT) private static Callable<ItemStackTileEntityRenderer> baseChestRenderer() { return () -> new BaseChestItemStackRenderer(ChestTileEntity::new); } @OnlyIn(Dist.CLIENT) private static Callable<ItemStackTileEntityRenderer> smeltingChestRenderer() { return () -> new BaseChestItemStackRenderer(SmeltingChestTileEntity::new); } @OnlyIn(Dist.CLIENT) private static Callable<ItemStackTileEntityRenderer> teleportChestRenderer() { return () -> new BaseChestItemStackRenderer(TeleportChestTileEntity::new); } @OnlyIn(Dist.CLIENT) private static Callable<ItemStackTileEntityRenderer> lootChestRenderer() { return () -> new BaseChestItemStackRenderer(LootChestTileEntity::new); } @OnlyIn(Dist.CLIENT) private static Callable<ItemStackTileEntityRenderer> pocketDimensionChestRenderer() { return () -> new BaseChestItemStackRenderer(PocketDimensionChestTileEntity::new); } private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) { return register(name, sup, (block) -> item(block, renderMethod)); } private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup) { return register(name, sup, (block) -> item(block)); } private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Function<RegistryObject<T>, Supplier<? extends Item>> itemCreator) { RegistryObject<T> ret = registerNoItem(name, sup); ITEMS.register(name, (Supplier) itemCreator.apply(ret)); return ret; } private static <T extends Block> RegistryObject<T> registerNoItem(String name, Supplier<? extends T> sup) { return BLOCKS.register(name, sup); } private static Supplier<BlockItem> item(RegistryObject<? extends Block> block, Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) { return () -> { BlockItem blockItem = new BlockItem(block.get(), (new Item.Properties().tab(TenChest.MOD_GROUP).setISTER(renderMethod))); return blockItem; }; } private static Supplier<BlockItem> item(RegistryObject<? extends Block> block) { return () -> new BlockItem(block.get(), (new Item.Properties()));//.tab(TenChest.MOD_GROUP))); } } How can i separate the process between server and client?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.