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.

SSslimer

Members
  • Joined

  • Last visited

Everything posted by SSslimer

  1. Thats why the same list had two versions 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)
  2. So toBytes() and fromBytes() are for diferent sides?? In both I used this.orders I will try to code what you sugested.
  3. 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())); } } }
  4. 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.
  5. 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());
  6. 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.
  7. 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.
  8. 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.
  9. Ok, I have that but how to send an element which is an object like all class?
  10. 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.
  11. 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.
  12. 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.
  13. When the button is activated it sends a packet. Than system add task using data from the packet. So I think its correct with what you have said.
  14. Ok but are any way to get tasks on clinent side? I need it to my gui, because clicling another buttons will remove tasks.
  15. In earlier versions there was but now I cant find it. Maybe they us sth with OpenGL.
  16. Sorry for offtopic but where we can find texture file with ligh, if it exists.
  17. 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());
  18. 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.
  19. Ok, thanks. I think I dont need this. Maybe somewhen in futer.
  20. Hey, I have no idea what is it and to what is it needed in the game code. Forge description tells me nothing. Can somebody tell me more about its application?
  21. So I must create packet which sends the button id andon message method put my stuff for adding or removing tasks? @Edit I think that I did it properly, removing tasks is easier(in my system I need only to remove task from list without any parameters) But to be sure that adding works good too I will need to make some upgrades in my code to allow customisation of tasks and of course I need to make tasks to add sth
  22. Thats not good, thats very bad. I will need to make a lot of things. Despite sending tasks objects I will need to send their configuration. Thanks for help. I will post back if I have a problem.
  23. I need the change tasks of one mob on which I opend GUI.
  24. Hey, I want to add and remove tasks why button in my gui is activated. Need I to send packets or it would work without it??
  25. Greate idea. I will try and reply. I was wrong. That par3 is strange. If I put there 2F speed seems to be 4m/tick When 4F it seems to be from 4 to 6. Can sb tries to get know what are those par3 and how to set correctly speed?? Mayby I have too much lags and speed isnt corectly shown in console. @Edit Ok, now I am 100% sure that par3 is speed par3 is preaty strange argument. The unit of it is meter per tick, but we must / our speed by 1.5 to make it correct in the balistic code.

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.