Jump to content

Recommended Posts

Posted

Hey,

in my gui when button is activated it send packet to server.

By data send to server it adds task to mob tasks list.

In packet sender class I can see that size of the list is growing up correctly, but when I try to get data from my list by entity class system tells that list size is 0.

I will post some code if it helps.

Posted
  On 2/6/2015 at 1:08 PM, SSslimer said:

when I try to get data from my list by entity class system tells that list size is 0.

I will post some code if it helps.

 

I don't understand this part.  Post this code

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Ok, I will post all code for better explanation.

 

In method actionPerformed().

ModBetterWorld.packets.sendToServer(new GuiRequestPacketAddOrder(this.villager.getEntityId(), guiButton.id));

 

 

That code adds tasks to list, entity is set by id system and task by my other list with possible tasks to add.

In that part of code, system prints that my taskEntries(I need to change the name) is growing on each button click so system adds tasks to list.

@Override
public IMessage onMessage(GuiRequestPacketAddOrder message, MessageContext ctx)
{
	EntityPlayer player = ctx.getServerHandler().playerEntity;
	World world = player.worldObj;
	EntityBetterVillager entity = (EntityBetterVillager) world.getEntityByID(message.entityID);

	entity.order.addTask((EntityAIBaseOrder) entity.possibleOrders.get(message.buttonID - 3));	
	System.out.println(entity.order.taskEntries.size());
	return null;
} 

 

Code for adding tasks to list using method.

    public List taskEntries = new ArrayList();

    public void addTask(EntityAIBaseOrder p_75776_2_)
    {
        this.taskEntries.add(p_75776_2_);
    }

 

That code is in initGui(). It should return the same size as in packet class but it doesnt.

System.out.println(this.villager.order.taskEntries.size());

 

 

Posted
  On 2/6/2015 at 5:33 PM, SSslimer said:

Ok but are any way to get tasks on clinent side?

I need it to my gui, because clicling another buttons will remove tasks.

 

Send a packet to the server, the GUI is only a presentation layer nothing except drawing should be computed on the Client.

 

MC Client = Presentation Layer

Packets = Transport Layer

MC Server = Logic/Business Layer

 

If you follow that pattern everything should work, clicking a button should just send a packet and the server does everything.

I require Java, both the coffee and the code :)

Posted

Using system.out.print I have noticed that list of tasks is null only in one side.

So the size on client and server isnt synchronized.

Only the server side list is changing. I dont know more but I think that I need to get my list from server not from client as I have in gui.

Posted

You will have to make response Server->Client packet.

 

Simply send packet to player that is viewing GUI whenever task-list changes. You can put response in onMessage or directly into entity class (make wrapper for addTask that will take addTaskWrapped(EntityAIBaseOrder task, EntityPlayer player) and send update packet to player from arguments). You will ofc have to also put packet-update in other places. I'd suggest making refresh button on client-side which would request tasks from server.

  Quote

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

Posted

I think I found a solution.

Few weeks earlier I have similar problem with inventory.

I will try to refresh(send packet from server to client) each time my gui changes

Now I need to make new packet class and I will post later if I managed to do that.

Posted

Is any good way to write and read an object like ArrayList??

I can try to make an id for each order and write only int and than read that id and set a order maching to that id.

I dont know is my way quite good so I am waiting for your sugestions.

Posted

I know the same is with ItemStack, it can be sended as primitives.

But my orders arent made in that way. I think the easiest will be writing the order id and other settings and that reading it and combining into order object. I am not sure will it work.

Posted

"But my orders arent made in that way."

 

There is no other way. Evrything IS made of bytes. If it exists, you can write it to buffer.

 

Maybe share how are your orders made?

  Quote

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

Posted

General order class:

public abstract class EntityAIBaseOrder
{
private int id;

public EntityAIBaseOrder(int par)
{
	this.id = par;
}

public int getId()
{
	return id;
}

    //Zwraca czy rozkaz powinien zostac wykonany, cos co od razu dziala to true, jesli musi byc cos spelnione to dac warunki
    public abstract boolean shouldExecute();

    //To jest wykonywane tylko raz podczas zaczecia polecenia, tutaj powinny byc cele poczatkowe
    public void startExecuting() {}

    //Wykonywane, gdy zadanie jest przerwane.
    public void resetTask() {}

    //Wykowywane jest za kazdym tickiem systemu
    public void updateTask() {}
    
    //Zwraca czy rozkaz zostal rozpoczety
    public abstract boolean hasStarted();
    
