net.minecraft.item.ItemArmor Java Examples

The following examples show how to use net.minecraft.item.ItemArmor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoArmorModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
private int findArmorSlot(EntityEquipmentSlot type) {
    int slot = -1;
    float damage = 0;

    for (int i = 9; i < 45; i++) {
        final ItemStack s = Minecraft.getMinecraft().player.inventoryContainer.getSlot(i).getStack();
        if (s != null && s.getItem() != Items.AIR) {

            if (s.getItem() instanceof ItemArmor) {
                final ItemArmor armor = (ItemArmor) s.getItem();
                if (armor.armorType == type) {
                    final float currentDamage = (armor.damageReduceAmount + EnchantmentHelper.getEnchantmentLevel(Enchantments.PROTECTION, s));

                    final boolean cursed = this.curse.getValue() ? (EnchantmentHelper.hasBindingCurse(s)) : false;

                    if (currentDamage > damage && !cursed) {
                        damage = currentDamage;
                        slot = i;
                    }
                }
            }
        }
    }

    return slot;
}
 
Example #2
Source File: TileChemicalReactor.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void registerRecipes() {
	//Chemical Reactor
	RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, new Object[] {new ItemStack(AdvancedRocketryItems.itemCarbonScrubberCartridge,1, 0), new ItemStack(Items.COAL, 1, 1)}, 40, 20, new ItemStack(AdvancedRocketryItems.itemCarbonScrubberCartridge, 1, AdvancedRocketryItems.itemCarbonScrubberCartridge.getMaxDamage()));
	RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, new ItemStack(Items.DYE,5,0xF), 100, 1, Items.BONE, new FluidStack(AdvancedRocketryFluids.fluidNitrogen, 10));
	RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, new FluidStack(AdvancedRocketryFluids.fluidRocketFuel, 20), 100, 10, new FluidStack(AdvancedRocketryFluids.fluidOxygen, 10), new FluidStack(AdvancedRocketryFluids.fluidHydrogen, 10));

	if(Configuration.enableOxygen) {
		for(ResourceLocation key : Item.REGISTRY.getKeys()) {
			Item item = Item.REGISTRY.getObject(key);

			if(item instanceof ItemArmor && !(item instanceof ItemSpaceArmor)) {
				ItemStack enchanted = new ItemStack(item);
				enchanted.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);

				if(((ItemArmor)item).armorType == EntityEquipmentSlot.CHEST)
					RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, enchanted, 100, 10, item, "gemDiamond", new ItemStack(AdvancedRocketryItems.itemPressureTank, 1, 3));
				else
					RecipesMachine.getInstance().addRecipe(TileChemicalReactor.class, enchanted, 100, 10, item, "gemDiamond");

			}
		}
	}
}
 
Example #3
Source File: ClientProxy.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void init() {

	//Colorizers
	CrystalColorizer colorizer = new CrystalColorizer();
	Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler((IBlockColor)colorizer, new Block[] {AdvancedRocketryBlocks.blockCrystal});
	Minecraft.getMinecraft().getItemColors().registerItemColorHandler((IItemColor)colorizer,  Item.getItemFromBlock(AdvancedRocketryBlocks.blockCrystal));

	Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor()
       {
           public int getColorFromItemstack(ItemStack stack, int tintIndex)
           {
               return tintIndex > 0 ? -1 : ((ItemArmor)stack.getItem()).getColor(stack);
           }
       }, AdvancedRocketryItems.itemSpaceSuit_Boots, AdvancedRocketryItems.itemSpaceSuit_Chest, AdvancedRocketryItems.itemSpaceSuit_Helmet, AdvancedRocketryItems.itemSpaceSuit_Leggings);
	
	AdvancedRocketry.materialRegistry.init();
}
 
Example #4
Source File: NotificationDisplay.java    From Cyberware with MIT License 6 votes vote down vote up
@SideOnly(Side.CLIENT)
private boolean updateLightArmor()
{
	for (ItemStack stack : inv)
	{
		if (stack != null && stack.getItem() instanceof ItemArmor)
		{
			if (((ItemArmor) stack.getItem()).getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST) > 4)
			{
				return false;
			}
		}
		else if (stack != null && stack.getItem() instanceof ISpecialArmor)
		{
			if (((ISpecialArmor) stack.getItem()).getProperties(Minecraft.getMinecraft().thePlayer, stack, DamageSource.cactus, 1, 1).AbsorbRatio * 25D > 4)
			{
				return false;
			}
		}
	}
	return true;
}
 
