本文整理汇总了Java中net.minecraft.item.ItemStack类的典型用法代码示例。如果您正苦于以下问题:Java ItemStack类的具体用法?Java ItemStack怎么用?Java ItemStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ItemStack类属于net.minecraft.item包,在下文中一共展示了ItemStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: attemptToGetAsVariant
import net.minecraft.item.ItemStack; //导入依赖的package包/类
/** Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br>
* (eg blue_orchid vs orchidBlue etc.)
* @param part the string (potentially in the 'wrong' format, eg 'orchidBlue')
* @param is the ItemStack from which this string came (eg from is.getUnlocalisedName)
* @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values.
*/
public static Variation attemptToGetAsVariant(String part, ItemStack is)
{
if (is.getItem() instanceof ItemBlock)
{
// Unlocalised name doesn't always match the names we use in types.xsd
// (which are the names displayed by Minecraft when using the F3 debug etc.)
ItemBlock ib = (ItemBlock)(is.getItem());
IBlockState bs = ib.block.getStateFromMeta(is.getMetadata());
for (IProperty prop : (java.util.Set<IProperty>)bs.getProperties().keySet())
{
Comparable<?> comp = bs.getValue(prop);
Variation var = attemptToGetAsVariant(comp.toString());
if (var != null)
return var;
}
return null;
}
else
return attemptToGetAsVariant(part);
}
示例2: onItemUse
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(hand);
if (!worldIn.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey("Statue")) {
EntityStatue statue =new EntityStatue(worldIn);
statue.readEntityFromNBT(stack.getTagCompound().getCompoundTag("Statue"));
BlockPos off = pos.offset(facing);
statue.setPosition(off.getX()+0.5, off.getY(), off.getZ()+0.5);
statue.rotationYaw = playerIn.rotationYawHead;
statue.renderYawOffset = playerIn.rotationYawHead;
statue.ticksLeft = -1;
worldIn.spawnEntity(statue);
if (!playerIn.capabilities.isCreativeMode)
stack.shrink(1);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.SUCCESS;
}
示例3: getCustomItemModel
import net.minecraft.item.ItemStack; //导入依赖的package包/类
public static IBakedModel getCustomItemModel(ItemStack p_getCustomItemModel_0_, IBakedModel p_getCustomItemModel_1_, ResourceLocation p_getCustomItemModel_2_)
{
if (p_getCustomItemModel_1_.isGui3d())
{
return p_getCustomItemModel_1_;
}
else if (itemProperties == null)
{
return p_getCustomItemModel_1_;
}
else
{
CustomItemProperties customitemproperties = getCustomItemProperties(p_getCustomItemModel_0_, 1);
return customitemproperties == null ? p_getCustomItemModel_1_ : customitemproperties.getModel(p_getCustomItemModel_2_);
}
}
示例4: getRemainingItems
import net.minecraft.item.ItemStack; //导入依赖的package包/类
public ItemStack[] getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
{
for (IRecipe irecipe : this.recipes)
{
if (irecipe.matches(craftMatrix, worldIn))
{
return irecipe.getRemainingItems(craftMatrix);
}
}
ItemStack[] aitemstack = new ItemStack[craftMatrix.getSizeInventory()];
for (int i = 0; i < aitemstack.length; ++i)
{
aitemstack[i] = craftMatrix.getStackInSlot(i);
}
return aitemstack;
}
示例5: onEquipped
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public void onEquipped(ItemStack stack, EntityLivingBase entity)
{
if (entity.getEntityWorld().isRemote) entity.playSound(SoundEvents.ITEM_ARMOR_EQUIP_DIAMOND, 0.1F, 1.3f);
else
{
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
PlayerInformation info = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);
if (info != null && info.getPlayerLevel() >= NBTHelper.loadStackNBT(stack).getInteger("Level"))
{
EventPlayerTick.updateStats(player, info);
}
else player.sendMessage(new TextComponentString(TextFormatting.RED + "WARNING: You are using a high-leveled item. It will be useless and will not provide any bonuses."));
}
}
}
示例6: getAAFromMatrix
import net.minecraft.item.ItemStack; //导入依赖的package包/类
private ItemStack getAAFromMatrix(InventoryCrafting matrix)
{
int counter = 0;
while (counter < matrix.getSizeInventory())
{
if (matrix.getStackInSlot(counter) != null && matrix.getStackInSlot(counter).getItem() instanceof PackedUpAA)
{
return matrix.getStackInSlot(counter); // Found it
}
counter += 1;
}
return null;
}
示例7: getCraftingResult
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public ItemStack getCraftingResult(InventoryCrafting matrix)
{
ItemStack stack = this.result.copy();
ItemStack previousAA = this.getAAFromMatrix(matrix);
if (previousAA != null && previousAA.hasTagCompound()) // Copying existing properties
{
stack.setTagCompound((NBTTagCompound) previousAA.getTagCompound().copy());
}
else // ...or just applying new ones
{
stack.setTagCompound(new NBTTagCompound());
}
// Apply the new upgrade now
stack.getTagCompound().setBoolean("hasWeaponUpgrade", true);
if (stack.getTagCompound().getInteger("currentHealth") == 0) // Just making sure it's not shown with 0 health
{
if (stack.getTagCompound().getBoolean("hasArmorUpgrade")) { stack.getTagCompound().setInteger("currentHealth", 40); }
else { stack.getTagCompound().setInteger("currentHealth", 20); } // Fresh turret, so setting some health
}
return stack;
}
示例8: doSingleFire
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public void doSingleFire(ItemStack stack, World world, Entity entity) // Server side
{
// Ignoring cooldown for firing purposes
// SFX
world.playSoundAtEntity(entity, "mob.bat.takeoff", 0.5F, 0.6F);
// Ready
FlintDust shot = new FlintDust(world, entity, (float) this.Speed);
// Properties
shot.damage = this.Dmg;
shot.ticksInAirMax = this.MaxBlocks;
// Go
world.spawnEntityInWorld(shot);
this.consumeAmmo(stack, entity, 1);
this.setCooldown(stack, 4);
}
示例9: addRecipes
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public void addRecipes()
{
if (this.Enabled)
{
// One Firework Rocket Launcher (empty)
GameRegistry.addRecipe(new ItemStack(this, 1 , this.getMaxDamage()), "x ", "yx ", "zyx",
'x', Blocks.planks,
'y', Items.iron_ingot,
'z', Items.flint_and_steel
);
}
else if (Main.noCreative) { this.setCreativeTab(null); } // Not enabled and not allowed to be in the creative menu
// Fill the RPG with 1 rocket
GameRegistry.addRecipe(new ItemStack(this), " ab", "zya", " x ",
'x', new ItemStack(this, 1 , this.getMaxDamage()),
'y', Blocks.tnt,
'z', Blocks.planks,
'a', Items.paper,
'b', Items.string
);
}
示例10: doVoidFogParticles
import net.minecraft.item.ItemStack; //导入依赖的package包/类
public void doVoidFogParticles(int posX, int posY, int posZ)
{
int i = 32;
Random random = new Random();
ItemStack itemstack = this.mc.player.getHeldItemMainhand();
if (itemstack == null || Block.getBlockFromItem(itemstack.getItem()) != Blocks.BARRIER)
{
itemstack = this.mc.player.getHeldItemOffhand();
}
boolean flag = this.mc.playerController.getCurrentGameType() == GameType.CREATIVE && !itemstack.func_190926_b() && itemstack.getItem() == Item.getItemFromBlock(Blocks.BARRIER);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int j = 0; j < 667; ++j)
{
this.showBarrierParticles(posX, posY, posZ, 16, random, flag, blockpos$mutableblockpos);
this.showBarrierParticles(posX, posY, posZ, 32, random, flag, blockpos$mutableblockpos);
}
}
示例11: importFromChamber
import net.minecraft.item.ItemStack; //导入依赖的package包/类
private void importFromChamber(TileEntityPressureChamberValve core) {
ItemStackHandler chamberStacks = core.getStacksInChamber();
for (ItemStack chamberStack : new ItemStackHandlerIterable(chamberStacks)) {
ItemStack inputStack = inventory.getStackInSlot(0);
if ((inputStack.isEmpty() || inputStack.isItemEqual(chamberStack)) && filterHandler.doesItemMatchFilter(chamberStack)) {
int maxAllowedItems = Math.abs(core.getAirHandler(null).getAir()) / PneumaticValues.USAGE_CHAMBER_INTERFACE;
if (maxAllowedItems > 0) {
if (!inputStack.isEmpty()) {
maxAllowedItems = Math.min(maxAllowedItems, chamberStack.getMaxStackSize() - inputStack.getCount());
}
int transferredItems = Math.min(chamberStack.getCount(), maxAllowedItems);
ItemStack toTransferStack = chamberStack.copy().splitStack(transferredItems);
ItemStack excess = inventory.insertItem(0, toTransferStack, true);
if (excess.getCount() < toTransferStack.getCount()) {
// we can transfer at least some of the items
transferredItems = toTransferStack.getCount() - excess.getCount();
core.addAir((core.getAirHandler(null).getAir() > 0 ? -1 : 1) * transferredItems * PneumaticValues.USAGE_CHAMBER_INTERFACE);
toTransferStack.setCount(transferredItems);
inventory.insertItem(0, toTransferStack, false);
chamberStack.shrink(transferredItems);
}
}
}
}
}
示例12: readFromNBT
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().readNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, itemStackHandler, null, tag.getTag("Items"));
progress = tag.getInteger("progress");
fuel = tag.getInteger("fuel");
output = new ItemStack(tag.getCompoundTag("output"));
fluidStack = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("fluidOutput"));
}
示例13: addDrops
import net.minecraft.item.ItemStack; //导入依赖的package包/类
@Override
public void addDrops(NonNullList<ItemStack> drops) {
super.addDrops(drops);
boolean shouldAddTag = false;
for (int i = 0; i < filters.getSlots(); i++) {
if (!filters.getStackInSlot(i).isEmpty()) { //Only set a tag when there are requests.
shouldAddTag = true;
break;
}
}
for (FluidTank fluidFilter : fluidFilters) {
if (fluidFilter.getFluidAmount() > 0) {
shouldAddTag = true;
break;
}
}
if (invisible) shouldAddTag = true;
if (shouldAddTag) {
ItemStack drop = drops.get(0);
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
drop.setTagCompound(tag);
}
}
示例14: create
import net.minecraft.item.ItemStack; //导入依赖的package包/类
/** Creates a melee weapon/armor with randomized stats. */
public static void create(ItemStack stack, NBTTagCompound nbt, World world, ChunkPos pos)
{
/*
* Set rarity
* Set level
* Generate attributes based on Rarity
* - Common: 0-1 attributes
* - Uncommon: 1-2 attributes
* - Rare: 2-3 attributes
* - Legendary: 3-4 attributes
* - Mythic: 4-5 attributes
* Generate base damage and base attack speed
* Generate name based on attributes + material/type
*/
if (Rarity.getRarity(nbt) != Rarity.DEFAULT)
{
IChunkLevelHolder chunkLevelHolder = world.getCapability(CapabilityChunkLevel.CHUNK_LEVEL, null);
IChunkLevel chunkLevel = chunkLevelHolder.getChunkLevel(pos);
int level = chunkLevel.getChunkLevel();
//Rarity.setRarity(nbt, Rarity.getRandomRarity(nbt, ItemGeneratorHelper.rand)); // sets a random rarity
ItemGeneratorHelper.setTypes(stack, nbt);
nbt.setInteger("Level", level); // set level to current player level
ItemGeneratorHelper.setRandomAttributes(stack, nbt, Rarity.getRarity(nbt));
ItemGeneratorHelper.setAttributeModifiers(nbt, stack);
nbt.setInteger("HideFlags", 6); // hides Attribute Modifier and Unbreakable tags
}
}
示例15: removeStackFromSlot
import net.minecraft.item.ItemStack; //导入依赖的package包/类
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (this.theInventory[index] != null)
{
ItemStack itemstack = this.theInventory[index];
this.theInventory[index] = null;
return itemstack;
}
else
{
return null;
}
}