    //Zwraca czy cele rozkazu zostaly osiagniete
    public abstract boolean isDone();
}

 

My exaple of order to look does the system work.

public class EntityAIStayHere extends EntityAIBaseOrder
{
    private EntityBetterVillager villager;
    private boolean isStarted;
    private boolean isDone;
    
    public EntityAIStayHere(EntityBetterVillager villager, int par)
    {
    	super(par);
    	this.villager = villager;
    }

    public boolean shouldExecute()
    {
    	return true;
    }

    public void startExecuting()
    {
    	this.isStarted = true;
    	this.villager.getNavigator().tryMoveToXYZ(this.villager.posX, this.villager.posY, this.villager.posZ, 0.6D);
    }   

    public void resetTask()
    {
    	this.isStarted = false;
    	this.villager.getNavigator().clearPathEntity();
    }

    public void updateTask()
    {
    	
    }

@Override
public boolean hasStarted()
{
	return isStarted;
}

@Override
public boolean isDone()
{
	return false;
}

That order might not work, but its set to not be removed.

 

Tell me how do you want to get from it primitives types without using id or sth like this.

 

Posted

Are those tasks shared between server-client? (both client and server has every task class and can do whetever he wants with it)

In that case - yeah, use ID for each task and send only packet with id. I suggest having HashMap with all registered tasks (id, task) and make method getTaskById();

 

And that'll be perfectly fine. I was thinking that you are making custom tasks inside config and want to send them to client.

In that case you would need a well-done constructor system and use some nice checksums and data holders, but that's not the case here.

 

I btw. siemka :) Coraz więcej Polaków tu widzę.

  Quote

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

Posted

Hm, I made class for sending packets form server to client but still both sides arent the same.

Where I should call my method to send packets?

Right now its in general order class and I call it in entity class each second.

Posted

You need to send packet everytime something is changed (added/removed) in list to keep it synced.

  Quote

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

Posted

Done, sth has changed. Now I get errors.

io.netty.handler.codec.EncoderException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to BetterWorld.ai.EntityAIBaseOrder

 

this.taskEntries() is an arraylist with stored EntityAIBaseOrder objects.

    public void syncOrders()
    {    	
    	ModBetterWorld.packets.sendToAll(new GuiRequestPacketSendOrders(this.villager.getEntityId(), this.taskEntries));
    }

 

There objects should be copied and stored in List orders.

private List orders = new ArrayList();
public GuiRequestPacketSendOrders(int id, List orders)
{
	this.entityId = id;
	this.orders = orders;
}

 

And here I get and error. The list should store correct object but it doesnt and gets error.

buffer.writeInt(((EntityAIBaseOrder) this.orders).getId());

Posted
  On 2/8/2015 at 1:08 PM, SSslimer said:

Done, sth has changed. Now I get errors.

io.netty.handler.codec.EncoderException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to BetterWorld.ai.EntityAIBaseOrder

 

this.taskEntries() is an arraylist with stored EntityAIBaseOrder objects.

    public void syncOrders()
    {    	
    	ModBetterWorld.packets.sendToAll(new GuiRequestPacketSendOrders(this.villager.getEntityId(), this.taskEntries));
    }

 

There objects should be copied and stored in List orders.

private List orders = new ArrayList();
public GuiRequestPacketSendOrders(int id, List orders)
{
	this.entityId = id;
	this.orders = orders;
}

 

And here I get and error. The list should store correct object but it doesnt and gets error.

buffer.writeInt(((EntityAIBaseOrder) this.orders).getId());

 

Does "EntityAIBaseOrder" extend ArrayList? Because if not you cannot cast the object EntityAIBaseOrder to an ArrayList.

I require Java, both the coffee and the code :)

Posted

Notfing has changed. Still the same error.

 

	for (int i = 0; i < this.orders.size(); i++)
	{
		System.out.println(this.orders.size());
		buffer.writeInt(((EntityAIBaseOrder) this.orders.get(i)).getId());
	}

Ups, I forgot to add .get(i)

I wanted to get an object from list and get grom it and id.

Adding it solved the error.

Posted

Again very strange error.

Below are two methods. In first this.orders isnt null, but in second is null.

When I put print method in first met. it shows size, in second met. I get an error.

Why it happens when it should not??

public void toBytes(ByteBuf buffer)
{
	buffer.writeInt(this.entityId);
	System.out.println(this.orders.size());
	for (int i = 0; i < this.orders.size(); i++)
	{			
		buffer.writeInt(((EntityAIBaseOrder) this.orders.get(i)).getId());
	}
}
  