Example #5
Source File: GuiArmorSelection.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void initGui() 
{
	EntityPlayer player = this.mc.player;
	ItemStack stack = player.inventory.getCurrentItem();
	NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
	
	if (player != null && stack != null && nbt != null && stack.getItem() instanceof ItemArmor)
	{
		attributes = new GuiButton[ArmorAttribute.ARMOR_ATTRIBUTES.size()];
		
		for (int i = 0; i < attributes.length; i++)
		{
			attributes[i] = new GuiButton(i, width / 2 - 147, 60 + (i * 20), 75, 20, ArmorAttribute.ARMOR_ATTRIBUTES.get(i).getName(nbt));
			this.buttonList.add(attributes[i]);
			attributes[i].enabled = false;
		}
	}
}
 
Example #6
Source File: GuiArmorSelection.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
protected void actionPerformed(GuiButton button) throws IOException 
{
	EntityPlayerSP player = mc.player;
	ItemStack stack = player.inventory.getCurrentItem();
	NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
	
	if (player != null && stack != null && nbt != null)
	{
		if (Experience.getAttributeTokens(nbt) > 0)
		{
			if (stack.getItem() instanceof ItemArmor)
			{
				for (int i = 0; i < attributes.length; i++)
				{
					if (button == attributes[i])
						Levels.network.sendToServer(new PacketAttributeSelection(i));
				}
			}
		}
	}
}
 
Example #7
Source File: WrappedArmorMaterialImpl.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public ItemArmor.ArmorMaterial getArmorMaterial()
{
    if (material != null)
        return material;

    if (vanillaMaterials.containsKey(name))
    {
        material = vanillaMaterials.get(name);
    } else
    {
        for (ItemArmor.ArmorMaterial mat : ItemArmor.ArmorMaterial.values())
        {
            if (mat.name().equalsIgnoreCase(name))
            {
                material = mat;
                break;
            }
        }
    }

    return material;
}
 
Example #8
Source File: EventTooltip.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onTooltip(ItemTooltipEvent event)
{
	ArrayList<String> tooltip = (ArrayList<String>) event.getToolTip();
	ItemStack stack = event.getItemStack();
	NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
	
	if (stack != null && nbt != null)
	{
		if (stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemBow || stack.getItem() instanceof ItemShield || stack.getItem() instanceof ItemTool)
		{
			Rarity rarity = Rarity.getRarity(nbt);
			
			if (rarity != Rarity.DEFAULT)
			{
				addTooltips(tooltip, stack, nbt);
			}
		}
	}
}
 
Example #9
Source File: EventCreateWeapon.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SubscribeEvent
public void onCreateWeapon(PlayerTickEvent event)
{
	if (!event.player.getEntityWorld().isRemote)
	{
		if (event.phase == Phase.START)
		{
			for (ItemStack stack : event.player.inventory.mainInventory)
			{
				if (stack != null && (stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemBow || stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemShield))
				{
					create(stack, event.player);
				}
			}
		}
	}
}
 
Example #10
Source File: ExtraInventory.java    From ForgeHax with MIT License 6 votes vote down vote up
private static int getItemValue(ItemStack stack, boolean loopGuard) {
  Item item = stack.getItem();
  if (stack.isEmpty()) {
    return 0;
  } else if (item instanceof ItemArmor
      || item instanceof ItemPickaxe
      || item instanceof ItemAxe
      || item instanceof ItemSword
      || item instanceof ItemFood
      || item instanceof ItemArrow
      || Items.TOTEM_OF_UNDYING.equals(item)) {
    return 100 * stack.getCount(); // very important
  } else if (item instanceof ItemShulkerBox) {
    return 5
        + (loopGuard
        ? 0
        : Utils.getShulkerContents(stack)
            .stream()
            .mapToInt(ExtraInventory::getItemValueSafe)
            .sum());
  } else {
    return 5;
  }
}
 
Example #11
Source File: AutoArmorHack.java    From ForgeWurst with GNU General Public License v3.0 6 votes vote down vote up
private int getArmorValue(ItemArmor item, ItemStack stack)
{
	int armorPoints = item.damageReduceAmount;
	int prtPoints = 0;
	int armorToughness = (int)item.toughness;
	int armorType = item.getArmorMaterial()
		.getDamageReductionAmount(EntityEquipmentSlot.LEGS);
	
	if(useEnchantments.isChecked())
	{
		Enchantment protection = Enchantments.PROTECTION;
		int prtLvl =
			EnchantmentHelper.getEnchantmentLevel(protection, stack);
		
		EntityPlayerSP player = WMinecraft.getPlayer();
		DamageSource dmgSource = DamageSource.causePlayerDamage(player);
		prtPoints = protection.calcModifierDamage(prtLvl, dmgSource);
	}
	
	return armorPoints * 5 + prtPoints * 3 + armorToughness + armorType;
}
 
