Java Code Examples for net.minecraft.entity.player.EntityPlayer.getItemStackFromSlot()

The following are Jave code examples for showing how to use getItemStackFromSlot() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pnc-repressurized   File: HUDHandler.java   View Source Code Vote up 7 votes
@SubscribeEvent
public void playerTick(TickEvent.PlayerTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        Minecraft mc = FMLClientHandler.instance().getClient();
        EntityPlayer player = event.player;
        if (player == mc.player) {
            ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
            if (helmetStack.getItem() == Itemss.PNEUMATIC_HELMET) {
                if (player.world.isRemote) {
                    update(mc.player);
                }
            } else {
                CommonHUDHandler.getHandlerForPlayer(player).ticksExisted = 0;
            }
        }
    }
}
 
Example 2
Project: CustomWorldGen   File: ItemArmor.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemStackIn);
    ItemStack itemstack = playerIn.getItemStackFromSlot(entityequipmentslot);

    if (itemstack == null)
    {
        playerIn.setItemStackToSlot(entityequipmentslot, itemStackIn.copy());
        itemStackIn.stackSize = 0;
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemStackIn);
    }
}
 
Example 3
Project: CustomWorldGen   File: ItemElytra.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemStackIn);
    ItemStack itemstack = playerIn.getItemStackFromSlot(entityequipmentslot);

    if (itemstack == null)
    {
        playerIn.setItemStackToSlot(entityequipmentslot, itemStackIn.copy());
        itemStackIn.stackSize = 0;
        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemStackIn);
    }
}
 
Example 4
Project: needtobreath   File: DimensionData.java   View Source Code Vote up 6 votes
public void worldTick(World world) {
    counter--;
    if (counter <= 0) {
        counter = MAXTICKS;

        effectCounter--;
        if (effectCounter <= 0) {
            effectCounter = MAXEFFECTSTICKS;
            handleEffects(world);
        }

        tick(world);

        PacketSendCleanAirToClient message = new PacketSendCleanAirToClient(getCleanAir());
        for (EntityPlayer player : world.playerEntities) {
            ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
            if (!helmet.isEmpty() && helmet.getItem() instanceof InformationGlasses) {
                NTBMessages.INSTANCE.sendTo(message, (EntityPlayerMP) player);
            }
        }
    }
    CleanAirManager.getManager().save();
}
 
