Jump to content

Briggybros

Members
  • Posts

    155
  • Joined

  • Last visited

Converted

  • Gender
    Male
  • URL
    http://www.toomuchminecraft.com
  • Location
    Wales, UK
  • Personal Text
    I am new! <-- Not so much..

Recent Profile Visitors

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

Briggybros's Achievements

Creeper Killer

Creeper Killer (4/8)

-1

Reputation

  1. Hello, I'm trying to find a way to neatly get the player which sent a packet using IMessageHandler. This only allows me to retrieve the data in the message the side and the net handler. What would be the best way to see who sent the packet? Currently I am including the player's entityid in the packet. However, I really dislike this because it will break if there is more than just the default world. So to counter that I could send the world id the player is in also, and this would work. I find that method messy and overly complicated, is there a better way which I have missed?
  2. Thank you, setting the return to null as the javadoc indicated fixed the issue. How does it show that the packets are registered incorrectly?
  3. But if handleKey were being called multiple times then there would be "[14:46:47] [Client thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.KeyHandler:handleKey:16]: Client: Sending key packet" printed to console for every time it is called, which there isn't.
  4. Here: public class KeyBindings { KeyHandler keyHandler; public static KeyBinding[] bindings = { new KeyBinding("key.overview", Keyboard.KEY_O, "key.categories.micity") }; public KeyBindings(KeyHandler keyHandler) { this.keyHandler = keyHandler; for(KeyBinding binding : bindings) { ClientRegistry.registerKeyBinding(binding); } FMLCommonHandler.instance().bus().register(this); } @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { for(KeyBinding binding : bindings) { if(binding.isPressed()) keyHandler.handleKey(Minecraft.getMinecraft().thePlayer, binding.getKeyCode()); } } } But if that were called repeatedly, then the "Client: Sending key packet" would also be printed repeatedly
  5. I have just started working with Minecraft forge again and I'm trying to set up my mod, however, when sending a packet it gets received repeatedly. I used the CatDany example for reference. This method gets called on a key press: public void handleKey(EntityPlayer player, int keyId) { if(player instanceof EntityClientPlayerMP) { System.out.println("Client: Sending key packet"); IMessage msg = new KeyPacket.KeyMessage(player.getEntityId(), keyId); PacketHandler.net.sendToServer(msg); } } Which is handled by this packet class: package com.laszloslads.micity.common.packets; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.MinecraftForge; import com.laszloslads.micity.common.MiCity; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; public class KeyPacket implements IMessageHandler<KeyPacket.KeyMessage, IMessage> { @Override public IMessage onMessage(KeyPacket.KeyMessage message, MessageContext ctx) { if(ctx.side.isServer()) { System.out.println("Server: Key recieved - " + message.playerId + ":" + message.keyId); } return message; } public static class KeyMessage implements IMessage { private int playerId; private int keyId; public KeyMessage() { } public KeyMessage(int playerId, int keyId) { this.playerId = playerId; this.keyId = keyId; } @Override public void fromBytes(ByteBuf buf) { this.playerId = buf.readInt(); this.keyId = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(playerId); buf.writeInt(keyId); } } } The output is: [14:46:47] [Client thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.KeyHandler:handleKey:16]: Client: Sending key packet [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:47] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:48] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:49] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:49] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 [14:46:49] [server thread/INFO] [sTDOUT]: [com.laszloslads.micity.common.packets.KeyPacket:onMessage:21]: Server: Key recieved - 872:24 at which point I need to close the game to stop it. Why is it that this packet is sent only once by the client but received in duplicate by the server?
  6. Hey, I was wondering what's the best way to keep a custom 'tracker' in sync between the client and server. I have this class: public class ObjectRegistry { static HashMap<EntityPlayer, MyObject> map = new HashMap<EntityPlayer, MyObject>(); public static MyObject createNewObject(EntityPlayer entityPlayer) { MyObject t = new MyObject(entityPlayer); map.put(entityPlayer, t); return t; } public static MyObject getPlayerObject(EntityPlayer player) { return map.get(player); } } And here is the MyObject class: package mods.ages.civilization; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; public class Town { private static int lastObjectID; public static int getNextObjectID() { return lastTownID + 1; } int id; String name; EntityPlayer owner; public Town (EntityPlayer player) { owner = player; id = getNextObjectID(); name = new String(player.username + "'s Object"); } public EntityPlayer getOwner() { return owner; } public String getName() { return name; } public void setName(String s) { name = s; } } This stores all MyObject classes in the hashmap. However, I need to access these classes from the client side and when I try (without packets) I get a NullPointerException. As would be expected. What would be the best way of making the HashMap and the static functions in the registry available for the client side to reference. I'm fine with creating packets to send the data, it's just I wouldn't know what to do with it after the packet arrives.
  7. Yes, I was looking into that tag, I don't know how to use it though..
  8. Right, I've got this set up to check if it's the player's first time: package mods.ages.player; import java.util.Random; import mods.ages.entity.EntityCivilian; import mods.ages.util.NameGenerator; import net.minecraft.entity.passive.EntityPig; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import cpw.mods.fml.common.IPlayerTracker; public class PlayerTracker implements IPlayerTracker { PlayerHandler ph; public PlayerTracker(PlayerHandler ph) { this.ph = ph; } @Override public void onPlayerLogin(EntityPlayer player) { if (PlayerHandler.getPlayerProperties((EntityPlayerMP) player).isFirstLogin()) { System.out.println("Player's first time"); // Do stuff } else { System.out.println("Player has played before!"); } } } However, this if statement will always return false. The PlayerHandler class looks like so: public class PlayerHandler { private static PlayerTracker pt; public PlayerHandler() { pt = new PlayerTracker(this); } @ForgeSubscribe(priority = EventPriority.NORMAL) public void onEntityConstuct(EntityConstructing event) { if (event.entity instanceof EntityPlayerMP) { EntityPlayerMP ep = (EntityPlayerMP) event.entity; ep.registerExtendedProperties(PlayerProperties.IDENTIFIER, new PlayerProperties(this)); } } public static PlayerProperties getPlayerProperties(EntityPlayerMP player) { return (PlayerProperties) player .getExtendedProperties(PlayerProperties.IDENTIFIER); } public static IPlayerTracker getPlayerTracker() { return pt; } } and my PlayerProperties class looks like this: public class PlayerProperties implements IExtendedEntityProperties { EntityPlayerMP player; PlayerHandler ph; boolean firstLogin; public PlayerProperties(PlayerHandler ph) { this.ph = ph; } public static final String IDENTIFIER = "MyPlayerProperties"; @Override public void saveNBTData(NBTTagCompound compound) { compound.setBoolean("firstLogin", firstLogin); } @Override public void loadNBTData(NBTTagCompound compound) { firstLogin = !compound.hasKey("firstLogin"); } @Override public void init(Entity entity, World world) { player = (EntityPlayerMP) entity; } public boolean isFirstLogin() { return firstLogin; } } To me, this code should work fine, yet for some reason it doesn't. The Player Tracker is registered and the Construction event is also registered. If the order makes any difference, the Event is registered before the tracker. Both are registered in the FMLInitializationEvent in my main class. What's going wrong? Please help. Also: How would I make this tag persistent?
  9. Hello, I know it's possible to set a custom NBT tag using IExtendedEntityProperties to persist through respawn etc. How would this be achieved? Actually setting the tag to be persistent instead of resetting on death..
  10. Okay, thanks EDIT: So to convert from a ResorceLocation to an InputStream, this should work: InputStream stream = Ages.class.getResourceAsStream("/assets/" + resource.func_110624_b() + "/" + resource.func_110623_a());
  11. Hello, in my mod I'm using a custom file type which I want to load into java. I have all of the loading methods set up, etc. However, I've got it set to load from a File object, so I can set up input streams. I thought, since the file's classified as an asset that I should use Minecraft's built in ResourceLocation class. Yet, using the ResourceLocation, I cannot seem to find a way to get the file object that the resource location's pointing to. How can I do this?
  12. That's exactly what I've done with IExtendedEntityProperties, thanks for the input guys
×
×
  • Create New...

Important Information

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