Example #12
Source File: EventSoulBound.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SubscribeEvent
public void onPlayerDeath(PlayerDropsEvent event)
{
	EntityPlayer player = event.getEntityPlayer();
	Item item;
	
	for (int i = 0; i < event.getDrops().size(); i++)
	{
		item = event.getDrops().get(i).getEntityItem().getItem();
		
		if (item != null && (item instanceof ItemSword || item instanceof ItemShield || item instanceof ItemArmor || item instanceof ItemBow))
		{
			ItemStack stack = event.getDrops().get(i).getEntityItem();
			NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
			
			if (nbt != null)
			{
				if (WeaponAttribute.SOUL_BOUND.hasAttribute(nbt) || ArmorAttribute.SOUL_BOUND.hasAttribute(nbt) || BowAttribute.SOUL_BOUND.hasAttribute(nbt) || ShieldAttribute.SOUL_BOUND.hasAttribute(nbt))
				{
					event.getDrops().remove(i);
					player.inventory.addItemStackToInventory(stack);
				}
			}
		}
	}
}
 
Example #13
Source File: ContainerCreativeInv.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
    ItemStack transferredStack = null;
    Slot slot = (Slot) inventorySlots.get(slotIndex);

    if (slot != null && slot.getHasStack()) {
        ItemStack stack = slot.getStack();
        transferredStack = stack.copy();

        if (stack.getItem() instanceof ItemArmor) {
            ItemArmor armor = (ItemArmor) stack.getItem();
            if (!getSlot(90 + armor.armorType).getHasStack()) {
                getSlot(90 + armor.armorType).putStack(transferredStack);
                slot.putStack(null);
                return transferredStack;
            }
        }

        if (slotIndex < 54) {
            if (!this.mergeItemStack(stack, 54, 90, true))
                return null;
        } else if (!this.mergeItemStack(stack, 0, 54, false)) {
            return null;
        }

        if (stack.stackSize == 0)
            slot.putStack(null);
        else
            slot.onSlotChanged();
    }

    return transferredStack;
}
 
Example #14
Source File: ItemArmorMetaProvider.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Override
public Object getMeta(ItemArmor target, ItemStack stack) {
	Map<String, Object> result = Maps.newHashMap();
	result.put("material", target.getArmorMaterial());
	result.put("type", convertArmorType(target.armorType));

	final int color = target.getColor(stack);
	if (color >= 0) result.put("color", color);

	return result;
}
 
Example #15
Source File: EventInput.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent event)
{
	KeyBinding l = ClientProxy.keyBindingL;
	Minecraft mc = Minecraft.getMinecraft();
	EntityPlayer player = mc.player;
	
	if (player != null)
	{
		ItemStack stack = player.inventory.getCurrentItem();
		
		if (stack != null)
		{
			Item current = stack.getItem();
			
			if (current != null)
			{
				if (current instanceof ItemSword || current instanceof ItemTool || current instanceof ItemArmor || current instanceof ItemBow || current instanceof ItemShield)
				{
					if (l.isPressed())
					{
						player.openGui(Levels.instance, GuiHandler.ITEM_INFORMATION, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
					}
				}
			}
		}
	}
}
 
Example #16
Source File: EntityFallenKnight.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
private void addRandomArmor() {

    float occupiedDiffcultyMultiplier = EntityUtil.getDifficultyMultiplierForLocation(world, posX, posY, posZ);

    int equipmentLevel = getRandomEquipmentLevel(occupiedDiffcultyMultiplier);
    int armorLevel = equipmentLevel;
    if(armorLevel == 1) {
      //Skip gold armor, I don't like it
      armorLevel++;
    }
    float chancePerPiece = isHardDifficulty() ? Config.fallenKnightChancePerArmorPieceHard
        : Config.fallenKnightChancePerArmorPiece;
    chancePerPiece *= (1 + occupiedDiffcultyMultiplier); //If we have the max occupied factor, double the chance of improved armor

    for(EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
      ItemStack itemStack = getItemStackFromSlot(slot);
      if(itemStack.isEmpty() && rand.nextFloat() <= chancePerPiece) {
        Item item = EntityLiving.getArmorByChance(slot, armorLevel);
        if(item != null) {
          ItemStack stack = new ItemStack(item);
          if(armorLevel == 0) {
            ((ItemArmor) item).setColor(stack, 0);
          }          
          setItemStackToSlot(slot, stack);
        }
      }
    }
    if(rand.nextFloat() > Config.fallenKnightRangedRatio) {
      setItemStackToSlot(EntityEquipmentSlot.MAINHAND, getSwordForLevel(equipmentLevel));
      if(Math.random() <= Config.fallenKnightChanceShield) {
        setItemStackToSlot(EntityEquipmentSlot.OFFHAND, getShieldForLevel(getRandomEquipmentLevel()));
      }
    } else {
      setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.BOW));
    }
  }
 
