Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello,

 

I'm trying to figure out how to change a variable in my TileEntity, when a button is pressed and updating all the players about that change. I have 1 number and 2 buttons one for increment the other for decrement. I think, i need packets. So i'm sending a packet when a button is pressed like this:

 

 

@Override
protected void actionPerformed(GuiButton par1GuiButton)
{
	switch (par1GuiButton.id)
	{

	case 0:
		PacketDispatcher.sendPacketToServer(PacketHelper.SendPacket(1, Arrays.asList(1, tileentity.xCoord, tileentity.yCoord, tileentity.zCoord)));
	break;

	case 1:
		PacketDispatcher.sendPacketToServer(PacketHelper.SendPacket(1, Arrays.asList(2, tileentity.xCoord, tileentity.yCoord, tileentity.zCoord)));
	break;

	}
}

 

 

My PacketHelper class is like this:

 

 

public static Packet SendPacket(int id, List<Integer> data)
{
	ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(;		
	DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream);

	try 
	{
	    dataoutputstream.writeInt(id);
	    
	    for (int element : data)
	    {
	    	dataoutputstream.writeInt(element);
	    }
	}

	catch (Exception ex) 
	{
	    ex.printStackTrace();
	}

	Packet250CustomPayload packet = new Packet250CustomPayload();

	packet.channel = "brickcraft";
	packet.data = bytearrayoutputstream.toByteArray();
	packet.length = bytearrayoutputstream.size();

	return packet;
}

 

 

It just creates a packet with a integer list for data storing.

 

Here is my PacketHandler class:

 

 

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) 
{
	DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(packet.data));
        
	int id;
	ArrayList<Integer> data = new ArrayList<Integer>();

        try 
        {
            id = datainputstream.readInt();
            
            while (datainputstream.available() > 0)
            {
            	data.add(datainputstream.readInt());
            }
        }
        
        catch (IOException ex)
        {	
            ex.printStackTrace();
            
            return;
        }
        
        HandlePacket(id, data, (EntityPlayer)player);
}

void HandlePacket(int id, ArrayList<Integer> data, EntityPlayer player)
{		
	if (id == 1)
	{
		if (player.worldObj.getBlockTileEntity(data.get(1), data.get(2), data.get(3)) != null)
		{
			PoseblockTileEntity tileentity = (PoseblockTileEntity)player.worldObj.getBlockTileEntity(data.get(1), data.get(2), data.get(3));

			if (data.get(0) == 1)
			{
				tileentity.SetScale(tileentity.scale - 1);
			}

			if (data.get(0) == 2)
			{
				tileentity.SetScale(tileentity.scale + 1);
			}
		}
	}
}

 

 

I checked if a packet is incoming and it is, but the var in the GUI is not updating. I've tried it with world.markBlockForUpdate(x, y, z) but that doesn't worked.

 

 

Thank you in advance!

 

ss7

You sir are a god damn hero.

  • Author

Hello,

 

Yes, i have overridden that already and tried both

markBlockForUpdate()

and

onInventoryChanged()

but none of them works.

 

ss7

You sir are a god damn hero.

  • Author

Hello,

 

Problem

SOLVED

it was that

 

if (scale > 0 && scale > 11)
	{
		this.scale = scale;
	}

 

that was wrong, now it works :P

 

Thank you!

 

ss7

You sir are a god damn hero.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.