net.minecraft.item.ItemBow Java Examples

The following examples show how to use net.minecraft.item.ItemBow. 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: BowBombModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void sendPacket(EventSendPacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof CPacketPlayerDigging) {
            final Minecraft mc = Minecraft.getMinecraft();

            final CPacketPlayerDigging packet = (CPacketPlayerDigging) event.getPacket();
            if (packet.getAction() == CPacketPlayerDigging.Action.RELEASE_USE_ITEM) {
                if (mc.player.inventory.getCurrentItem().getItem() instanceof ItemBow && mc.player.getItemInUseMaxCount() >= 20) {
                    if (!mc.player.onGround) {
                        mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY - 0.1f, mc.player.posZ, false));
                        mc.player.connection.sendPacket(new CPacketPlayer.Position(mc.player.posX, mc.player.posY - 10000f, mc.player.posZ, true));
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: ItemArmUpgrade.java    From Cyberware with MIT License 6 votes vote down vote up
@SubscribeEvent
public void useBow(LivingEntityUseItemEvent.Tick event)
{
	EntityLivingBase e = event.getEntityLiving();
	
	ItemStack test = new ItemStack(this, 1, 0);
	if (CyberwareAPI.isCyberwareInstalled(e, test))
	{
		ItemStack item = event.getItem();
		
		if (item != null && item.getItem() instanceof ItemBow)
		{
			event.setDuration(event.getDuration() - 1);
		}
	}
}
 
Example #3
Source File: GuiBowSelection.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 ItemBow)
	{
		attributes = new GuiButton[BowAttribute.BOW_ATTRIBUTES.size()];
		
		for (int i = 0; i < attributes.length; i++)
		{
			attributes[i] = new GuiButton(i, width / 2 - 147, 60 + (i * 20), 75, 20, BowAttribute.BOW_ATTRIBUTES.get(i).getName(nbt));
			this.buttonList.add(attributes[i]);
			attributes[i].enabled = false;
		}
	}
}
 
Example #4
Source File: GuiBowSelection.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 ItemBow)
			{
				for (int i = 0; i < attributes.length; i++)
				{
					if (button == attributes[i])
						Levels.network.sendToServer(new PacketAttributeSelection(i));
				}
			}
		}
	}
}
 
Example #5
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 #6
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 #7
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 #8
Source File: EventBarrage.java    From Levels with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
@SubscribeEvent
public void onBowFire(ArrowLooseEvent event)
{
	EntityPlayer player = event.getEntityPlayer();
	ItemStack stack = event.getBow();
	NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
	
	if (player != null && stack != null && nbt != null && !player.getEntityWorld().isRemote)
	{
		if (BowAttribute.BARRAGE.hasAttribute(nbt))
		{
			for (int i = 0; i < (int) BowAttribute.BARRAGE.getCalculatedValue(nbt, 3, 1.5); i++)
			{
				EntityArrow entityarrow = new EntityTippedArrow(player.getEntityWorld(), player);
				entityarrow.setAim(player, player.rotationPitch, player.rotationYaw, 0, ((ItemBow) event.getBow().getItem()).getArrowVelocity(event.getCharge()) * 3, 20F);
				entityarrow.pickupStatus = PickupStatus.DISALLOWED;
				player.getEntityWorld().spawnEntity(entityarrow);
			}
		}
	}
}
 
Example #9
Source File: FastBowModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onWalkingUpdate(EventUpdateWalkingPlayer event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Minecraft mc = Minecraft.getMinecraft();

        if(mc.player.inventory.getCurrentItem().getItem() instanceof ItemBow) {
            if(mc.player.isHandActive() && mc.player.getItemInUseMaxCount() >= 3) {
                mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, mc.player.getHorizontalFacing()));
                mc.player.connection.sendPacket(new CPacketPlayerTryUseItem(mc.player.getActiveHand()));
                mc.player.stopActiveHand();
            }
        }
    }
}
 
Example #10
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 #11
Source File: GuiBowSelection.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 ItemBow)
	{
		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 < BowAttribute.BOW_ATTRIBUTES.size(); i++)
		{
			if (BowAttribute.BOW_ATTRIBUTES.get(i).hasAttribute(nbt))
			{
				k++;
				drawCenteredString(fontRendererObj, BowAttribute.BOW_ATTRIBUTES.get(i).getName(nbt), width / 2 + 112, 60 + (10 * k), BowAttribute.BOW_ATTRIBUTES.get(i).getHex());
			}
		}
		
		displayButtons(nbt);
		drawTooltips(nbt, mouseX, mouseY);
	}
}
 
