本文整理汇总了Java中net.minecraft.item.ItemStack.getTagCompound方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.getTagCompound方法的具体用法?Java ItemStack.getTagCompound怎么用?Java ItemStack.getTagCompound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.item.ItemStack
的用法示例。
在下文中一共展示了ItemStack.getTagCompound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCraftingResult
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = ItemStack.field_190927_a;
for (int i = 0; i < inv.getSizeInventory() && itemstack.func_190926_b(); ++i)
{
ItemStack itemstack1 = inv.getStackInSlot(i);
if (itemstack1.getItem() == Items.FILLED_MAP)
{
itemstack = itemstack1;
}
}
itemstack = itemstack.copy();
itemstack.func_190920_e(1);
if (itemstack.getTagCompound() == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
itemstack.getTagCompound().setInteger("map_scale_direction", 1);
return itemstack;
}
示例2: writeItemStackToBuffer
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
* Writes the ItemStack's ID (short), then size (byte), then damage. (short)
*/
public void writeItemStackToBuffer(ItemStack stack)
{
if (stack == null)
{
this.writeShort(-1);
}
else
{
this.writeShort(Item.getIdFromItem(stack.getItem()));
this.writeByte(stack.stackSize);
this.writeShort(stack.getMetadata());
NBTTagCompound nbttagcompound = null;
if (stack.getItem().isDamageable() || stack.getItem().getShareTag())
{
nbttagcompound = stack.getTagCompound();
}
this.writeNBTTagCompoundToBuffer(nbttagcompound);
}
}
示例3: onUpdate
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void onUpdate(ItemStack remote, World worl, Entity entity, int slot, boolean holdingItem) {
if (!worl.isRemote) {
NBTTagCompound tag = remote.getTagCompound();
if (tag != null) {
if (tag.hasKey("securityX")) {
int x = tag.getInteger("securityX");
int y = tag.getInteger("securityY");
int z = tag.getInteger("securityZ");
int dimensionId = tag.getInteger("securityDimension");
WorldServer world = DimensionManager.getWorld(dimensionId);
if (world != null) {
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
if (!(te instanceof TileEntitySecurityStation)) {
tag.removeTag("securityX");
tag.removeTag("securityY");
tag.removeTag("securityZ");
tag.removeTag("securityDimension");
}
}
}
}
}
}
示例4: getGPSLocation
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static BlockPos getGPSLocation(ItemStack gpsTool) {
NBTTagCompound compound = gpsTool.getTagCompound();
if (compound != null) {
String var = getVariable(gpsTool);
if (!var.equals("") && PneumaticCraftRepressurized.proxy.getClientWorld() == null) {
BlockPos pos = GlobalVariableManager.getInstance().getPos(var);
setGPSLocation(gpsTool, pos);
}
int x = compound.getInteger("x");
int y = compound.getInteger("y");
int z = compound.getInteger("z");
if (x != 0 || y != 0 || z != 0) {
return new BlockPos(x, y, z);
} else {
return null;
}
} else {
return null;
}
}
示例5: onItemRightClick
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
if(worldIn.isRemote)
{
//check to make sure the player didn't just click on a chalk tile
//it's a little hacky but it gets the job done eh?
if (worldIn.getBlockState(playerIn.rayTrace(5.0f, 0).getBlockPos()).getBlock()!= ModBlocks.chalkBase) {
//if the scrap has nbtdata for text, open it. Otherwise open a blank scrap
if (itemStackIn.getTagCompound() == null || !itemStackIn.getTagCompound().hasKey("text"))
Minecraft.getMinecraft().displayGuiScreen(new GuiPaperScrap(""));
else
Minecraft.getMinecraft().displayGuiScreen(new GuiPaperScrap(itemStackIn.getTagCompound().getString("text")));
}
}
return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
}
示例6: EntityFireworkRocket
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public EntityFireworkRocket(World worldIn, double x, double y, double z, ItemStack givenItem)
{
super(worldIn);
this.fireworkAge = 0;
this.setSize(0.25F, 0.25F);
this.setPosition(x, y, z);
int i = 1;
if (givenItem != null && givenItem.hasTagCompound())
{
this.dataWatcher.updateObject(8, givenItem);
NBTTagCompound nbttagcompound = givenItem.getTagCompound();
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("Fireworks");
if (nbttagcompound1 != null)
{
i += nbttagcompound1.getByte("Flight");
}
}
this.motionX = this.rand.nextGaussian() * 0.001D;
this.motionZ = this.rand.nextGaussian() * 0.001D;
this.motionY = 0.05D;
this.lifetime = 10 * i + this.rand.nextInt(6) + this.rand.nextInt(7);
}
示例7: moveItemsIntoStack
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
private static void moveItemsIntoStack(IInventory chest, ItemStack stack)
{
if (stack.getTagCompound() == null)
{
stack.setTagCompound(new NBTTagCompound());
}
NBTTagList nbtList = new NBTTagList();
for (int i = 0; i < chest.getSizeInventory(); ++i)
{
if (!chest.getStackInSlot(i).isEmpty())
{
NBTTagCompound nbtTabCompound2 = new NBTTagCompound();
nbtTabCompound2.setShort("Slot", (short) i);
chest.getStackInSlot(i).copy().writeToNBT(nbtTabCompound2);
chest.setInventorySlotContents(i, ItemStack.EMPTY);
nbtList.appendTag(nbtTabCompound2);
}
}
stack.getTagCompound().setTag("Items", nbtList);
}
示例8: getMaxItemUseDuration
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public int getMaxItemUseDuration(ItemStack is)
{
NBTTagCompound tag = is.getTagCompound();
if(tag != null)
{
Instrument instrument = InstrumentLibrary.getInstrumentByName(tag.getString("itemName"));
if(instrument != null)
{
return Math.round(instrument.tuning.fadeout * 20);
}
}
return 0;
}
示例9: updateEntity
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@SubscribeEvent
public void updateEntity(LivingEvent.LivingUpdateEvent event){
if(event.getEntity() instanceof EntityPlayer && event.getEntity().getAir() <= 300 - Config.ARMOR_TICKS_PER_LANOLIN){
// The entity is a player and is not at full air
if(event.getEntity().isInsideOfMaterial(Material.WATER)){
for(int i = 0; i < 4; i++){
ItemStack armorPiece = ((EntityPlayer) event.getEntity()).inventory.armorInventory.get(i);
if(armorPiece != ItemStack.EMPTY){
NBTTagCompound tags = armorPiece.getTagCompound();
if(tags != null && tags.hasKey("lanolin")){
// Found armor with lanolin. Reset air and remove a piece of lanolin.
event.getEntity().setAir(300);
if(tags.getInteger("lanolin") == 1){
// No more lanolin on this item, remove the tag
tags.removeTag("lanolin");
}
else{
tags.setInteger("lanolin", tags.getInteger("lanolin")-1);
}
armorPiece.setTagCompound(tags);
((EntityPlayer) event.getEntity()).inventory.armorInventory.set(i, armorPiece);
break;
}
}
}
}
}
}
示例10: apply
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean apply(@Nullable ItemStack used)
{
if (used != null)
{
for (ItemStack stack : getMatchingStacks())
{
if (stack.getItem() == used.getItem())
{
int i = stack.getMetadata();
if (i == 32767 || i == used.getMetadata())
{
if (used.getTagCompound() != null && stack.getTagCompound() != null)
{
NBTTagCompound tagStack = stack.getTagCompound();
NBTTagCompound tagUsed = used.getTagCompound();
for (String s : tagStack.getKeySet())
{
if (!tagUsed.hasKey(s))
return false;
if (!tagUsed.getTag(s).equals(tagStack.getTag(s)))
return false;
}
}
return true;
}
}
}
}
return false;
}
示例11: extractEnergy
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) {
return 0;
}
int energy = container.getTagCompound().getInteger("Energy");
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
if (!simulate) {
energy -= energyExtracted;
container.getTagCompound().setInteger("Energy", energy);
}
return energyExtracted;
}
示例12: GuiScreenBook
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public GuiScreenBook(EntityPlayer player, ItemStack book, boolean isUnsigned)
{
this.editingPlayer = player;
this.bookObj = book;
this.bookIsUnsigned = isUnsigned;
if (book.hasTagCompound())
{
NBTTagCompound nbttagcompound = book.getTagCompound();
this.bookPages = nbttagcompound.getTagList("pages", 8);
if (this.bookPages != null)
{
this.bookPages = (NBTTagList)this.bookPages.copy();
this.bookTotalPages = this.bookPages.tagCount();
if (this.bookTotalPages < 1)
{
this.bookTotalPages = 1;
}
}
}
if (this.bookPages == null && isUnsigned)
{
this.bookPages = new NBTTagList();
this.bookPages.appendTag(new NBTTagString(""));
this.bookTotalPages = 1;
}
}
示例13: getCurrentDestination
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static int getCurrentDestination(ItemStack stack) {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null) {
return -1;
}
return tag.getInteger("destination");
}
示例14: onItemUse
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack iStack = player.getHeldItem(hand);
if (!world.isRemote) {
EntityDrone drone = new EntityLogisticsDrone(world, player);
BlockPos placePos = pos.offset(facing);
drone.setPosition(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5);
world.spawnEntity(drone);
NBTTagCompound stackTag = iStack.getTagCompound();
NBTTagCompound entityTag = new NBTTagCompound();
drone.writeEntityToNBT(entityTag);
if (stackTag != null) {
entityTag.setFloat("currentAir", stackTag.getFloat("currentAir"));
entityTag.setInteger("color", stackTag.getInteger("color"));
entityTag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, stackTag.getCompoundTag(ChargeableItemHandler.NBT_UPGRADE_TAG));
}
drone.readEntityFromNBT(entityTag);
addLogisticsProgram(pos, drone.progWidgets);
if (iStack.hasDisplayName()) drone.setCustomNameTag(iStack.getDisplayName());
drone.naturallySpawned = false;
//TODO 1.8 check if valid replacement drone.onSpawnWithEgg(null);
drone.onInitialSpawn(world.getDifficultyForLocation(placePos), null);
iStack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
示例15: getMoleculeName
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public String getMoleculeName(ItemStack stack)
{
NBTTagCompound tag = stack.getTagCompound();
String name = "unknown";
int amount = 0;
if(tag != null){
name = tag.getString("molecule_name");
amount = tag.getInteger("quantity");
}
return I18n.format("molecule."+name+".name")+" ("+amount+")";
}