Example #17
Source File: GuiArmorSelection.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) 
{
	this.drawDefaultBackground();
	super.drawScreen(mouseX, mouseY, partialTicks);
	
	EntityPlayer player = this.mc.player;
	ItemStack stack = player.inventory.getCurrentItem();
	NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
	
	if (player != null && stack != null &&  nbt != null && stack.getItem() instanceof ItemArmor)
	{
		drawCenteredString(fontRendererObj, I18n.format("levels.misc.attributes"), width / 2, 20, 0xFFFFFF);
		drawCenteredString(fontRendererObj, I18n.format("levels.misc.attributes.tokens") + ": " + Experience.getAttributeTokens(nbt), width / 2 - 112, 40, 0xFFFFFF);
		drawCenteredString(fontRendererObj, I18n.format("levels.misc.attributes.current"), width / 2 + 112, 40, 0xFFFFFF);
		
		int k = -1;
		
		for (int i = 0; i < ArmorAttribute.ARMOR_ATTRIBUTES.size(); i++)
		{
			if (ArmorAttribute.ARMOR_ATTRIBUTES.get(i).hasAttribute(nbt))
			{
				k++;
				drawCenteredString(fontRendererObj, ArmorAttribute.ARMOR_ATTRIBUTES.get(i).getName(nbt), width / 2 + 112, 60 + (10 * k), ArmorAttribute.ARMOR_ATTRIBUTES.get(i).getHex());
			}
		}
		
		displayButtons(nbt);
		drawTooltips(nbt, mouseX, mouseY);
	}
}
 
Example #18
Source File: ItemPneumaticArmor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public ItemPneumaticArmor(String textureLocation, ItemArmor.ArmorMaterial par2EnumArmorMaterial, int par3,
        int par4, int volume, int maxAir){
    super(par2EnumArmorMaterial, par3, par4);
    this.textureLocation = textureLocation;
    this.volume = volume;
    setMaxDamage(maxAir);
    setCreativeTab(PneumaticCraft.tabPneumaticCraft);
}
 