public void fromBytes(ByteBuf buffer)
{
	this.entityId = buffer.readInt();

	if(this.orders != null)
	{
		for (int j = 0; j < this.orders.size(); j++)
		{
			this.orders.add(j, this.orderSystem.getOrderById(buffer.readInt())); 
		}
	}
}

Posted

Let's say:

- Server has 10 orders on given entity

- Client has none (need to be updated)

 

What happens in your code:

Server:

1. You write int (entityID)

2. You write 10x ints (order Id's)

Client:

1. You read 1st int (entityID)

2. Checking if orders aren't null (they most likely are, if you didn't init them)

3. You attempt to read as many int's fromreceived message as your client-side order list, which at that very momeny is EQUAL TO 0.

4. Nothing is read, because loop has (j = 0) < (size = 0).

 

What you need:

After writing entityID, write one more int - number of id's sent.

Read that int and put it as j < size in reader.

 

Overall note:

If client has 5 orders and server has 10, client will receive 10 orders, no matter if you alredy have them on client. So most likely you will end up with duplicates. Fix: Send all Id's when one is changed and on client-side clear order list and set to received one OR send only lacking orders (harder, more efficient).

  Quote

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

Posted

Well, obviously :o

toBytes writed data to byte stream (buffer) and fromBytes reads it. Sender writes, receiver reads.

  Quote

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I never thought I’d fall for it but I did. It all started with what seemed like a promising crypto investment opportunity I found through a popular social media platform. The project looked legitimate, with a sleek website, professional looking team profiles, and glowing testimonials. After doing what I thought was enough due diligence, I invested. First $5,000. Then $10,000. Over the next few months, I put in a total of $153,000. The returns were amazing on paper. My account showed massive gains, and I was told I could “withdraw soon.” But when I tried to cash out, I was hit with endless delays, excuses, and requests for additional “verification fees.” That’s when the panic set in: I realized I’d been scammed. I felt sick. Devastated. Embarrassed. After days of searching online, I came across Malice Cyber Recovery, a firm that specialized in tracing and recovering lost digital assets. I was skeptical at first I’d already lost so much, and I wasn’t ready to be taken advantage of again. But their team was incredibly professional and transparent from the start. They explained the recovery process in detail and didn’t make any unrealistic promises. They began with a full investigation, tracing the blockchain transactions and identifying the wallet addresses involved. Within a week, they had compiled enough evidence to begin their recovery strategy. It wasn’t easy and it wasn’t overnight but within a matter of weeks, I received the news I never thought I’d hear They had recovered my $153,000. I cried. Not just because I got my money back but because someone actually cared enough to help me. If you’ve fallen victim to a crypto scam, don’t suffer in silence. Malice Cyber Recovery gave me my life back and they just might be able to do the same for you  
    • Maximizing savings on  Temu  has never been easier! With the exclusive 70% Off Coupon Code [acu729640], you can enjoy unparalleled discounts on a vast array of trending products. This offer, coupled with fast delivery and free shipping across 67 countries, ensures that shoppers receive high-quality items at remarkably reduced prices. Exclusive  Temu  Coupon Codes for Maximum Savings Enhance your shopping experience by applying these verified Coupon Codes: acu729640 – Enjoy a 70% discount on your order. acu729640 – Receive an extra 30% off on select items. acu729640 – Benefit from free shipping on all purchases. acu729640 – Save $10 on orders exceeding $50. acu729640 – Unlock special discounts on newly launched products. What is the  Temu  70% Off Coupon Code [acu729640]? The 70% Off Coupon Code [acu729640] is a premier promotional tool that significantly reduces the cost of various products across  Temu 's extensive marketplace. Whether you are a first-time buyer or a returning customer, applying this Code at checkout guarantees exceptional discounts on categories such as apparel, electronics, home essentials, and more. How Does the 70% Off Coupon Code [acu729640] Work on  Temu ? Leveraging the 70% Off Coupon Code [acu729640] is effortless: Browse  Temu ’s diverse product range. Select and add desired items to your shopping cart. Enter [acu729640] at checkout. Instantly receive a 70% discount. Complete your transaction and enjoy expedited, reliable shipping. Is the  Temu  70% Off Coupon Code [acu729640] Legitimate? Absolutely! The  Temu  70% Off Coupon Code [acu729640] is an authentic and verified discount, actively used by thousands of savvy shoppers. Unlike misleading online offers, this Coupon is officially endorsed by  Temu , ensuring its seamless functionality across multiple product categories. Latest  Temu  Coupon Code 70% Off [acu729640] + Additional 30% Discount  Temu  continually updates its promotional lineup. In addition to the 70% Off Coupon Code [acu729640], customers can utilize to obtain an extra 30% discount on selected items. These stacked savings empower users to optimize their purchases and maximize financial benefits.  Temu  Coupon Code 70% Off United States [acu729640] For 2025 For customers residing in the United States, the  Temu  Coupon Code 70% Off [acu729640] remains a top-tier deal in 2025. Coupled with nationwide free shipping, this offer presents an unparalleled opportunity to secure premium products at a fraction of their original cost.  Temu  70% Off Coupon Code [acu729640] + Free Shipping In addition to receiving 70% off, users also enjoy complimentary shipping when applying the  Temu  70% Off Coupon Code [acu729640]. This combination of discounts and free shipping eliminates hidden costs, reinforcing  Temu ’s dedication to customer satisfaction and affordability. More Exclusive  Temu  Coupon Codes for Additional Savings Maximize your savings with these additional discount Codes: acu729640 – Unlock a 70% discount instantly. acu729640 – Avail extra savings for new users. acu729640 – Get free shipping on all orders. acu729640 – Enjoy bulk purchase discounts. acu729640 – Access exclusive markdowns on premium collections. Why Should You Use the  Temu  70% Off Coupon Code [acu729640]? Substantial savings across multiple product categories. Exclusive discounts for new and returning customers. Verified and legitimate Coupon Codes with immediate application. Complimentary shipping available across 67 countries. Expedited delivery and a seamless shopping experience. Final Note: Use The Latest  Temu  Coupon Code [acu729640] 70% Off The  Temu  Coupon Code [acu729640] 70% off offers an unparalleled opportunity to save significantly on high-quality products. Secure this deal now to maximize your benefits in July 2025. With the  Temu  Coupon 70% off, you can access exceptional discounts and unbeatable pricing. Apply the Code today and transform your shopping experience. Summary:  Temu  Coupon Code 70% Off  Temu  70% Off Coupon Code acu729640 70% Off Coupon Code acu729640  Temu   Temu  Coupon Code 70% Off United States 2025 Latest  Temu  Coupon Code 70% Off acu729640  Temu  70% Off Coupon Code legit How to use  Temu  70% Off Coupon Code Temu  70% Off Coupon Code free shipping Best  Temu  discount Codes 2025  Temu  promo Codes July 2025 FAQs About the  Temu  70% Off Coupon What is the 70% Off Coupon Code [acu729640] on  Temu ? The 70% Off Coupon Code [acu729640] is a promotional tool enabling shoppers to secure up to 70% savings on a vast selection of  Temu  products. How can I apply the  Temu  70% Off Coupon Code [acu729640]? To redeem the Coupon, simply add your chosen items to the cart, enter [acu729640] at checkout, and enjoy the automatic discount. Is the  Temu  70% Off Coupon Code [acu729640] available for all users? Yes! Both first-time and returning customers can leverage the 70% Off Coupon Code [acu729640] to access incredible savings. Does the 70% Off Coupon Code [acu729640] include free shipping? Yes! Applying [acu729640] at checkout not only provides a 70% discount but also ensures free shipping across applicable regions. Can the  Temu  70% Off Coupon Code [acu729640] be used multiple times? The validity and frequency of Coupon usage are subject to  Temu ’s promotional policies. Many users report success in applying the Coupon across multiple transactions, maximizing their overall savings potential.  
    • Temu Gutscheincode 100 € RABATT → [acu729640] für die USA im Juli  Spare riesig mit dem Temu Gutscheincode 100 € RABATT → [acu729640] im Juli 2025 Im Juli 2025 bringt Temu unglaubliche Rabatte für seine treuen Kunden mit einem exklusiven Gutscheincode (acu729640), der dir beeindruckende 100 € Rabatt auf deinen Einkauf gewährt. Egal, ob du Neukunde oder Stammkunde bist – du kannst bei einer riesigen Auswahl an Artikeln sparen, darunter Elektronik, Mode, Haushaltswaren und vieles mehr! Jetzt ist der perfekte Zeitpunkt, um satte Rabatte zu genießen und zu erleben, warum Temu eine der führenden globalen E-Commerce-Plattformen ist. Was macht Temu so besonders? Temu ist bekannt für eine riesige Auswahl an trendigen Produkten zu unschlagbaren Preisen. Von den neuesten Technik-Gadgets bis zu stylischer Kleidung und Haushaltsbedarf – hier findest du alles. Außerdem bietet Temu kostenlosen Versand in über 67 Länder, schnelle Lieferung und Rabatte von bis zu 90 % auf ausgewählte Produkte. Mit dem Gutscheincode (acu729640) erhältst du zusätzliche Rabatte! So verwendest du den Temu Gutscheincode (acu729640) im Juli 2025 So nutzt du das 100 €-Angebot mit dem Temu Gutscheincode (acu729640): Registrieren oder Einloggen bei Temu: Ob neu oder bereits Kunde – du musst dich anmelden oder ein Konto erstellen, um den Gutscheincode einzulösen. Durchstöbere die große Temu-Auswahl: Entdecke Temus umfangreiches Produktsortiment – von Haushaltsartikeln, Beauty-Produkten, Mode bis hin zu Hightech-Gadgets. Gutscheincode eingeben (acu729640): Gib den Code im Feld "Promo Code" beim Checkout ein, um die 100 € sofort abzuziehen. Zusätzliche Rabatte sichern: Neben den 100 € Rabatt gibt es bis zu 40 % Rabatt auf ausgewählte Artikel oder kombinierbare Gutscheinpakete. Bestellung abschließen: Überprüfe deinen Warenkorb und schließe die Bestellung ab – inklusive kostenlosem Versand in über 67 Länder! Warum du den Temu Gutscheincode (acu729640) verwenden solltest Der Temu Gutscheincode (acu729640) bietet viele Vorteile – egal ob Neukunde oder Bestandskunde: 100 € Rabatt für Neukunden: Spare 100 € bei deiner ersten Bestellung. 100 € Rabatt für Bestandskunden: Auch wiederkehrende Kunden profitieren mit acu729640 von 100 € Rabatt. 40 % zusätzlicher Rabatt: Auf ausgewählte Produkte gibt es bis zu 40 % zusätzlich. Gratisgeschenk für Neukunden: Neukunden erhalten ein kostenloses Geschenk beim Einsatz des Gutscheins. 100 € Gutscheinpaket: Spare noch mehr mit gebündelten Gutscheinen für Technik, Mode, Haushaltswaren und mehr. Temu Neukunden-Rabatte & Angebote Perfekt für Neueinsteiger! Als Neukunde bekommst du: 100 € Rabatt auf die erste Bestellung mit dem Code (acu729640). Kostenloser Versand in über 67 Länder. Exklusive Promo-Codes je nach Produktkategorie. Zusätzliche Temu Gutscheine speziell für Neukunden im Juli 2025. Temu Gutscheine für Bestandskunden Auch bestehende Kunden gehen nicht leer aus: 100 € Rabatt mit acu729640 auf die nächste Bestellung. 40 % Rabatt auf ausgewählte Produkte in vielen Kategorien. Gutscheinpaket für Bestandskunden, ideal für größere Einkäufe. Weitere Rabattcodes für beliebte Produkte und Aktionen. Neue Temu-Angebote im Juli 2025 Temu überrascht immer wieder mit frischen Angeboten. Im Juli 2025 gibt es: 100 € Rabatt für Neu- und Bestandskunden mit dem Code acu729640. Bis zu 40 % Rabatt auf Elektronik, Beauty, Deko und mehr. Neukunden-Coupons inklusive Gratisgeschenk und Sonderaktionen. Laufend neue Angebote den ganzen Juli über – regelmäßig reinschauen lohnt sich! Spare in verschiedenen Ländern & Kategorien mit Temu Gutscheinen Beispiele, wie Temu-Codes weltweit funktionieren: USA: 100 € Rabatt mit acu729640 auf Bestellungen in den USA. Kanada: Kanadier erhalten 100 € Rabatt bei Erst- oder Folgebestellung. UK: Auch britische Kunden sparen 100 € mit dem Code. Japan: Japanische Kunden erhalten 100 € Rabatt plus Sonderaktionen. Mexiko, Brasilien, Spanien, Deutschland: Bis zu 40 % Rabatt auf ausgewählte Artikel mit acu729640. Fazit Ob neu oder treu – der Temu Gutscheincode (acu729640) bringt dir im Juli 2025 satte Rabatte:  100 € sparen, 40 % auf ausgewählte Artikel und kostenloser Versand weltweit. Temu bietet großartige Preise, eine riesige Auswahl und jede Menge Aktionen. Jetzt zuschlagen: Code acu729640 im Warenkorb eingeben und sparen!  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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