Jump to content

[1.7.10] [SOLVED] Problem with list for tasks.


SSslimer

Recommended Posts

Thats why the same list had two versions :D I will remember it for future project works.

Now I am working on getting task from list by id.

 

I have done sth like this:

    public EntityAIBaseOrder getOrderById(int par)
    {
    	switch(par)
    	{
    		case 0:
    			return new EntityAIStayHere(villager, 0);
    			
    		default:
    			return null;
    	}    	   	
    } 

 

this.orders.add(j, orderSystem.getOrderById(buffer.readInt())); 

That code adds to my empty list(its on client) object returned from method up with par as a id get from toBytes().

 

 

 

@Edit, I think everythink works as I wanted. Code is correct, no errors.

Last question in that topic. How to make gui actionPerformed() wait for a moment to run some method(I want to refresh screen, but it refreshes before tasks are synchronized)

 

Link to comment
Share on other sites

Client has only one instance of gui - well, not one, but you don't really care if there is one or more, depends on routine (it can be even static). As long as you keep that instance you can even call inti() from outside.

 

I wouldn't use tick because that's next thing that will need coding not-readable stuff, also, you don't know when packets arrive, it can be 10 ticks or even 100 (if you have lags).

 

Make a method inside you GUI that will look: (I mean, not exacly like it, but you get the idea - call initGui() after you put your task in list)

public void refresh(List<task> list)
{
this.taskList = list;
this.initGui();
}

...and call it from packet receiver.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Why would you...

 

I alredy told you Guis are constructed when you call:

mc.displayGuiScreen(new GuiScreen());

 

To understand this better:

@Override
public void finalize()
{
System.out.println("THIS GUI FINALIZED");
}

 

Put this inside you GuiScreen class.

 

Now - here's how thing happen: (let's call you gui "MyGui.class" - extending GuiScreen)

1. You open gui - MyGui.constructor

2. initGui() is called, you add buttons and task lists.

3. You press button to add/remove SOME task from some entity.

4. Server gets you "button clicked" and if can, adds some task to server-side task list of entity.

5. You should have some wrapper method like onTaskAdded() which you call after you add task to entity list and after that send apcket to client.

6. Client receives packet and inside onMessage you simply do MyGui.getCurrentlyViewedEntity().addTaskFromId(message.taskID).

7. Then (still inside onMessage) you call MyGui.getInstance().initGui();

 

Now, to have instance you can simply add field in MyGui.class: static MyGui instance, and inside constructor set it to this.

I belive there is also minecraft method to get currendly displayed screen.

Try something like: Minecraft.getMinecraft().*****  - there should be method proposed that will return currentScreen.

 

 

Provide new code, or better - github.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

HINT:

To sand multiple data between server an client you can use NBT system, that is ready to work, example:

Goal: transfer using 1 packet, EntityPlayer, int, int and boolean

First: let's convert player in string using UUID system (for recovery afterwards we will also need id of dimension he's in, that's first int):

player.func_146094_a(player.getGameProfile()).toString()

Now we need to transfer String, int, int and boolean.

How to do that?

- Using NBT!

NBTTagCompound data = new NBTTagCompound();
	data.setString("player", player.func_146094_a(player.getGameProfile()).toString());
	data.setBoolean("fixed", fixed);
	data.setInteger("mode", mode);
	data.setInteger("dim", player.worldObj.provider.dimensionId);

Now a general question: how to convert it in bytes?

- FML did all for you: using cpw.mods.fml.common.network.ByteBufUtils.writeTag you can convert NBT into bytes:

ByteBufUtils.writeTag(buf, data);

 

Now how to read it?

- I'll say only one thing about it:

NBTTagCompound data = ByteBufUtils.readTag(buf);

 

What did you learn:

Using NBT, you can transfer multiple data in 1 packet. Data that you can transfer using NBT: String, byte, short, long, int, boolean, double, float, int[]... And others if you create new types of NBTTags!

Link to comment
Share on other sites

Ernio thanks for help, refreshing gui works, very important to close current gui to avoid multiple gui on one screen.

You wrote too much, I told you that list etc works fine, only gui refreshing had been to do.

 

elix I dont want to move my packet code into NBT unless I do customization for my tasks.

I am sure that I will need to use NBT to save and load tasks when game loads etc.

 

@Offtopic

diesieben07 we can read int etc. in packet class only in specific order?

Can we read specific byte eg. second or 9th?

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.