Example #19
Source File: GuiItemInformation.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
protected void actionPerformed(GuiButton button) throws IOException 
{
	EntityPlayerSP player = mc.player;
	
	if (player != null)
	{
		ItemStack stack = player.inventory.getCurrentItem();
		
		if (stack != null)
		{
			if (button == selection)
			{
				if (stack.getItem() instanceof ItemSword)
				{
					player.openGui(Levels.instance, GuiHandler.WEAPON_ATTRIBUTES, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
				}
				else if (stack.getItem() instanceof ItemArmor)
				{
					player.openGui(Levels.instance, GuiHandler.ARMOR_ATTRIBUTES, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
				}
				else if (stack.getItem() instanceof ItemBow)
				{
					player.openGui(Levels.instance, GuiHandler.BOW_ATTRIBUTES, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
				}
				else if (stack.getItem() instanceof ItemShield)
				{
					player.openGui(Levels.instance, GuiHandler.SHIELD_ATTRIBUTES, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
				}
				else if (stack.getItem() instanceof ItemTool)
				{
					//player.openGui(Levels.instance, GuiHandler., player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
				}
			}
		}
	}
}
 
Example #20
Source File: SlotPneumaticArmor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
/**
 * Returns the icon index on items.png that is used as background image of the slot.
 */
public IIcon getBackgroundIconIndex(){
    return ItemArmor.func_94602_b(armorType);
}
 
Example #21
Source File: ItemAirUtils.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean protectsFromSubstance(IAtmosphere atmosphere,
		ItemStack stack, boolean commitProtection) {
	if(stack != null && stack.getItem() instanceof ItemArmor) {
		if(((ItemArmor) stack.getItem()).armorType == EntityEquipmentSlot.CHEST )
			return decrementAir(stack, 1) == 1;
		
		return true;
	}
	return false;
}
 
Example #22
Source File: TileEntityAerialInterface.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j){
    if(i < 4) return true;
    EntityPlayer player = getPlayer();
    if(player == null) return false;
    if(getPressure(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_AERIAL_INTERFACE) {
        if(!dispenserUpgradeInserted || i >= 40 && i <= 43) {
            return i < 40 || itemstack != null && itemstack.getItem() instanceof ItemArmor && ((ItemArmor)itemstack.getItem()).armorType == 43 - i;
        } else {
            if(i == 4 + player.inventory.getSizeInventory() && getFoodValue(itemstack) > 0) {
                int foodValue = getFoodValue(itemstack);
                int curFoodLevel = player.getFoodStats().getFoodLevel();
                int feedMode = this.feedMode;
                if(feedMode == 2) {
                    feedMode = player.getMaxHealth() - player.getHealth() > 0 ? 1 : 0;
                }
                switch(feedMode){
                    case 0:
                        return 20 - curFoodLevel >= foodValue * itemstack.stackSize;
                    case 1:
                        return 20 - curFoodLevel >= foodValue * (itemstack.stackSize - 1) + 1;
                }
            }
            return false;
        }
    } else {
        return false;
    }
}
 
Example #23
Source File: TileChemicalReactor.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void consumeItemsSpecial(IRecipe recipe) {
	List<List<ItemStack>> ingredients = recipe.getIngredients();

	for(int ingredientNum = 0;ingredientNum < ingredients.size(); ingredientNum++) {

		List<ItemStack> ingredient = ingredients.get(ingredientNum);

		ingredientCheck:
		for(IInventory hatch : itemInPorts) {
			for(int i = 0; i < hatch.getSizeInventory(); i++) {
				ItemStack stackInSlot = hatch.getStackInSlot(i);
				for (ItemStack stack : ingredient) {
					if(stackInSlot != null && stackInSlot.getCount() >= stack.getCount() && stackInSlot.isItemEqual(stack)) {
						ItemStack stack2 = hatch.decrStackSize(i, stack.getCount());
						
						if(stack2.getItem() instanceof ItemArmor)
						{
							stack2.addEnchantment(AdvancedRocketryAPI.enchantmentSpaceProtection, 1);
							List<ItemStack> list = new LinkedList<ItemStack>();
							list.add(stack2);
							setOutputs(list);
						}
						
						hatch.markDirty();
						world.notifyBlockUpdate(pos, world.getBlockState(((TileEntity)hatch).getPos()),  world.getBlockState(((TileEntity)hatch).getPos()), 6);
						break ingredientCheck;
					}
				}
			}
		}
	}
}
 
Example #24
Source File: TileSuitWorkStation.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
	
	return (slot == 0 && stack.getItem() instanceof IModularArmor) || 
			(!inventory.getStackInSlot(0).isEmpty() && inventory.getStackInSlot(0).getItem() instanceof IModularArmor && slot != 0 && stack.getItem() instanceof IArmorComponent && 
			((IArmorComponent)stack.getItem()).isAllowedInSlot(stack, ((ItemArmor)inventory.getStackInSlot(0).getItem()).armorType) && slot - 1 < ((IModularArmor)inventory.getStackInSlot(0).getItem()).getNumSlots(inventory.getStackInSlot(0))
			&& ((IModularArmor)inventory.getStackInSlot(0).getItem()).isItemValidForSlot(stack, slot - 1) );
}
 
Example #25
Source File: ContainerCreativeInv.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotIndex) {
    ItemStack transferredStack = ItemStack.EMPTY;
    Slot slot = inventorySlots.get(slotIndex);

    if (slot != null && slot.getHasStack()) {
        ItemStack stack = slot.getStack();
        transferredStack = stack.copy();

        if (stack.getItem() instanceof ItemArmor) {
            ItemArmor armor = (ItemArmor) stack.getItem();
            if (!getSlot(90 + armor.armorType.getIndex()).getHasStack()) {
                getSlot(90 + armor.armorType.getIndex()).putStack(transferredStack);
                slot.putStack(ItemStack.EMPTY);
                return transferredStack;
            }
        }

        if (slotIndex < 54) {
            if (!this.mergeItemStack(stack, 54, 90, true)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.mergeItemStack(stack, 0, 54, false)) {
            return ItemStack.EMPTY;
        }

        if (stack.getCount() == 0) {
            slot.putStack(ItemStack.EMPTY);
        } else {
            slot.onSlotChanged();
        }
    }

    return transferredStack;
}
 
Example #26
Source File: MixinLayerArmorBase.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderLayer", at = @At("HEAD"), cancellable = true)
private void preRenderLayer(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks,
                            float netHeadYaw, float headPitch, float scale, int armorSlot, CallbackInfo ci) {
    ItemStack itemstack = this.getCurrentArmor(entitylivingbaseIn, armorSlot);

    if (itemstack != null && itemstack.getItem() instanceof ItemArmor) {
        Item item = itemstack.getItem();
        if (Settings.HIDE_LEATHER_ARMOR &&
            (item == Items.leather_boots || item == Items.leather_leggings || item == Items.leather_chestplate || item == Items.leather_helmet)) {
            ci.cancel();
        }
    }
}
 
Example #27
Source File: OnlineCraft.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public CraftingGuiInventoryContainer(EntityPlayer basePlayer) {
    this.addSlotToContainer(new SlotCrafting(basePlayer, this.craftMatrix, this.craftResult, 0, -2000, -2000));
    for (int i = 0; i < 4; ++i) {
        this.addSlotToContainer(new Slot(this.craftMatrix, i, -2000, -2000));
    }
    for (int i = 0; i < 4; ++i) {
        final int k = i;
        this.addSlotToContainer(new Slot(basePlayer.inventory, basePlayer.inventory.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
            @Override
            public int getSlotStackLimit() {
                return 1;
            }

            @Override
            public boolean isItemValid(ItemStack p_75214_1_) {
                if (p_75214_1_ == null) {
                    return false;
                }
                return p_75214_1_.getItem().isValidArmor(p_75214_1_, k, Wrapper.INSTANCE.player());
            }

            @Override
            public IIcon getBackgroundIconIndex() {
                return ItemArmor.func_94602_b(k);
            }
        });
    }
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 9; ++j) {
            this.addSlotToContainer(new Slot(basePlayer.inventory, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
        }
    }
    for (int i = 0; i < 9; ++i) {
        this.addSlotToContainer(new Slot(basePlayer.inventory, i, 8 + i * 18, 142));
    }
    this.onCraftMatrixChanged(this.craftMatrix);
}
 
Example #28
Source File: WrappedArmorMaterialDeserializerTest.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void fromString()
{
    Map<String, WrappedArmorMaterial> map = gson.fromJson("{ \"material\":\"iron\" }", new TypeToken<Map<String, WrappedArmorMaterial>>() {}.getType());

    ItemArmor.ArmorMaterial material = map.get("material").getArmorMaterial();
    assertSame(ItemArmor.ArmorMaterial.IRON, material);
}
 
Example #29
Source File: EntitySentry.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected ItemStack colorArmor(ItemStack stack) {
	if (getCivilization() == null) {
		return stack;
	}
	ItemArmor armor = (ItemArmor) stack.getItem();
	armor.setColor(stack, determineColorByCiv());
	return stack;
}
 
Example #30
Source File: ItemSkinUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleHurt(LivingHurtEvent event)
{
	EntityLivingBase e = event.getEntityLiving();

	if (CyberwareAPI.isCyberwareInstalled(e, new ItemStack(this, 1, 1)))
	{
		if (event.getSource() instanceof EntityDamageSource && !(event.getSource() instanceof EntityDamageSourceIndirect))
		{
			for (ItemStack stack : e.getArmorInventoryList())
			{
				if (stack != null && stack.getItem() instanceof ItemArmor)
				{
					if (((ItemArmor) stack.getItem()).getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST) > 4)
					{
						return;
					}
				}
				else if (stack != null && stack.getItem() instanceof ISpecialArmor)
				{
					if (((ISpecialArmor) stack.getItem()).getProperties(e, stack, event.getSource(), event.getAmount(), 1).AbsorbRatio * 25D > 4)
					{
						return;
					}
				}
			}
			
			Random random = e.getRNG();
			Entity attacker = ((EntityDamageSource) event.getSource()).getSourceOfDamage();
			int level = 2;
			if (EnchantmentThorns.shouldHit(3, random))
			{
				if (attacker != null)
				{
					attacker.attackEntityFrom(DamageSource.causeThornsDamage(e), (float) EnchantmentThorns.getDamage(2, random));
				}
			}
		}
	}
}