Jump to content

Recommended Posts

Posted

TileEntity:

 

 

public class TileEntityAdvertising extends TileEntity {
private ItemStack[] advertisingItemStacks = new ItemStack[1];
....


public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_)
    {
        this.advertisingItemStacks[p_70299_1_] = p_70299_2_;

        if (p_70299_2_ != null && p_70299_2_.stackSize > this.getInventoryStackLimit())
        {
            p_70299_2_.stackSize = this.getInventoryStackLimit();
        }
    }

@Override
    public void readFromNBT(NBTTagCompound p_145839_1_)
    {
        super.readFromNBT(p_145839_1_);
        NBTTagList nbttaglist = p_145839_1_.getTagList("Items", 10);
        this.advertisingItemStacks = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
            byte b0 = nbttagcompound1.getByte("Slot");

            if (b0 >= 0 && b0 < this.advertisingItemStacks.length)
            {
                this.advertisingItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }


        if (p_145839_1_.hasKey("CustomName", )
        {
            this.field_145958_o = p_145839_1_.getString("CustomName");
        }
    }
    @Override
    public void writeToNBT(NBTTagCompound p_145841_1_)
    {
    	
        super.writeToNBT(p_145841_1_);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.advertisingItemStacks.length; ++i)
        {
            if (this.advertisingItemStacks[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                this.advertisingItemStacks[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }

        p_145841_1_.setTag("Items", nbttaglist);

        if (this.hasCustomInventoryName())
        {
            p_145841_1_.setString("CustomName", this.field_145958_o);
        }
    }

 

 

 

my Block:

 

 

public class BlockAdvertising extends Block implements ITileEntityProvider 
{
....
public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
        if (p_149727_1_.isRemote)
        {
            return true;
            
        }
        else
        {
        	TileEntityAdvertising tileentity = (TileEntityAdvertising)p_149727_1_.getTileEntity(p_149727_2_, p_149727_3_, p_149727_4_);
        	ItemStack stack = p_149727_5_.getHeldItem();
            if (tileentity != null && stack!=null)
            {
            	ItemStack st = stack.copy();
            	Item it = st.getItem();
            	it = stack.getItem();
            	st.stackSize=1;
            	tileentity.setInventorySlotContents(0, st);
            	tileentity.markDirty();
            	

            }

            return true;
        }
    }

@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
	// TODO Auto-generated method stub
    	TileEntityAdvertising tileentity = new TileEntityAdvertising();
         return tileentity;
}
    

public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)
    {


        if (p_149689_6_.hasDisplayName())
        {
            ((TileEntityAdvertising)p_149689_1_.getTileEntity(p_149689_2_, p_149689_3_, p_149689_4_)).func_145951_a(p_149689_6_.getDisplayName());
        }
    }
 /**
     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
     */
@Override
    public int onBlockPlaced(World p_149660_1_, int p_149660_2_, int p_149660_3_, int p_149660_4_, int p_149660_5_, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_)
    {
        int j1 = p_149660_9_;


        return j1;
    }


 

 

 

when player right-click ob this block. tileEntity save one Item from HeldItem

and block must refresh render for show getting item.

 

but redraw not working and when disconnect from world item not saved.(if break block then item dropped correctly)

 

what i need to do for save data and refresh render block?

 

Posted

If I understand your problem correctly, I've had this exact problem before, too. My issue was that the entity's tracking range (specified in EntityRegistry.registerModEntity) wasn't big enough; changing it to a large value like 80 fixed it -- this means that players 80 blocks away will receive updates. In SP, it will just pause updating if the player leaves that range.

I like to make mods, just like you. Here's one worth checking out

Posted

Did you register your TileEntity? To make the client work correctly, you will need to send packets (TileEntities have a description packet, you can use that).

Of course! I forgot to register!

Posted

can't understend.

constructor TileEntity call two time

and created two with different id

public class BlockAdvertising extends Block implements ITileEntityProvider 
{
...
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
	// TODO Auto-generated method stub
    	TileEntityAdvertising tileentity = new TileEntityAdvertising();
         return tileentity;
}

 

when call method: tileentity return with first id

public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
        if (p_149727_1_.isRemote)
        {
            return true;
            
        }
        else
        {
        	TileEntityAdvertising tileentity = (TileEntityAdvertising)p_149727_1_.getTileEntity(p_149727_2_, p_149727_3_, p_149727_4_);

 

when call render method, return tileentity with second id

 

public class AdvertisingRenderer implements ISimpleBlockRenderingHandler {
....
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z,
		Block block, int modelId, RenderBlocks renderer) 
{
	// TODO Auto-generated method stub
TileEntityAdvertising ent = (TileEntityAdvertising)world.getTileEntity(x, y, z);

 

 

 

Posted

The constructor is called twice, ones for the server and ones for the client. That's why you need to sync the two, as the server and the client both have different copies of the TileEntity which can contain different values than the TileEntity on the other side.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

If I understand your problem correctly, I've had this exact problem before, too. My issue was that the entity's tracking range (specified in EntityRegistry.registerModEntity) wasn't big enough; changing it to a large value like 80 fixed it -- this means that players 80 blocks away will receive updates. In SP, it will just pause updating if the player leaves that range.

I'm add:

worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);

in method: MarkDirty() and onDataPacket()

 

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.