Jump to content


  • Posts

  • Joined

  • Last visited


  • Gender
  • Personal Text
    I am not new!

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Ablaze's Achievements

Stone Miner

Stone Miner (3/8)



  1. I want to limit the stack size to 1 and only allow some items. Keep in mind I'm using the IInventory system. I can't understand the capabilities system AT ALL, and will switch once I understand it. Thanks.
  2. Yes. Also, which external storage would you recommend, and how would you implement it? Preferably free.
  3. After the first build, shouldn't it be safe to remove "./gradlew setupCIWorkspace"? Actually, on hindsight, maybe not. It clones the repository every single time, thus resetting the workspace. Am I right?
  4. But if it is on multiplayer how does Minecraft know which player 'thePlayer' is referring to?
  5. Cazzar and I came to the same exact conclusion on IRC. Sadly there is no ByteBuf.writePlayer() haha . Just one more thing - will this work on multiplayer? thePlayer sounds more 'single-player-ish' due to the usage of the word 'the'.
  6. I send a message for the GUI on my screen to update (IExtendedEntityProperties), but it crashes with an NPE. But it isn't null! Stacktrace: http://pastebin.com/zsMV5K7A Code: Main file: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/main/LetsMod.java Class implementing ExtendedProperties (called manaplayer): https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/extendedproperty/ManaPlayer.java ExtendedPropertyMessage: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/message/ExtendedPropertyMessage.java ExtendedPropertyMessageHandler: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/message/ExtendedPropertyMessageHandler.java The two places where I send a message: FirstBlock: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/block/FirstBlock.java#L50 FirstItem: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/item/FirstItem.java#L34 Okay so, I want to consume mana when I place a block. (Look at consumeMana() in ManaPlayer.java). This works fine. But now I have a gui (a bar at the top) so I have to send values to the client as well. So in the onBlockPlacedBy() method of FirstBlock.java I send a message. But it gives me an NPE (NullPointerException) (see the stacktrace) on ManaPlayer.java line 28. So I go there and add a few checks - "Player is null" and "Mana is null". It outputs Player is null. But it can't be! I have proof that it isn't null!: The first two lines of the stacktrace are Yay! and Mana:35/50. This shows that 15 mana has been taken out. I initialize the ManaPlayer object on this line: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/block/FirstBlock.java#L48 . Over there you see I pass it an entity? Well, how could I have initialized the object if my player was null? P.S. If you want to see where the Yay! and Mana:35/50 lines are coming from, it is over here: https://github.com/greatblitz982/LetsMod_1.7/blob/master/src/main/java/com/github/greatblitz982/extendedproperty/ManaPlayer.java#L58 Please help me. This thread was a bit hard to explain so if you don't understand, or need some code, just tell me and I'll explain that bit of code or provide you with that code. All my code is available on that github. Regards, Ablaze.
  7. Check out diesieben's tutorial here too: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html SimpleNetworkWrapper and what it is SimpleNetworkWrapper is an FML wrapper around Messages and MessageHandlers, so that Netty can understand your messages and handlers. It is the new way to send packets to players. You could use Netty itself but as cpw said, it can cause lots of problems like memory leaks. Steps to use the SimpleNetworkWrapper 1. Register a SimpleNetworkWrapper and a message 2. Create an IMessage 3. Create an IMessageHandler 4. Send the message Register a SimpleNetworkWrapper This step is fairly simple. public static SimpleNetworkWrapper snw; in your preInit: snw = NetworkRegistry.INSTANCE.newSimpleChannel(modid); snw.registerMessage(TutorialMessageHandler.class, TutorialMessage.class, 0, Side.CLIENT); You need to give the wrapper a String to identify the wrapper. It is a good practice to give it your mod-id so that it is unique for every mod. The parameters for registerMessage() are - a message handler, a message, a discriminator byte (a unique identifier for your messages), the side the handler is on - client or server. Create an IMessage IMessage is a packet. Your class will be implementing IMessage, and will be implementing some methods. public class TutorialMessage implements IMessage{ public int extremelyImportantInteger; public TutorialMessage() {} public TutorialMessage(int a) { this.extremelyImportantInteger = a; } @Override public void toBytes(ByteBuf buf) { buf.writeInt(extremelyImportantInteger); } @Override public void fromBytes(ByteBuf buf) { this.extremelyImportantInteger = buf.readInt(); } } We will pretend that extremelyImportantInteger is an extremely important integer to be sent from the client to the server. Yes, you need two constructors. This one will be used by you to initialize your fields, while the other one will be used by Forge to create your packet. Your data will be sent through a ByteBuffer and so you must write your data to it using the write*** methods in the toBytes() method. To read from the buffer, use fromBytes(). You must read data IN THE SAME ORDER as you wrote it! And that is it for your message! Create an IMessageHandler The IMessageHandler will act as your packet handler. So make sure your class implements this class. public class TutorialMessageHandler implements IMessageHandler<TutorialMessage, IMessage> { @Override public IMessage onMessage(TutorialMessage message, MessageContext ctx) { System.out.println(message.extremelyImportantInteger); return null; } } IMessageHandler<> takes two type parameters - first is the packet you handle and the other one is the packet you return. The handler calls the onMessage() method when it receives the packet. That is it for your handler! Send the message We got it all working now. Launch Minecraft and it will work fine. But.. you never send a packet! So, wherever you want to send a packet, add this line: MainFile.snw.sendTo(new TutorialMessage(3), (EntityPlayerMP) entityPlayer); The sendTo() method takes a packet to be sent and an EntityPlayerMP. The SimpleNetworkWrapper class also has some more cool methods like sendToDimension() but I'll leave that to you for exploring. There you go! Give yourself a pat on the back because you successfully got it working! BONUS: Reading and writing strings to and from ByteBufs If you noticed, there is no ByteBuf.readString() or ByteBuf.writeString("") method. Not to worry! There is a class called ByteBufUtils which you can use to operate on much more complex stuff like ItemStacks and Strings! So, to write a String - ByteBufUtils.writeUTF8String(buf, ""); and to read String myString = ByteBufUtils.readUTF8String(buf); In writeUTF8String(), buf is your ByteBuffer and the other parameter should be obvious. readUTF8String should be quite obvious. buf is your buffer. Thanks to diesieben for telling me about ByteBufUtils. That is it folks! Hope you learnt something from this Regards, Ablaze.
  8. Are you a teacher or a professor or something? You explain very well! Thanks to your explanation I understood even though I'm only 13 Just one thing - your approach uses packets, while the one diesieben and pahimar show uses messages. Is there any difference?
  9. Okay how do I send a message?
  10. Thanks a lot for the explanation jabelar That isn't what bothers me, you see. The thing is I don't understand how to do it. Once I understand how to do it, I will do it no matter how much effort or how much typing it takes. I just want to understand how to do it. And that is what I'm unable to do. EDIT: Took a giant trip around the source of Forge and Minecraft and a bunch of other mods. All I want an explanation of is these three methods, and how to use them: fromBytes() toBytes() onMessage() Also, how would I use them in the context I provided?
  11. I still don't quite get how this might help in the scenario I picture. This is the link I refer to - http://www.minecraftforum.net/topic/1952901-172164-eventhandler-and-iextendedentityproperties/ Over there, check out post #2 (iExtendedEntityProperties) and check Step 3.3. That is where I stumbled upon.
  12. I was reading through the IExtendedEntityProperties tutorial by coolAlias, and wanted to see the Gui Overlay bit. I reached the packet handling subsection(because properties are handled on server side and and the mana bar drawing thing on the client). There is said the following: So I scrolled up, and saw this link - http://www.minecraftforge.net/wiki/Netty_Packet_Handling . I was about to use that, but what worries me is that it is full of screams - I have never used netty before, nor have I used packet handlers. Can someone guide me? coolAlias' tutorial - http://www.minecraftforum.net/topic/1952901-172164-eventhandler-and-iextendedentityproperties/ Regards, and I welcome myself back, Ablaze
  • Create New...

Important Information

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