本文整理汇总了Java中net.minecraft.item.ItemStack.getItem方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.getItem方法的具体用法?Java ItemStack.getItem怎么用?Java ItemStack.getItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.getItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matches
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
boolean key = false;
ItemStack crate = ItemStack.EMPTY;
for (int x = 0; x < inv.getSizeInventory(); x++) {
ItemStack stack = inv.getStackInSlot(x);
if (!stack.isEmpty())
if (stack.getItem() == TF2weapons.itemTF2 && stack.getMetadata() == 7) {
if (!key)
key = true;
else
return false;
} else if (crate.isEmpty() && stack.getItem() instanceof ItemCrate)
crate = stack;
else
return false;
}
// System.out.println("matches "+(australium&&stack2!=null));
return key && crate != null;
}
示例2: doTrade
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean doTrade(MerchantRecipe trade, ItemStack firstItem, ItemStack secondItem)
{
ItemStack itemstack = trade.getItemToBuy();
ItemStack itemstack1 = trade.getSecondItemToBuy();
if (firstItem != null && firstItem.getItem() == itemstack.getItem())
{
if (itemstack1 != null && secondItem != null && itemstack1.getItem() == secondItem.getItem())
{
firstItem.stackSize -= itemstack.stackSize;
secondItem.stackSize -= itemstack1.stackSize;
return true;
}
if (itemstack1 == null && secondItem == null)
{
firstItem.stackSize -= itemstack.stackSize;
return true;
}
}
return false;
}
示例3: isItemValidForSlot
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For
* guis use Slot.isItemValid
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
if (index == 2)
{
return false;
}
else if (index != 1)
{
return true;
}
else
{
ItemStack itemstack = this.furnaceItemStacks[1];
return isItemFuel(stack) || SlotFurnaceFuel.isBucket(stack) && (itemstack == null || itemstack.getItem() != Items.BUCKET);
}
}
示例4: dropItemOnGround
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void dropItemOnGround(ItemStack stack, World world, double x, double y, double z) {
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(stack.getItem(), stack.getCount(), stack.getItemDamage()));
if (stack.hasTagCompound()) {
entityItem.getItem().setTagCompound(stack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntity(entityItem);
stack.setCount(0);
}
示例5: playEquipSound
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
protected void playEquipSound(ItemStack stack)
{
if (!stack.func_190926_b())
{
SoundEvent soundevent = SoundEvents.ITEM_ARMOR_EQUIP_GENERIC;
Item item = stack.getItem();
if (item instanceof ItemArmor)
{
soundevent = ((ItemArmor)item).getArmorMaterial().getSoundEvent();
}
else if (item == Items.ELYTRA)
{
soundevent = SoundEvents.field_191258_p;
}
this.playSound(soundevent, 1.0F, 1.0F);
}
}
示例6: writeEntityToNBT
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
super.writeEntityToNBT(tagCompound);
tagCompound.setTag("Inventory", this.inventory.writeToNBT(new NBTTagList()));
tagCompound.setInteger("SelectedItemSlot", this.inventory.currentItem);
tagCompound.setBoolean("Sleeping", this.sleeping);
tagCompound.setShort("SleepTimer", (short)this.sleepTimer);
tagCompound.setFloat("XpP", this.experience);
tagCompound.setInteger("XpLevel", this.experienceLevel);
tagCompound.setInteger("XpTotal", this.experienceTotal);
tagCompound.setInteger("XpSeed", this.xpSeed);
tagCompound.setInteger("Score", this.getScore());
if (this.spawnChunk != null)
{
tagCompound.setInteger("SpawnX", this.spawnChunk.getX());
tagCompound.setInteger("SpawnY", this.spawnChunk.getY());
tagCompound.setInteger("SpawnZ", this.spawnChunk.getZ());
tagCompound.setBoolean("SpawnForced", this.spawnForced);
}
this.foodStats.writeNBT(tagCompound);
this.capabilities.writeCapabilitiesToNBT(tagCompound);
tagCompound.setTag("EnderItems", this.theInventoryEnderChest.saveInventoryToNBT());
ItemStack itemstack = this.inventory.getCurrentItem();
if (itemstack != null && itemstack.getItem() != null)
{
tagCompound.setTag("SelectedItem", itemstack.writeToNBT(new NBTTagCompound()));
}
}
示例7: removeCraftingRecipe
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void removeCraftingRecipe(Item item) {
@SuppressWarnings("unchecked")
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
Iterator<IRecipe> iterator = recipes.iterator();
while (iterator.hasNext()) {
ItemStack is = iterator.next().getRecipeOutput();
if (is != null && is.getItem() == item)
iterator.remove();
}
}
示例8: shouldCauseReequipAnimation
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
if (oldStack.getItem() == newStack.getItem()) {
return false;
}
return super.shouldCauseReequipAnimation(oldStack, newStack, slotChanged);
}
示例9: isHittingPosition
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private boolean isHittingPosition(BlockPos pos)
{
ItemStack itemstack = this.mc.player.getHeldItemMainhand();
boolean flag = this.currentItemHittingBlock.func_190926_b() && itemstack.func_190926_b();
if (!this.currentItemHittingBlock.func_190926_b() && !itemstack.func_190926_b())
{
flag = itemstack.getItem() == this.currentItemHittingBlock.getItem() && ItemStack.areItemStackTagsEqual(itemstack, this.currentItemHittingBlock) && (itemstack.isItemStackDamageable() || itemstack.getMetadata() == this.currentItemHittingBlock.getMetadata());
}
return pos.equals(this.currentBlock) && flag;
}
示例10: isBreedingItem
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Checks if the parameter is an item which this animal can be fed to breed it (wheat, carrots or seeds depending on
* the animal type)
*/
public boolean isBreedingItem(ItemStack stack)
{
return stack != null && stack.getItem() == Items.carrot;
}
示例11: interact
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
*/
public boolean interact(EntityPlayer player)
{
ItemStack itemstack = player.inventory.getCurrentItem();
if (itemstack != null && itemstack.getItem() == Items.spawn_egg)
{
if (!this.worldObj.isRemote)
{
Class <? extends Entity > oclass = EntityList.getClassFromID(itemstack.getMetadata());
if (oclass != null && this.getClass() == oclass)
{
EntityAgeable entityageable = this.createChild(this);
if (entityageable != null)
{
entityageable.setGrowingAge(-24000);
entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F);
this.worldObj.spawnEntityInWorld(entityageable);
if (itemstack.hasDisplayName())
{
entityageable.setCustomNameTag(itemstack.getDisplayName());
}
if (!player.capabilities.isCreativeMode)
{
--itemstack.stackSize;
if (itemstack.stackSize <= 0)
{
player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack)null);
}
}
}
}
}
return true;
}
else
{
return false;
}
}
示例12: canApplyAtEnchantingTable
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
return stack != null && stack.getItem() == Items.book;
}
示例13: onStrangeUpdate
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static void onStrangeUpdate(ItemStack stack, EntityLivingBase player) {
int points = 0;
if (stack.getItem() instanceof ItemMedigun) {
points = stack.getTagCompound().getInteger("Ubercharges");
} else if (stack.getItem() instanceof ItemCloak) {
points = stack.getTagCompound().getInteger("CloakTicks") / 400;
} else {
points = stack.getTagCompound().getInteger("Kills");
points += stack.getTagCompound().getInteger("PlayerKills") * 5;
}
int calculatedLevel = 0;
if (points >= STRANGE_KILLS[STRANGE_KILLS.length - 1]) {
calculatedLevel = STRANGE_KILLS.length - 1;
} else {
for (int i = 1; i < STRANGE_KILLS.length; i++)
if (points < STRANGE_KILLS[i]) {
calculatedLevel = i - 1;
break;
}
}
if (calculatedLevel > stack.getTagCompound().getInteger("StrangeLevel")) {
stack.getTagCompound().setInteger("StrangeLevel", calculatedLevel);
if(player instanceof EntityPlayer) {
((EntityPlayer) player).addExperience(40 * calculatedLevel);
ItemHandlerHelper.giveItemToPlayer((EntityPlayer) player, new ItemStack(TF2weapons.itemTF2, calculatedLevel<10?MathHelper.ceil(calculatedLevel/2f) : calculatedLevel - 5, 6));
if(calculatedLevel == 20)
ItemHandlerHelper.giveItemToPlayer((EntityPlayer) player, new ItemStack(TF2weapons.itemTF2, 2, 7));
}
/*final int level = calculatedLevel;
if (player instanceof EntityPlayerMP) {
((EntityPlayerMP) player).addStat(new Achievement(Integer.toString(player.getRNG().nextInt()), "strangeUp", 0, 0, stack, null) {
@Override
public ITextComponent getStatName() {
return super.getStatName().appendText(STRANGE_TITLES[level]);
}
});
}*/
}
}
示例14: onActivated
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean onActivated(EntityPlayer playerIn, EnumHand hand)
{
if(!isCauldron())
return false;
ItemStack itemstack = playerIn.getHeldItem(hand);
Item item = itemstack.getItem();
if (itemstack.isEmpty())
return false;
boolean flag;
if(item instanceof BloodCollector && (controller.fluid == GlassContainerValues.BLOOD.getType() || controller.fluid == CauldronLiquid.NONE))
{
if(controller.level != getMaxLevels())
if (playerIn.capabilities.isCreativeMode || (!playerIn.capabilities.isCreativeMode && ((BloodCollector)item).remove(playerIn, hand, 3)))
{
this.world.playSound((EntityPlayer)null, pos, SoundEvents.ITEM_BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
controller.level ++;
controller.fluid = GlassContainerValues.BLOOD.getType();
}
return true;
}
CauldronLiquid potentionalLiquid = HarshenRegistry.getLiquidFromStack(itemstack);
if(potentionalLiquid != null && (controller.level <= 0 || (controller.fluid == potentionalLiquid && controller.level + HarshenRegistry.getFill(itemstack) <= getMaxLevels())))
{
controller.fluid = HarshenRegistry.getRelativeFluid(potentionalLiquid);
controller.level += HarshenRegistry.getFill(itemstack);
ItemStack oldStack = itemstack.copy();
itemstack.shrink(1);
HarshenUtils.give(playerIn, hand, HarshenRegistry.getOutPutItem(oldStack, potentionalLiquid));
return true;
}
ItemStack potentionalItem = HarshenRegistry.getInputFromOutput(itemstack, controller.fluid);
if(potentionalItem != null && !potentionalItem.isEmpty() && controller.level - HarshenRegistry.getRemoveFill(itemstack, controller.fluid) >= 0)
{
controller.level -= HarshenRegistry.getRemoveFill(itemstack, controller.fluid);
itemstack.shrink(1);
HarshenUtils.give(playerIn, hand, potentionalItem);
return true;
}
return false;
}
示例15: processInteract
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
ItemStack itemstack = player.getHeldItem(hand);
if (itemstack.getItem() == Items.SPAWN_EGG)
{
return super.processInteract(player, hand);
}
else
{
if (!this.isChild())
{
if (this.isTame() && player.isSneaking())
{
this.openGUI(player);
return true;
}
if (this.isBeingRidden())
{
return super.processInteract(player, hand);
}
}
if (!itemstack.func_190926_b())
{
boolean flag = this.func_190678_b(player, itemstack);
if (!flag && !this.isTame())
{
if (itemstack.interactWithEntity(player, this, hand))
{
return true;
}
this.func_190687_dF();
return true;
}
if (!flag && !this.func_190695_dh() && itemstack.getItem() == Item.getItemFromBlock(Blocks.CHEST))
{
this.setChested(true);
this.func_190697_dk();
flag = true;
this.initHorseChest();
}
if (!flag && !this.isChild() && !this.isHorseSaddled() && itemstack.getItem() == Items.SADDLE)
{
this.openGUI(player);
return true;
}
if (flag)
{
if (!player.capabilities.isCreativeMode)
{
itemstack.func_190918_g(1);
}
return true;
}
}
if (this.isChild())
{
return super.processInteract(player, hand);
}
else if (itemstack.interactWithEntity(player, this, hand))
{
return true;
}
else
{
this.mountTo(player);
return true;
}
}
}