Jump to content

[1.8] how do you store nbttags in a block ??


perromercenary00

Recommended Posts

good nigths

 

i been working on this

 

it must be very similar to this one

 

 

this is mi version of the ares FMG concept from early 1980 this  gun has to modes, the first as a weapon when in the players hand, and the second is folded as a block,  the idea is to spawn this one in block mode inside a dungeon hiden on pictures or something to later the player could find and use 

 

the gun is ready as you could see

the trouble is that i dont know how to store the values of the nbttags states and munition when in block mode soo when i folded and put it as a block in the world it reset all the values, the munition came back as full and the shoot mode goes to semiautomatic

 

i been reading about tile entities but the guides i found are mostly to 1.7 and the more complete guide i found for 1.8 was this

http://www.orangetutorial.com/tile-entity/

 

someone can point to a more complete guide or tell me how i store nbttags in a block in 1.8 minecraft ??

Link to comment
Share on other sites

If you make the block you what to store nbt in into an ItemStack, you can access it's stackTagCompound and make it equal a new NBTTagCompound(); then store information in this compound. Like this:

ItemStack block = new ItemStack(blockYouWantNbtIn);

block.stackTagCompound = new NBTTagCompound();

block.stackTagCompound.setString("whatYouWantToStore", "theValue");

 

If that makes sense.

Link to comment
Share on other sites

you need to attach a tileentity to your block. The tile entity can store NBT tags(and do other fun stuff).

 

http://www.orangetutorial.com/tile-entity/#sthash.A0mSVOdk.dpbs

How much wood could a woodchuck chuck if a wood chuck could chuck wood - Guybrush Treepwood

 

I wrote my own mod ish... still a few bugs to fix. http://thaumcraft.duckdns.org/downloads/MagicCookies-1.0.6.4.jar

Link to comment
Share on other sites

little stuck here

 

take the nbttags from this block "blk" and put it in the ItemsTack "subfusil" and then put that in the the players hand look posible

 

but take the nbttas from the ItemStack "subfusil" put it in a block and then put that block in the world dont seem so feasible

 

the main trouble i find to use this is the lack in 1.8 of the methods

worldIn.getBlockTileEntity(par2, par3, par4);  //(pos)
worldIn.setBlockTileEntity(mitileEntity,  pos);  //(pos)

 

this shit is surely atached now to IBlockStates but i dont find it in eclipse

 

take the bnts from the block and put it on the gun and put that gun in steves/alex hand whent they rigthclick whith empty hand on the block if there is not nbt in the block initialize gun whith default values ,(full amo, semiAutoMode)

this block alredy has tileEntity

public class subfusilAresFMG_blocke extends Block implements ITileEntityProvider

  //###########################################################3
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
    	   	
    	
    	int hand = playerIn.inventory.currentItem;
    	
    	/*
*		ItemStack block = new ItemStack(blockYouWantNbtIn);

*		block.stackTagCompound = new NBTTagCompound();

*		block.stackTagCompound.setString("whatYouWantToStore", "theValue");
 */

    	
    	IBlockState blkst = worldIn.getBlockState(pos);
    	Block blk = blkst.getBlock();
    	ItemStack block = new ItemStack(blk);
    	
    	ItemStack subfusil = new ItemStack(MercenaryModItems.subfusilAresFMG, 1, 6);
    	intialize(subfusil, playerIn);
    	
	NBTTagCompound tags = block.getTagCompound();
	if (tags != null) 
	{
		subfusil.setTagCompound(etiquetas);
	}
    	    	    	
    	ItemStack objeto=playerIn.inventory.getStackInSlot(hand);
    	
    	if ( (objeto == null) & (!playerIn.isSneaking()) )
    	{
    		playerIn.inventory.setInventorySlotContents(hand, subfusil);
    		worldIn.setBlockToAir(pos);
    	}
    	
    return false;}
// #########################################################################3

 

 

when sneaking and rigth click the upper part of a block take the values of this gun "subfusil Ares" put it in a block and then put that block in the world

// ######################################################################################3	
@Override
 public boolean onItemUse(ItemStack subfusil, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
    {

	if (!worldIn.isRemote)
	{
		//chat.chatga(playerIn, "onItemUse()");

        if ( (side == EnumFacing.UP) & ( playerIn.isSneaking() ) & (worldIn.isAirBlock(pos.up())) )
        {
     
           	//chat.chatga(playerIn, "lado de arriba");
        	int hand = playerIn.inventory.currentItem;
        	
        	NBTTagCompound etiquetas = subfusil.getTagCompound();
        
        	
        	Block blk = MercenaryModItems.subfusilAresFMG_blocke;
        	ItemStack block = new ItemStack(blk);
        	block.setTagCompound(etiquetas);
        
//heres where i tink the nbtags get losse
         	        Item iblock = block.getItem();
        	blk = Block.getBlockFromItem(iblock);
        		        	
        	IBlockState state = blk.getDefaultState();
        	PropertyDirection FACING = PropertyDirection.create("facing");
        	
        	worldIn.setBlockState(pos.up(), state.withProperty(FACING, getFacingFromEntity(worldIn, pos, playerIn )), 2);
    
        	 playerIn.inventory.setInventorySlotContents(hand, null );
        }
	}    
        return false;    
    } 
// ######################################################################################3

 

 

thanks

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.