本文整理汇总了Java中net.minecraft.item.ItemArrow类的典型用法代码示例。如果您正苦于以下问题:Java ItemArrow类的具体用法?Java ItemArrow怎么用?Java ItemArrow使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ItemArrow类属于net.minecraft.item包,在下文中一共展示了ItemArrow类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleNock
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
@SubscribeEvent
public void handleNock(ArrowNockEvent event){
if(event.getEntityPlayer() !=null){
ExtendedPlayer exPlayer = ExtendedPlayerProvider.getExtendedPlayer(event.getEntityPlayer());
if(exPlayer !=null){
ExtendedPlayerInventory inv = exPlayer.getInventory();
ItemStack backpack = inv.getStackInSlot(ExtendedPlayerInventory.BACKPACK_SLOT_ID);
if(ItemStackTools.isValid(backpack)){
InventoryBackpackUpgrades upgrades = BackpackUtil.getUpgradeInventory(event.getEntityPlayer(), backpack);
if(upgrades !=null && upgrades.hasUpgrade(BackpackUpgrade.BOW)){
InventoryBackpack backpackInv = BackpackUtil.getInventory(event.getEntityPlayer(), backpack);
if(backpackInv !=null){
for(int i = 0; i < backpackInv.getSize(); i++){
ItemStack st = backpackInv.getStackInSlot(i);
if(ItemStackTools.isValid(st) && st.getItem() instanceof ItemArrow){
event.getEntityPlayer().setActiveHand(event.getHand());
event.setAction(new ActionResult<ItemStack>(EnumActionResult.SUCCESS, event.getBow()));
return;
}
}
}
}
}
}
}
}
示例2: countAmmo
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
private int countAmmo(EntityPlayerSP player) {
ItemStack current = player.inventory.getCurrentItem();
if(current != null) {
if(current.getItem() instanceof ItemBow) {
int enchant = net.minecraft.enchantment.EnchantmentHelper.getEnchantmentLevel(net.minecraft.init.Enchantments.INFINITY, current);
if(enchant > 0) {
return INFINITE_AMMO;
}
return countItem(player.inventory, ItemArrow.class);
} else if(current.getItem() instanceof FunWeaponItem) {
return INFINITE_AMMO;
} else if(current.getItem() instanceof WeaponItem) {
return countAmmo(player.inventory, ((WeaponItem) current.getItem()).getDefinition().getAmmoType());
}
}
return INFINITE_AMMO;
}
示例3: onArrowFired
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
@Override
public void onArrowFired(World world, EntityPlayer player, ItemStack stack, ItemStack bow, EntityArrow arrow) {
if(!player.capabilities.isCreativeMode){
int selectedSlot = getSelectedSlot(stack);
ItemStack arrowStack = getStackInSlot(stack, selectedSlot);
if(!(arrowStack.getItem() instanceof ItemArrow) || !((ItemArrow) arrowStack.getItem()).isInfinite(arrowStack, bow, player)) {
arrowStack.shrink(1);
if (arrowStack.isEmpty()) {
//ForgeEventFactory.onPlayerDestroyItem(player, arrowStack);
arrowStack = ItemStack.EMPTY;
}
setStackInSlot(stack, selectedSlot, arrowStack);
}
}
bow.getTagCompound().removeTag("Battlegear2-LoadedArrow");
}
示例4: handleLoose
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
@SubscribeEvent
public void handleLoose(ArrowLooseEvent event){
if(event.getEntityPlayer() !=null){
ExtendedPlayer exPlayer = ExtendedPlayerProvider.getExtendedPlayer(event.getEntityPlayer());
if(exPlayer !=null){
ExtendedPlayerInventory inv = exPlayer.getInventory();
ItemStack backpack = inv.getStackInSlot(ExtendedPlayerInventory.BACKPACK_SLOT_ID);
if(ItemStackTools.isValid(backpack)){
InventoryBackpackUpgrades upgrades = BackpackUtil.getUpgradeInventory(event.getEntityPlayer(), backpack);
if(upgrades !=null && upgrades.hasUpgrade(BackpackUpgrade.BOW)){
InventoryBackpack backpackInv = BackpackUtil.getInventory(event.getEntityPlayer(), backpack);
if(backpackInv !=null){
for(int i = 0; i < backpackInv.getSize(); i++){
ItemStack st = backpackInv.getStackInSlot(i);
if(ItemStackTools.isValid(st) && st.getItem() instanceof ItemArrow){
if(!EntityUtil.shootArrow(event.getWorld(), event.getEntityPlayer(), event.getBow(), st, event.getCharge())){
backpackInv.decrStackSize(i, 1);
backpackInv.markDirty();
backpackInv.guiSave(event.getEntityPlayer());
inv.setChanged(ExtendedPlayerInventory.BACKPACK_SLOT_ID, true);
event.setCanceled(true);
return;
}
}
}
}
}
}
}
}
}
示例5: onEntityJoinWorld
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
/**
* Listen to {@link EntityJoinWorldEvent} :
* Adds random special {@link EntityArrow}s data to {@link AbstractSkeleton}s {@link net.minecraft.network.datasync.EntityDataManager} (for display)
* Replace the vanilla fired {@link EntityTippedArrow} with the custom {@link AbstractMBArrow} (for actual action)
* Note: Fails silently
*/
@SubscribeEvent(priority = EventPriority.LOW)
public void onEntityJoinWorld(EntityJoinWorldEvent event){
if(event.getEntity() instanceof AbstractSkeleton){
registerArrowType((AbstractSkeleton)event.getEntity());
}else if(event.getEntity() instanceof EntityTippedArrow && ((EntityTippedArrow) event.getEntity()).getColor() == 0){
EntityArrow arrow = ((EntityArrow)event.getEntity());
if (arrow.shootingEntity instanceof AbstractSkeleton) {
AbstractSkeleton skeleton = (AbstractSkeleton) arrow.shootingEntity;
if(skeleton.getAttackTarget() != null) {
ItemStack type = getArrowForMob(skeleton);
if (type.getItem() instanceof ItemArrow) {
EntityArrow mbArrow = ((ItemArrow)type.getItem()).createArrow(skeleton.world, type, skeleton);
if (!(mbArrow instanceof EntityTippedArrow)) {
EntityLivingBase target = skeleton.getAttackTarget();
float pow = MathHelper.sqrt(skeleton.getDistanceSq(target.posX, target.getEntityBoundingBox().minY, target.posZ)) / 15F;
pow = MathHelper.clamp(pow, 0.1F, 1.0F);
mbArrow.setEnchantmentEffectsFromEntity(skeleton, pow);
if (skeleton instanceof EntityWitherSkeleton)
mbArrow.setFire(100);
double d0 = target.posX - skeleton.posX;
double d1 = target.getEntityBoundingBox().minY + (double)(target.height / 3.0F) - mbArrow.posY;
double d2 = target.posZ - skeleton.posZ;
double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
mbArrow.setThrowableHeading(d0, d1 + d3 * 0.2D, d2, 1.6F, (float)(14 - skeleton.world.getDifficulty().getDifficultyId() * 4));
mbArrow.setDamage(arrow.getDamage());
if (skeleton.world.spawnEntity(mbArrow))
event.setCanceled(true);
}
}
}
}
}
}
示例6: isArrow
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
protected boolean isArrow(ItemStack stack)
{
return stack.getItem() instanceof ItemArrow;
}
示例7: isArrowInOffhand
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
protected boolean isArrowInOffhand() {
return !this.armyMember.getHeldItemOffhand().isEmpty() && this.armyMember.getHeldItemOffhand().getItem() instanceof ItemArrow;
}
示例8: shootArrow
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
/**Returns if an arrow was infinite or not**/
public static boolean shootArrow(World world, EntityPlayer entityplayer, ItemStack bow, ItemStack itemstack, int charge) {
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, bow) > 0;
int i = charge;
if (ItemStackTools.isValid(itemstack) || flag)
{
if (ItemStackTools.isEmpty(itemstack))
{
itemstack = new ItemStack(Items.ARROW);
}
float f = ItemBow.getArrowVelocity(i);
if (f >= 0.1D)
{
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow ? ((ItemArrow)itemstack.getItem()).isInfinite(itemstack, bow, entityplayer) : false);
if (!world.isRemote)
{
ItemArrow itemarrow = ((ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
EntityArrow entityarrow = itemarrow.createArrow(world, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, bow);
if (j > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, bow);
if (k > 0)
{
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, bow) > 0)
{
entityarrow.setFire(100);
}
bow.damageItem(1, entityplayer);
if (flag1)
{
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
world.spawnEntity(entityarrow);
}
world.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
entityplayer.addStat(StatList.getObjectUseStats(Items.BOW));
return flag1;
}
}
return false;
}
示例9: isArrow
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
protected boolean isArrow(@Nullable ItemStack stack)
{
return stack != null && stack.getItem() instanceof ItemArrow;
}
示例10: onPlayerStoppedUsing
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
{
if (entityLiving instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)entityLiving;
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = this.findAmmo(entityplayer);
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer)entityLiving, i, itemstack != null || flag);
if (i < 0) return;
if (itemstack != null || flag)
{
if (itemstack == null)
{
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if ((double)f >= 0.1D)
{
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow ? ((ItemArrow)itemstack.getItem()).isInfinite(itemstack, stack, entityplayer) : false);
if (!worldIn.isRemote)
{
EntityArrow entityarrow = this.createArrow(worldIn, itemstack.getItem() instanceof ItemSpectralArrow, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0)
{
entityarrow.setKnockbackStrength(k);
}
stack.damageItem(1, entityplayer);
if (flag1)
{
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
worldIn.spawnEntityInWorld(entityarrow);
}
worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1)
{
--itemstack.stackSize;
if (itemstack.stackSize == 0)
{
entityplayer.inventory.deleteStack(itemstack);
}
}
entityplayer.addStat(StatList.getObjectUseStats(this));
}
}
}
}
示例11: isInfinite
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
@Override
public boolean isInfinite(ItemStack arrow, ItemStack bow, EntityPlayer player)
{
int enchant = EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, bow);
return enchant > 0 && this instanceof ItemArrow;
}
示例12: onPlayerStoppedUsing
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
{
if (entityLiving instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)entityLiving;
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = this.findAmmo(entityplayer);
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, itemstack != null || flag);
if (i < 0) return;
if (itemstack != null || flag)
{
if (itemstack == null)
{
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if ((double)f >= 0.1D)
{
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow ? ((ItemArrow)itemstack.getItem()).isInfinite(itemstack, stack, entityplayer) : false);
if (!worldIn.isRemote)
{
ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F)
{
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0)
{
entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0)
{
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
{
entityarrow.setFire(100);
}
if (flag1)
{
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
worldIn.spawnEntityInWorld(entityarrow);
}
worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
entityplayer.addStat(StatList.getObjectUseStats(this));
}
}
}
}
示例13: isArrow
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
default boolean isArrow(@Nullable ItemStack stack) {
return stack != null && stack.getItem() instanceof ItemArrow;
}
示例14: onPlayerStoppedUsing
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
/**
* Called when the player stops using an Item (stops holding the right mouse button).
*
* @param timeLeft The amount of ticks left before the using would have been complete
*/
default void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = this.findAmmo(entityplayer);
int i = this.getMaxItemUseDuration(stack) - timeLeft;
i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, i, itemstack != null || flag);
if (i < 0) {
return;
}
if (itemstack != null || flag) {
if (itemstack == null) {
itemstack = new ItemStack(Items.ARROW);
}
float f = getArrowVelocity(i);
if ((double) f >= 0.1D) {
boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
if (!worldIn.isRemote) {
ItemArrow itemarrow = (ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
if (f == 1.0F) {
entityarrow.setIsCritical(true);
}
int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
entityarrow.setKnockbackStrength(k);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, entityplayer);
if (flag1) {
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
worldIn.spawnEntity(entityarrow);
}
worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (__getItemRand().nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1) {
itemstack.setCount(itemstack.getCount() - 1);
if (itemstack.getCount() == 0) {
entityplayer.inventory.deleteStack(itemstack);
}
}
entityplayer.addStat(StatList.getObjectUseStats(__getBowItem()));
}
}
}
}
示例15: onPlayerStoppedUsing
import net.minecraft.item.ItemArrow; //导入依赖的package包/类
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
if (! (entityLiving instanceof EntityPlayer)) {
return;
}
EntityPlayer entityplayer = (EntityPlayer) entityLiving;
boolean hasInfinateArrows = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = getArrowsToShoot(entityplayer);
int draw = getMaxItemUseDuration(stack) - timeLeft;
draw = ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, draw, itemstack != null || hasInfinateArrows);
if (draw < 0){
return;
}
if(itemstack == null && hasInfinateArrows) {
itemstack = new ItemStack(Items.ARROW);
}
if (itemstack == null) {
return;
}
float drawRatio = getArrowVelocity(draw);
if (drawRatio >= 0.1) {
boolean arrowIsInfinite = hasInfinateArrows && itemstack.getItem() instanceof ItemArrow;
if (!worldIn.isRemote) {
ItemArrow itemarrow = (ItemArrow) ((ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
//TODO: 1.9 Arrows dont fly straight with higher force
// entityarrow.func_184547_a(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, drawRatio * 3.0F * forceMultiplier, 1.0F);
entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, drawRatio * (3.0F + forceMultiplier), 0.25F);
//entityarrow.setVelocity(x, y, z);
if (drawRatio == 1.0F) {
entityarrow.setIsCritical(true);
}
int powerLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
if (powerLevel > 0) {
entityarrow.setDamage(entityarrow.getDamage() + (double) powerLevel * 0.5D + 0.5D);
}
int knockBack = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
if (knockBack > 0) {
entityarrow.setKnockbackStrength(knockBack);
}
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
entityarrow.setFire(100);
}
stack.damageItem(1, entityplayer);
if (arrowIsInfinite) {
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
entityarrow.setDamage(entityarrow.getDamage() + damageBonus + 20);
worldIn.spawnEntity(entityarrow);
}
worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL,
1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + drawRatio * 0.5F);
if (!arrowIsInfinite) {
itemstack.shrink(1);
if (itemstack.isEmpty()) {
entityplayer.inventory.deleteStack(itemstack);
}
}
entityplayer.addStat(StatList.getObjectUseStats(this));
}
}