Example #12
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 #13
Source File: ItemBowRenderer.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
	TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
	ResourceLocation resource = textureManager.getResourceLocation(stack.getItemSpriteNumber());

	EntityPlayer player = Minecraft.getMinecraft().thePlayer;
	ItemStack usingItem = player.getItemInUse();
	int useRemaining = player.getItemInUseCount();

	ItemBow bow = (ItemBow) stack.getItem();

	IIcon icon = bow.getIcon(stack, 0);
	if (usingItem != null && usingItem == stack) {
		int charge = stack.getMaxItemUseDuration() - useRemaining;
		if (charge >= 18)
			icon = bow.getItemIconForUseDuration(2);
		else if (charge > 13)
			icon = bow.getItemIconForUseDuration(1);
		else if (charge > 0)
			icon = bow.getItemIconForUseDuration(0);
	}
	if (icon == null)
		icon = ((TextureMap) textureManager.getTexture(resource)).getAtlasSprite("missingno");

	OpenGLHelper.pushMatrix();
	textureManager.bindTexture(resource);

	OpenGLHelper.colour(bow.getColorFromItemStack(stack, 0));

	OpenGLHelper.disableLighting();
	OpenGLHelper.enableAlpha();
	OpenGLHelper.enableBlend();
	OpenGlHelper.glBlendFunc(770, 771, 1, 0);

	renderItem.renderIcon(0, 0, icon, 16, 16);

	OpenGLHelper.enableLighting();
	OpenGLHelper.disableAlpha();
	OpenGLHelper.disableBlend();

	if (stack.hasEffect(0))
		renderItem.renderEffect(textureManager, 0, 0);

	OpenGLHelper.popMatrix();
}
 
Example #14
Source File: GuiItemInformation.java    From Levels with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the strings for the ability selection screen.
 * @param stack
 * @param abilities
 * @param nbt
 */
private void drawStrings(ItemStack stack, NBTTagCompound nbt)
{
	Rarity rarity = Rarity.getRarity(nbt);
	
	drawCenteredString(fontRendererObj, stack.getDisplayName(), width / 2, 20, rarity.getHex());
	drawString(fontRendererObj, I18n.format("levels.misc.rarity") + ": " + rarity.getName(), width / 2 - 50, 40, rarity.getHex());
	drawCenteredString(fontRendererObj, I18n.format("levels.misc.attributes"), width / 2, 80, 0xFFFFFF);
	drawCenteredString(fontRendererObj, I18n.format("levels.misc.attributes.tokens") + ": " + Experience.getAttributeTokens(nbt), width / 2 - 112, 100, 0xFFFFFF);
	drawCenteredString(fontRendererObj, I18n.format("levels.misc.attributes.current"), width / 2 + 112, 100, 0xFFFFFF);
	
	if (Experience.getLevel(nbt) == Config.maxLevel)
	{
		drawString(fontRendererObj, I18n.format("levels.misc.level") + ": " + I18n.format("levels.misc.max"), width / 2 - 50, 50, 0xFFFFFF);
		drawString(fontRendererObj, I18n.format("levels.misc.experience") + ": " + I18n.format("levels.misc.max"), width / 2 - 50, 60, 0xFFFFFF);
	}
	else
	{
		drawString(fontRendererObj, I18n.format("levels.misc.level") + ": " + Experience.getLevel(nbt), width / 2 - 50, 50, 0xFFFFFF);
		drawString(fontRendererObj, I18n.format("levels.misc.experience") + ": " + Experience.getExperience(nbt) + " / " + Experience.getNextLevelExperience(Experience.getLevel(nbt)), width / 2 - 50, 60, 0xFFFFFF);
	}
	
	int k = -1;
	
	if (stack.getItem() instanceof ItemSword)
	{	
		for (int i = 0; i < WeaponAttribute.WEAPON_ATTRIBUTES.size(); i++)
		{
			if (WeaponAttribute.WEAPON_ATTRIBUTES.get(i).hasAttribute(nbt))
			{
				k++;
				drawCenteredString(fontRendererObj, WeaponAttribute.WEAPON_ATTRIBUTES.get(i).getName(nbt), width / 2 + 112, 115 + (10 * k), WeaponAttribute.WEAPON_ATTRIBUTES.get(i).getHex());
			}
		}
	}
	else if (stack.getItem() instanceof ItemTool)
	{
		
	}
	else if (stack.getItem() instanceof ItemBow)
	{
		for (int i = 0; i < BowAttribute.BOW_ATTRIBUTES.size(); i++)
		{
			if (BowAttribute.BOW_ATTRIBUTES.get(i).hasAttribute(nbt))
			{
				k++;
				drawCenteredString(fontRendererObj, BowAttribute.BOW_ATTRIBUTES.get(i).getName(nbt), width / 2 + 112, 115 + (10 * k), BowAttribute.BOW_ATTRIBUTES.get(i).getHex());
			}
		}
	}
	else if (stack.getItem() instanceof ItemArmor)
	{
		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, 115 + (10 * k), ArmorAttribute.ARMOR_ATTRIBUTES.get(i).getHex());
			}
		}
	}
	else if (stack.getItem() instanceof ItemShield)
	{
		for (int i = 0; i < ShieldAttribute.SHIELD_ATTRIBUTES.size(); i++)
		{
			if (ShieldAttribute.SHIELD_ATTRIBUTES.get(i).hasAttribute(nbt))
			{
				k++;
				drawCenteredString(fontRendererObj, ShieldAttribute.SHIELD_ATTRIBUTES.get(i).getName(nbt), width / 2 + 112, 115 + (10 * k), ShieldAttribute.SHIELD_ATTRIBUTES.get(i).getHex());
			}
		}
	}
}
 
