本文整理了Java中net.minecraft.item.ItemStack.writeToNBT()
方法的一些代码示例,展示了ItemStack.writeToNBT()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.writeToNBT()
方法的具体详情如下:
包路径:net.minecraft.item.ItemStack
类名称:ItemStack
方法名:writeToNBT
暂无
代码示例来源:origin: Vazkii/Botania
public static void setLensAtPos(ItemStack stack, ItemStack lens, int pos) {
NBTTagCompound cmp = new NBTTagCompound();
if(lens != null)
cmp = lens.writeToNBT(cmp);
ItemNBTHelper.setCompound(stack, TAG_LENS + pos, cmp);
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
private NBTBase createItemTag( final ItemStack i )
{
final NBTTagCompound c = new NBTTagCompound();
if( !i.isEmpty() )
{
i.writeToNBT( c );
}
return c;
}
代码示例来源:origin: Vazkii/Botania
@Nonnull
@Override
public NBTTagCompound writeToNBT(NBTTagCompound cmp) {
NBTTagCompound ret = super.writeToNBT(cmp);
cmp.setInteger(TAG_STACK_COUNT, stacksIn.size());
int i = 0;
for(ItemStack stack : stacksIn) {
NBTTagCompound stackcmp = stack.writeToNBT(new NBTTagCompound());
cmp.setTag(TAG_STACK + i, stackcmp);
i++;
}
return ret;
}
代码示例来源:origin: Vazkii/Botania
@Override
public void setCosmeticItem(ItemStack stack, ItemStack cosmetic) {
NBTTagCompound cmp = new NBTTagCompound();
if(!cosmetic.isEmpty())
cmp = cosmetic.writeToNBT(cmp);
ItemNBTHelper.setCompound(stack, TAG_COSMETIC_ITEM, cmp);
}
代码示例来源:origin: Vazkii/Botania
@Override
public ItemStack setCompositeLens(ItemStack sourceLens, ItemStack compositeLens) {
if(!compositeLens.isEmpty()) {
NBTTagCompound cmp = compositeLens.writeToNBT(new NBTTagCompound());
ItemNBTHelper.setCompound(sourceLens, TAG_COMPOSITE_LENS, cmp);
}
return sourceLens;
}
代码示例来源:origin: Vazkii/Botania
@Override
public void writePacketNBT(NBTTagCompound cmp) {
super.writePacketNBT(cmp);
NBTTagCompound cmp1 = new NBTTagCompound();
if(!stack.isEmpty())
cmp1 = stack.writeToNBT(cmp1);
cmp.setTag(TAG_STACK, cmp1);
}
代码示例来源:origin: Vazkii/Botania
@Override
public void writePacketNBT(NBTTagCompound par1nbtTagCompound) {
super.writePacketNBT(par1nbtTagCompound);
NBTTagCompound cmp = new NBTTagCompound();
if(!requestTarget.isEmpty())
cmp = requestTarget.writeToNBT(cmp);
par1nbtTagCompound.setTag(TAG_REQUEST_TARGET, cmp);
par1nbtTagCompound.setInteger(TAG_ITEM_COUNT, itemCount);
}
代码示例来源:origin: Vazkii/Botania
@Override
public void writePacketNBT(NBTTagCompound cmp) {
cmp.setInteger(TAG_MANA, mana);
cmp.setInteger(TAG_MANA_REQUIRED, manaRequired);
cmp.setInteger(TAG_STAGE, stage.ordinal());
cmp.setInteger(TAG_STAGE_TICKS, stageTicks);
cmp.setInteger(TAG_STAGE_3_END_TICKS, stage3EndTicks);
NBTTagCompound itemCmp = new NBTTagCompound();
if(!itemToEnchant.isEmpty())
itemCmp = itemToEnchant.writeToNBT(itemCmp);
cmp.setTag(TAG_ITEM, itemCmp);
String enchStr = enchants.stream()
.map(e -> Enchantment.REGISTRY.getNameForObject(e.enchantment) + "=" + e.enchantmentLevel)
.collect(Collectors.joining(","));
cmp.setString(TAG_ENCHANTS, enchStr);
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
public void writeToNBT( final NBTTagCompound c )
{
for( int x = 0; x < this.facades; x++ )
{
if( this.storage.getFacade( x ) != null )
{
final NBTTagCompound data = new NBTTagCompound();
this.storage.getFacade( x ).getItemStack().writeToNBT( data );
c.setTag( "facade:" + x, data );
}
}
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
private void setColor( final ItemStack is, final ItemStack newColor )
{
final NBTTagCompound data = Platform.openNbtData( is );
if( newColor.isEmpty() )
{
data.removeTag( "color" );
}
else
{
final NBTTagCompound color = new NBTTagCompound();
newColor.writeToNBT( color );
data.setTag( "color", color );
}
}
代码示例来源:origin: Vazkii/Botania
public static void setLens(ItemStack stack, ItemStack lens) {
if(hasClip(stack))
setLensAtPos(stack, lens, getClipPos(stack));
NBTTagCompound cmp = new NBTTagCompound();
if(!lens.isEmpty())
cmp = lens.writeToNBT(cmp);
ItemNBTHelper.setCompound(stack, TAG_LENS, cmp);
}
代码示例来源:origin: Vazkii/Botania
@Override
public void writeEntityToNBT(NBTTagCompound compound) {
super.writeEntityToNBT(compound);
if(!stack.isEmpty()) {
compound.setTag("fly_stack", stack.writeToNBT(new NBTTagCompound()));
}
compound.setBoolean("flare", isFire());
}
代码示例来源:origin: Vazkii/Botania
@Override
public void writeToPacketNBT(NBTTagCompound cmp) {
super.writeToPacketNBT(cmp);
cmp.setInteger(TAG_COOLDOWN, cooldown);
cmp.setInteger(TAG_DIGESTING_MANA, digestingMana);
cmp.setTag(TAG_LAST_FOOD, lastFood.writeToNBT(new NBTTagCompound()));
cmp.setInteger(TAG_LAST_FOOD_COUNT, lastFoodCount);
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
public void writeToNBT( final NBTTagCompound i )
{
this.getDefinition().writeToNBT( i );
i.setLong( "Cnt", this.getStackSize() );
i.setLong( "Req", this.getCountRequestable() );
i.setBoolean( "Craft", this.isCraftable() );
}
代码示例来源:origin: Vazkii/Botania
private void saveRecipeToStack(ItemCraftedEvent event, ItemStack stack) {
NBTTagCompound cmp = new NBTTagCompound();
NBTTagCompound cmp1 = new NBTTagCompound();
ItemStack result = CraftingManager.findMatchingResult((InventoryCrafting) event.craftMatrix, event.player.world);
if(!result.isEmpty()) {
cmp1 = result.writeToNBT(cmp1);
cmp.setTag(TAG_ITEM_PREFIX + 9, cmp1);
for(int i = 0; i < 9; i++) {
cmp1 = new NBTTagCompound();
ItemStack stackSlot = event.craftMatrix.getStackInSlot(i);
if(!stackSlot.isEmpty()) {
ItemStack writeStack = stackSlot.copy();
writeStack.setCount(1);
cmp1 = writeStack.writeToNBT(cmp1);
}
cmp.setTag(TAG_ITEM_PREFIX + i, cmp1);
}
}
ItemNBTHelper.setCompound(stack, TAG_LAST_CRAFTING, cmp);
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
private void addItems( final NBTTagCompound data, final InvTracker inv, final int offset, final int length )
{
final String name = '=' + Long.toString( inv.which, Character.MAX_RADIX );
final NBTTagCompound tag = data.getCompoundTag( name );
if( tag.hasNoTags() )
{
tag.setLong( "sortBy", inv.sortBy );
tag.setString( "un", inv.unlocalizedName );
}
for( int x = 0; x < length; x++ )
{
final NBTTagCompound itemNBT = new NBTTagCompound();
final ItemStack is = inv.server.getStackInSlot( x + offset );
// "update" client side.
ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() );
if( !is.isEmpty() )
{
is.writeToNBT( itemNBT );
}
tag.setTag( Integer.toString( x + offset ), itemNBT );
}
data.setTag( name, tag );
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
if( this.forcePlan && this.myPlan != null )
{
final ItemStack pattern = this.myPlan.getPattern();
if( !pattern.isEmpty() )
{
final NBTTagCompound compound = new NBTTagCompound();
pattern.writeToNBT( compound );
data.setTag( "myPlan", compound );
data.setInteger( "pushDirection", this.pushDirection.ordinal() );
}
}
this.upgrades.writeToNBT( data, "upgrades" );
this.settings.writeToNBT( data );
return data;
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.cm.writeToNBT( data );
data.setByte( "paintedColor", (byte) this.paintedColor.ordinal() );
data.setLong( "securityKey", this.securityKey );
this.getConfigSlot().writeToNBT( data, "config" );
final NBTTagCompound storedItems = new NBTTagCompound();
int offset = 0;
for( final IAEItemStack ais : this.inventory.getStoredItems() )
{
final NBTTagCompound it = new NBTTagCompound();
ais.createItemStack().writeToNBT( it );
storedItems.setTag( String.valueOf( offset ), it );
offset++;
}
data.setTag( "storedItems", storedItems );
return data;
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
public void writeToNBT( final NBTTagCompound data )
{
this.config.writeToNBT( data, "config" );
this.patterns.writeToNBT( data, "patterns" );
this.storage.writeToNBT( data, "storage" );
this.upgrades.writeToNBT( data, "upgrades" );
this.cm.writeToNBT( data );
this.craftingTracker.writeToNBT( data );
data.setInteger( "priority", this.priority );
final NBTTagList waitingToSend = new NBTTagList();
if( this.waitingToSend != null )
{
for( final ItemStack is : this.waitingToSend )
{
final NBTTagCompound item = new NBTTagCompound();
is.writeToNBT( item );
waitingToSend.appendTag( item );
}
}
data.setTag( "waitingToSend", waitingToSend );
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
public void writeToNBT( final NBTTagCompound data )
{
data.setInteger( "hasRedstone", this.hasRedstone.ordinal() );
final IFacadeContainer fc = this.getFacadeContainer();
for( final AEPartLocation s : AEPartLocation.values() )
{
fc.writeToNBT( data );
final IPart part = this.getPart( s );
if( part != null )
{
final NBTTagCompound def = new NBTTagCompound();
part.getItemStack( PartItemStack.WORLD ).writeToNBT( def );
final NBTTagCompound extra = new NBTTagCompound();
part.writeToNBT( extra );
data.setTag( "def:" + this.getSide( part ).ordinal(), def );
data.setTag( "extra:" + this.getSide( part ).ordinal(), extra );
}
}
}
内容来源于网络,如有侵权,请联系作者删除!