Java Code Examples for net.minecraft.entity.EntityLivingBase#getItemStackFromSlot()

The following examples show how to use net.minecraft.entity.EntityLivingBase#getItemStackFromSlot() . These examples are extracted from open source projects. 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
public static void renderArmorLayer(LayerArmorBase<ModelBase> layer, EntityLivingBase entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale, EntityEquipmentSlot slotIn) {
    ItemStack itemStack = entity.getItemStackFromSlot(slotIn);

    if (isArmorItem(itemStack, slotIn)) {
        IArmorItem armorItem = (IArmorItem) itemStack.getItem();
        ModelBase armorModel = layer.getModelFromSlot(slotIn);
        if (armorModel instanceof ModelBiped) {
            armorModel = ForgeHooksClient.getArmorModel(entity, itemStack, slotIn, (ModelBiped) armorModel);
        }
        armorModel.setModelAttributes(layer.renderer.getMainModel());
        armorModel.setLivingAnimations(entity, limbSwing, limbSwingAmount, partialTicks);
        layer.setModelSlotVisible(armorModel, slotIn);

        GlStateManager.enableBlend();
        GlStateManager.blendFunc(SourceFactor.ONE, DestFactor.ONE_MINUS_SRC_ALPHA);

        int layers = armorItem.getArmorLayersAmount(itemStack);
        for (int layerIndex = 0; layerIndex < layers; layerIndex++) {
            int i = armorItem.getArmorLayerColor(itemStack, layerIndex);
            float f = (float) (i >> 16 & 255) / 255.0F;
            float f1 = (float) (i >> 8 & 255) / 255.0F;
            float f2 = (float) (i & 255) / 255.0F;
            GlStateManager.color(f, f1, f2, 1.0f);
            String type = layerIndex == 0 ? null : "layer_" + layerIndex;
            layer.renderer.bindTexture(getArmorTexture(entity, itemStack, slotIn, type));
            armorModel.render(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale);
        }
        if (itemStack.hasEffect()) {
            LayerArmorBase.renderEnchantedGlint(layer.renderer, entity, armorModel, limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale);
        }
    }
}
 
Example 2
@Override
public boolean isImmune(EntityLivingBase player) {

	//Checks if player is wearing spacesuit or anything that extends ItemSpaceArmor

	ItemStack feet = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
	ItemStack leg = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS /*so hot you can fry an egg*/ );
	ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
	ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);

	return (player instanceof EntityPlayer && ((((EntityPlayer)player).capabilities.isCreativeMode) || ((EntityPlayer)player).isSpectator()))
			|| player.getRidingEntity() instanceof EntityRocketBase || player.getRidingEntity() instanceof EntityElevatorCapsule ||
			protectsFrom(helm) && protectsFrom(leg) && protectsFrom(feet) && protectsFrom(chest);
}
 
Example 3
Source Project: AdvancedRocketry   File: AtmosphereVacuum.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isImmune(EntityLivingBase player) {

	
	//Checks if player is wearing spacesuit or anything that extends ItemSpaceArmor

	ItemStack feet = player.getItemStackFromSlot(EntityEquipmentSlot.FEET);
	ItemStack leg = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS /*so hot you can fry an egg*/ );
	ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
	ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);

	return (player instanceof EntityPlayer && ((((EntityPlayer)player).capabilities.isCreativeMode) || ((EntityPlayer)player).isSpectator()))
			|| player.getRidingEntity() instanceof EntityRocketBase || player.getRidingEntity() instanceof EntityElevatorCapsule ||
			protectsFrom(helm) && protectsFrom(leg) && protectsFrom(feet) && protectsFrom(chest);
	}
 
Example 4
Source Project: AdvancedRocketry   File: AtmosphereLowOxygen.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isImmune(EntityLivingBase player) {

	//Checks if player is wearing spacesuit or anything that extends ItemSpaceArmor
	ItemStack chest = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
	ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);

	return (player instanceof EntityPlayer && ((((EntityPlayer)player).capabilities.isCreativeMode) || ((EntityPlayer)player).isSpectator()))
			|| player.getRidingEntity() instanceof EntityRocketBase || player.getRidingEntity() instanceof EntityElevatorCapsule ||
			protectsFrom(helm) && protectsFrom(chest);
}
 
Example 5
Source Project: WearableBackpacks   File: ProxyCommon.java    License: MIT License 5 votes vote down vote up
/** Called when a mob spawns with a backpack with a 1 tick delay. */
private void onSpawnedWith(EntityLivingBase entity, BackpackCapability backpack, BackpackEntry entry) {
	ItemStack stack = new ItemStack(entry.getBackpackItem());

	if (entry.colorRange != null) // Set a random color!
		NbtUtils.set(stack, entry.colorRange.getRandom(), "display", "color");

	// Set damage to a random amount (25% - 75%).
	int maxDamage = stack.getMaxDamage();
	int damage = maxDamage / 4 + ((maxDamage / 2 > 0)
		? entity.world.rand.nextInt(maxDamage / 2) : 0);
	stack.setItemDamage(damage);

	if (BackpackHelper.equipAsChestArmor) {
		// If the entity spawned with enchanted armor,
		// then move over all compatible enchantments.
		ItemStack armor = entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
		if ((armor != null) && armor.isItemEnchanted()) {
			NBTTagList enchList = armor.getEnchantmentTagList();
			for (int i = 0; i < enchList.tagCount(); ++i) {
				NBTTagCompound enchTag = enchList.getCompoundTagAt(i);
				Enchantment enchantment = Enchantment.getEnchantmentByID(enchTag.getShort("id"));
				// If the enchantment doesn't work with the backpack, remove it.
				if (!enchantment.canApply(stack)) enchList.removeTag(i--);
			}
			if (enchList.tagCount() > 0)
				NbtUtils.set(stack, enchList, "ench");
		}
	}

	IBackpackType type = entry.getBackpackItem();
	IBackpackData data = type.createBackpackData(stack);
	BackpackHelper.setEquippedBackpack(entity, stack, data);
	type.onSpawnedWith(entity, backpack, entry.lootTable);
	backpack.spawnWith  = null;
	backpack.mayDespawn = true;
}
 
Example 6
Source Project: WearableBackpacks   File: ItemBackpack.java    License: MIT License 5 votes vote down vote up
@Override
public void onSpawnedWith(EntityLivingBase entity, IBackpack backpack, String lootTable) {
	
	// If backpack is equipped in chestplate slot, set drop chance to 100%.
	if ((entity instanceof EntityLiving) &&
	    (entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST) == backpack.getStack()))
		((EntityLiving)entity).setDropChance(EntityEquipmentSlot.CHEST, 1.0F);
	
	// Set backpack's loot table.
	IBackpackData data = backpack.getData();
	if ((lootTable != null) && (data instanceof BackpackDataItems))
		((BackpackDataItems)data).setLootTable(lootTable, entity.world.rand.nextLong());
	
}
 
Example 7
public static boolean shouldNotRenderHeadItem(EntityLivingBase entityLivingBase) {
    ItemStack itemStack = entityLivingBase.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    return isArmorItem(itemStack, EntityEquipmentSlot.HEAD);
}