Example #15
Source File: EventAttack.java    From Levels with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Uses rarity bonuses, such as bonus experience or durability bonuses. 
 * @param nbt
 * @param stack
 */
private void useRarity(NBTTagCompound nbt, ItemStack stack, boolean death)
{
	Rarity rarity = Rarity.getRarity(nbt);
	
	if (rarity != Rarity.DEFAULT)
	{
		int var;
		int var1;
		int var2;
		int var3;
		
		switch (rarity)
		{
			case UNCOMMON: // 6% chance of adding 1-3 experience points; 6% chance of not using durability
				if ((stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemShield) || ((stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemBow) && death))
				{
					var = (int) (Math.random() * 15);
					var1 = (int) (Math.random() * 3 + 1);
					if (var == 0) Experience.setExperience(nbt, Experience.getExperience(nbt) + var1);
				}
				
				if (!Config.unlimitedDurability && !death)
				{
					var2 = (int) (Math.random() * 15);
					if (var2 == 0) stack.setItemDamage(stack.getItemDamage() - 1);
				}
				
				break;
			case RARE: // 10% chance of adding 1-5 experience points; 10% chance of not using durability AND gaining an additional durability point
				if ((stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemShield) || ((stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemBow) && death))
				{
					var = (int) (Math.random() * 10);
					var1 = (int) (Math.random() * 5 + 1);
					if (var == 0) Experience.setExperience(nbt, Experience.getExperience(nbt) + var1);
				}
				
				if (!Config.unlimitedDurability && !death)
				{
					var2 = (int) (Math.random() * 10);
					var3 = (int) (Math.random() * 2);
					if (var2 == 0) stack.setItemDamage(stack.getItemDamage() - (1 + var3));
				}
				
				break;
			case LEGENDARY: // 14% chance of adding 3-5 experience points; 14% chance of not using durability AND gaining 1-3 durability points
				if ((stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemShield) || ((stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemBow) && death))
				{
					var = (int) (Math.random() * 7);
					var1 = (int) (Math.random() * 5 + 3);
					if (var == 0) Experience.setExperience(nbt, Experience.getExperience(nbt) + var1);
				}
				
				if (!Config.unlimitedDurability && !death)
				{
					var2 = (int) (Math.random() * 7);
					var3 = (int) (Math.random() * 3 + 1);
					if (var2 == 0) stack.setItemDamage(stack.getItemDamage() - (1 + var3));
				}
				
				break;
			case MYTHIC: // 20% chance of adding 3-10 experience points; 20% chance of not using durability AND gaining 1-5 durability points
				if ((stack.getItem() instanceof ItemArmor || stack.getItem() instanceof ItemShield) || ((stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemBow) && death))
				{
					var = (int) (Math.random() * 5);
					var1 = (int) (Math.random() * 8 + 3);
					if (var == 0) Experience.setExperience(nbt, Experience.getExperience(nbt) + var1);
				}
				
				if (!Config.unlimitedDurability && !death)
				{
					var2 = (int) (Math.random() * 5);
					var3 = (int) (Math.random() * 5 + 1);
					if (var2 == 0) stack.setItemDamage(stack.getItemDamage() - (1 + var3));
				}
				
				break;
			default:
				break;
		}
	}
}