Example 5
Project: Backmemed   File: ItemElytra.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);
    ItemStack itemstack1 = worldIn.getItemStackFromSlot(entityequipmentslot);

    if (itemstack1.func_190926_b())
    {
        worldIn.setItemStackToSlot(entityequipmentslot, itemstack.copy());
        itemstack.func_190920_e(0);
        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 6
Project: Backmemed   File: ItemArmor.java   View Source Code Vote up 6 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    EntityEquipmentSlot entityequipmentslot = EntityLiving.getSlotForItemStack(itemstack);
    ItemStack itemstack1 = worldIn.getItemStackFromSlot(entityequipmentslot);

    if (itemstack1.func_190926_b())
    {
        worldIn.setItemStackToSlot(entityequipmentslot, itemstack.copy());
        itemstack.func_190920_e(0);
        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
    else
    {
        return new ActionResult(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 7
Project: pnc-repressurized   File: HUDHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void renderWorldLastEvent(RenderWorldLastEvent event) {
    if (!GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade.coreComponents").checked) return;
    Minecraft mc = FMLClientHandler.instance().getClient();
    EntityPlayer player = mc.player;
    double playerX = player.prevPosX + (player.posX - player.prevPosX) * event.getPartialTicks();
    double playerY = player.prevPosY + (player.posY - player.prevPosY) * event.getPartialTicks();
    double playerZ = player.prevPosZ + (player.posZ - player.prevPosZ) * event.getPartialTicks();

    GL11.glPushMatrix();
    GL11.glTranslated(-playerX, -playerY, -playerZ);
    ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    if (helmetStack.getItem() == Itemss.PNEUMATIC_HELMET) {
        if (((IPressurizable) helmetStack.getItem()).getPressure(helmetStack) > 0F) {
            CommonHUDHandler comHudHandler = CommonHUDHandler.getHandlerForPlayer(player);
            if (comHudHandler.ticksExisted > comHudHandler.getStartupTime()) {

                GL11.glDisable(GL11.GL_TEXTURE_2D);

                for (int i = 0; i < UpgradeRenderHandlerList.instance().upgradeRenderers.size(); i++) {
                    if (comHudHandler.upgradeRenderersInserted[i] && GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade." + UpgradeRenderHandlerList.instance().upgradeRenderers.get(i).getUpgradeName()).checked)
                        UpgradeRenderHandlerList.instance().upgradeRenderers.get(i).render3D(event.getPartialTicks());
                }

                GL11.glEnable(GL11.GL_TEXTURE_2D);

            }
        }
    }
    GL11.glPopMatrix();
}
 
Example 8
Project: pnc-repressurized   File: DroneDebugUpgradeHandler.java   View Source Code Vote up 5 votes
public static boolean enabledForPlayer(EntityPlayer player) {
    ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    if (!helmet.isEmpty()) {
        return enabledForStacks(ItemPneumaticArmor.getUpgradeStacks(helmet));
    } else {
        return false;
    }
}
 
Example 9
Project: pnc-repressurized   File: DroneAIBlockInteraction.java   View Source Code Vote up 5 votes
/**
 * Sends particle spawn packets to any close player that has a charged pneumatic helmet with entity tracker.
 *
 * @param pos
 */
protected void indicateToListeningPlayers(BlockPos pos) {
    for (EntityPlayer player : drone.world().playerEntities) {
        ItemStack helmet = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        if (helmet.getItem() == Itemss.PNEUMATIC_HELMET && ItemPneumaticArmor.getUpgrades(EnumUpgrade.ENTITY_TRACKER, helmet) > 0
                && ((IPressurizable) Itemss.PNEUMATIC_HELMET).getPressure(helmet) > 0) {
            NetworkHandler.sendTo(new PacketSpawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0, 0), (EntityPlayerMP) player);
        }
    }
}
 
Example 10
Project: pnc-repressurized   File: PacketUpdateSearchStack.java   View Source Code Vote up 5 votes
@Override
public void handleServerSide(PacketUpdateSearchStack message, EntityPlayer player) {
    ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    if (!helmetStack.isEmpty()) {
        NBTTagCompound tag = NBTUtil.getCompoundTag(helmetStack, "SearchStack");
        tag.setInteger("itemID", message.itemId);
        tag.setInteger("itemDamage", message.itemDamage);
    }
}
 
Example 11
Project: pnc-repressurized   File: PacketCoordTrackUpdate.java   View Source Code Vote up 5 votes
@Override
public void handleServerSide(PacketCoordTrackUpdate message, EntityPlayer player) {
    ItemStack stack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    if (!stack.isEmpty()) {
        NBTTagCompound tag = NBTUtil.getCompoundTag(stack, "CoordTracker");
        tag.setInteger("dimID", message.dimensionID);
        NBTUtil.setPos(tag, message.pos);
    }
}
 
Example 12
Project: pnc-repressurized   File: CommonHUDHandler.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void tickEnd(TickEvent.PlayerTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        EntityPlayer player = event.player;
        if (this == PneumaticCraftRepressurized.proxy.getCommonHudHandler()) {
            getHandlerForPlayer(player).tickEnd(event);
        } else {
            ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
            if (helmetStack.getItem() == Itemss.PNEUMATIC_HELMET) {
                helmetPressure = ((IPressurizable) helmetStack.getItem()).getPressure(helmetStack);
                if (ticksExisted == 0) {
                    checkHelmetInventory(helmetStack);
                }
                ticksExisted++;
                if (!player.world.isRemote) {
                    if (ticksExisted > getStartupTime() && !player.capabilities.isCreativeMode) {
                        ((IPressurizable) helmetStack.getItem()).addAir(helmetStack, (int) -UpgradeRenderHandlerList.instance().getAirUsage(player, false));
                    }
                }

            } else {
                ticksExisted = 0;
            }
            if (!player.world.isRemote) handleHacking(player);
        }
    }
}
 
Example 13
Project: ExPetrum   File: PlayerManager.java   View Source Code Vote up 5 votes
public static void takeDamage(EntityPlayer player, DamageSource source, float amount)
{
	final float baseAmount = amount;
	IExPPlayer data = IExPPlayer.of(player);
	List<DamageMapping> mappings = ExPDamageMappings.provide(source);
	BodyPart part = WeightedRandom.getRandomItem(player.world.rand, mappings).getPart();
	EntityEquipmentSlot armorCheck = part == BodyPart.HEAD ? EntityEquipmentSlot.HEAD : part == BodyPart.ARM_LEFT || part == BodyPart.ARM_RIGHT || part == BodyPart.BODY ? EntityEquipmentSlot.CHEST : player.world.rand.nextBoolean() ? EntityEquipmentSlot.LEGS : EntityEquipmentSlot.FEET;
	ItemStack armorStack = player.getItemStackFromSlot(armorCheck);
	if (!armorStack.isEmpty())
	{
		amount = handleArmorProtection(player, source, amount, armorStack, part, armorCheck);
	}
	
	float partDamage = player.world.rand.nextFloat();
	// No damage reduction was applied, player has no armor
	if (baseAmount == amount)
	{
		partDamage *= 10;
	}
	
	data.setState(part, Math.max(0, data.getState(part) - partDamage));
	// TODO bleeding, bones breaking
	float actualDamage = amount * (200 + player.world.rand.nextFloat() * 50 - player.world.rand.nextFloat() * 50);
	data.setHealth(data.getCurrentHealth() - actualDamage, true, true);
	
	// Player died
	if (data.getCurrentHealth() <= 0)
	{
		player.sendMessage(source.getDeathMessage(player));
	}
}
 
Example 14
Project: uniquecrops   File: TileShyPlant.java   View Source Code Vote up 5 votes
@Override
public void update() {

	if (worldObj.isRemote)
		return;
	
	if (this.worldObj.getTotalWorldTime() % 10L != 0)
		return;
	
	boolean wasLooking = this.isLooking();
	int range = 10;
	List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.add(-range, -range, -range), pos.add(range, range, range)));
	
	boolean looker = false;
	for (EntityPlayer player : players) {
		ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
		if (helm != null && helm.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
			continue;
		
		RayTraceResult rtr = this.rayTraceFromEntity(worldObj, player, true, range);
		if (rtr != null && rtr.getBlockPos() != null && rtr.getBlockPos().equals(getPos())) {
			looker = true;
			break;
		}
		if (!wasLooking && ((WeepingBells)worldObj.getBlockState(getPos()).getBlock()).isWeepingCropGrown(worldObj.getBlockState(getPos())) && !player.capabilities.isCreativeMode) {
			if (getTarget(worldObj, getPos()).canEntityBeSeen(player)) {
				player.attackEntityFrom(DamageSource.outOfWorld, 1.0F);
			}
		}
	}
	if (looker != wasLooking && !worldObj.isRemote)
		setLooking(looker);
}
 
Example 15
Project: pnc-repressurized   File: HUDHandler.java   View Source Code Vote up 4 votes
private void render2D(float partialTicks) {
    Minecraft minecraft = FMLClientHandler.instance().getClient();
    EntityPlayer player = minecraft.player;
    ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    if (minecraft.inGameHasFocus && helmetStack.getItem() == Itemss.PNEUMATIC_HELMET) {
        ScaledResolution sr = new ScaledResolution(minecraft);
        GL11.glDepthMask(false);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glPushMatrix();
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glColor4d(0, 1, 0, 0.8D);
        CommonHUDHandler comHudHandler = CommonHUDHandler.getHandlerForPlayer(player);
        if (comHudHandler.ticksExisted <= comHudHandler.getStartupTime()) {
            // blockTrackInfo = null;
            gaveEmptyWarning = false;
            gaveNearlyEmptyWarning = false;
            RenderProgressBar.render(sr.getScaledWidth() / 2, 10, sr.getScaledWidth() - 10, 30, -90F, comHudHandler.ticksExisted * 100 / comHudHandler.getStartupTime());
        } else {

            if (comHudHandler.helmetPressure < 0.05F && !gaveEmptyWarning) {
                addMessage(new ArmorMessage("The helmet is out of air!", new ArrayList<String>(), 100, 0x70FF0000));
                gaveEmptyWarning = true;
            }
            if (comHudHandler.helmetPressure > 0.2F && comHudHandler.helmetPressure < 0.5F && !gaveNearlyEmptyWarning) {
                addMessage(new ArmorMessage("The helmet almost out of air!", new ArrayList<String>(), 60, 0x70FF0000));
                gaveNearlyEmptyWarning = true;
            }
            if (GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade.coreComponents").checked) {
                for (int i = 0; i < UpgradeRenderHandlerList.instance().upgradeRenderers.size(); i++) {
                    IUpgradeRenderHandler upgradeRenderHandler = UpgradeRenderHandlerList.instance().upgradeRenderers.get(i);
                    if (comHudHandler.upgradeRenderersInserted[i] && GuiKeybindCheckBox.trackedCheckboxes.get("pneumaticHelmet.upgrade." + upgradeRenderHandler.getUpgradeName()).checked) {
                        IGuiAnimatedStat stat = upgradeRenderHandler.getAnimatedStat();
                        if (stat != null) {
                            stat.render(-1, -1, partialTicks);
                        }
                        upgradeRenderHandler.render2D(partialTicks, comHudHandler.helmetPressure > 0F);
                    }
                }
            }
        }

        // render every item in the list.
        for (ArmorMessage message : messageList) {
            message.renderMessage(minecraft.fontRenderer, partialTicks);
        }

        GL11.glPopMatrix();
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glDepthMask(true);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        if (comHudHandler.ticksExisted <= comHudHandler.getStartupTime())
            minecraft.fontRenderer.drawString(CommonHUDHandler.getHandlerForPlayer().ticksExisted * 100 / comHudHandler.getStartupTime() + "%", sr.getScaledWidth() * 3 / 4 - 8, 16, 0x000000);
    } else if (helmetStack.isEmpty()) {
        messageList.clear();
    }
}
 
Example 16
Project: pnc-repressurized   File: BlockSecurityStation.java   View Source Code Vote up 4 votes
private int getPlayerHackLevel(EntityPlayer player) {
    ItemStack armorStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
    return armorStack.getItem() == Itemss.PNEUMATIC_HELMET ? ItemPneumaticArmor.getUpgrades(EnumUpgrade.SECURITY, armorStack) : 0;
}
 
Example 17
Project: pnc-repressurized   File: InventorySearch.java   View Source Code Vote up 4 votes
public InventorySearch(EntityPlayer player) {
    helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
}
 
Example 18
Project: rtap   File: armorBolognaHelmet.java   View Source Code Vote up 3 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {

	if (playerIn.getItemStackFromSlot(EntityEquipmentSlot.HEAD) == ItemStack.EMPTY) {
		
		System.out.println("successfully equipped!");
		
		worldIn.playSound(playerIn, playerIn.getPosition(), ModSoundHandler.BOLOGNAARMOREQIUP, SoundCategory.PLAYERS, 1F, 1F);
		
	}
	
	return super.onItemRightClick(worldIn, playerIn, handIn);
	
}
 
Example 19
Project: rtap   File: armorBolognaBoots.java   View Source Code Vote up 3 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {

	if (playerIn.getItemStackFromSlot(EntityEquipmentSlot.FEET) == ItemStack.EMPTY) {
		
		System.out.println("successfully equipped!");
		
		worldIn.playSound(playerIn, playerIn.getPosition(), ModSoundHandler.BOLOGNAARMOREQIUP, SoundCategory.PLAYERS, 1F, 1F);
		
	}
	
	return super.onItemRightClick(worldIn, playerIn, handIn);
	
}
 
Example 20
Project: rtap   File: armorBolognaLeggings.java   View Source Code Vote up 3 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {

	if (playerIn.getItemStackFromSlot(EntityEquipmentSlot.LEGS) == ItemStack.EMPTY) {
		
		System.out.println("successfully equipped!");
		
		worldIn.playSound(playerIn, playerIn.getPosition(), ModSoundHandler.BOLOGNAARMOREQIUP, SoundCategory.PLAYERS, 1F, 1F);
		
	}
	
	return super.onItemRightClick(worldIn, playerIn, handIn);
	
}