Jump to content

AppliedOnce

Members
  • Posts

    104
  • Joined

  • Last visited

Everything posted by AppliedOnce

  1. You never add any data to the NBTTagCompound, which you don't even need since you can write the int and String directly to the output stream, and read them back in. You don't need getter and setter methods because you will never be (should never be) trying to access your variables outside of this class. Thank you, I forgot I could use the NBTTagCompound to store the values (I am very stupid sometimes). Everything works as it should now, I really appreciate your help.
  2. For some reason this is giving me null and 0 all the time. I even tried using lists but that doesn't work either. package com.xetosphere.pantheon.network.packet; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import com.xetosphere.pantheon.entity.ExtendedPlayer; import com.xetosphere.pantheon.network.AbstractPacket; import cpw.mods.fml.common.network.ByteBufUtils; public class UpdateReligionPacket extends AbstractPacket { private NBTTagCompound data; private String religion; private int religionId; public UpdateReligionPacket() { } public UpdateReligionPacket(String religion, int religionId) { data = new NBTTagCompound(); setReligion(religion); setReligionId(religionId); } public void setReligion(String religion) { this.religion = religion; } public void setReligionId(int religionId) { this.religionId = religionId; } public String getReligion() { return religion; } public int getReligionId() { return religionId; } @Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { ByteBufUtils.writeTag(buffer, data); } @Override public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { data = ByteBufUtils.readTag(buffer); } @Override public void handleClientSide(EntityPlayer player) { } @Override public void handleServerSide(EntityPlayer player) { System.out.println(getReligion() + ", " + getReligionId()); ExtendedPlayer.get(player).setPantheon(getReligion()); ExtendedPlayer.get(player).setPantheonId(getReligionId()); if (!player.worldObj.isRemote) player.addChatComponentMessage(new ChatComponentText("You set your pantheon to: " + ExtendedPlayer.get(player).getPantheon())); System.out.println("[XETOPC] Pantheon = " + ExtendedPlayer.get(player).getPantheon()); System.out.println("[XETOPC] PantheonId = " + ExtendedPlayer.get(player).getPantheonId()); } }
  3. Ok, it seems I can't work this out by myself even after the information you gave me (server/client stuff really confuses me and this is my first time handling nbttag stuff). My current bugs is, when I open a world after quiting the game, it prints out correct information in the console (I made it so that when I use the method loadNBTData in the ExtendedPlayer.class it will print the religion and culture) but when I look inside my gui everything is reset back to the standard values. Though when I open a different world without leaving the game, it still has the information from the earlier world. So I ask how I can make it save for only the world he is currently in, and that it will save and load correctly even after I restart the game. Here is my current code: Mod class: GuiReligion.class: ItemTalisman.class: ExtendedPlayer.class: CultureEventHandler.class: SyncPlayerPropsPacket.class: CommonProxy.class: AbstractPacket.class: ClientProxy.class:
  4. So let me see if I got you right, you mean that I create a new packet that instead of sending from server side sends info from server to client instead? And that this new packet should be sent whenever one of the buttons are pressed? If that is correct do you know of any tutorial on sending data from server to client or the other way around? I wanna learn the new netty system in and out, so that I can use this for future projects and problems as well.
  5. No, what I meant to say is that when I have it as "!=" it crashes when I open the world. I get a nullpointer exception when using "!=". Crashlog: My real problems (I think) is that my values never really gets synced (client -> server or server -> client). This also make it so that when I open a new world, the gui says that I have the religion from the previous world (even if I create a new one) as well as when I close down minecraft and open it again it is reset to "None" instead of the religion name (where "None" is my default value in the ExtendedPlayer class).
  6. No, I am pretty sure what that code does is, if the player haven't been registered yet then register it. Other than that thank you for replying and helping me out. (btw if I use != it just crashes when the player joins the world)
  7. Hi, I'm currently working on a project and got into a small problem. I try to change a value that is saved in the player using the ExtendedEntityProperties stuff, inside a gui. The only I am having is that the way I am doing it, I only change the values on the client side which makes a lot of problems. So I was wondering how I can fix this problem, is there something missing in my packet or something or do I need a new one? Here is all the classes I am using for it: Mod class: ItemTalisman class: GuiReligion class: PacketPipeline class: SyncPlayerPropsPacket class: CultureEventHandler class: CommonProxy class: ExtendedPlayer class:
  8. Sorry, it was just I that was dumb. It was something else that caused it not to update. It had nothing to do with the code I used in there.
  9. That code only fires when a GuiButton is pressed. You should probably use the drawGuiForegroundLayer method to draw the strings, because that's updated every tick. This would work if I had a class that extends GuiContainer, but I am extending GuiScreen which has no such method.
  10. I tried calling it from the onItemRightClick method in one of my item classes. Seems like the code inside there is reachable even when it's opened.
  11. If I understand the code correctly that won't work because they are not really using a variable that shows up, but they are rendering a square that get's bigger and bigger. Rendering that should go fine, but I think variables need an update.
  12. Hi, I was just wondering if there was a way of updating a string that is drawn in a gui without exiting the gui first. By update I mean change value if I have done something to make it change. I have made it so that it updates every time you exit the gui and open it again, but that is all I can do. Here is the code I am using:
  13. Thanks alot, this is exactly what I need. The only problem with something like this (at least when I tried it out now) it gives me a total random y and z coordinate as well as it only change when moving around and not when I look around using the mouse. Sorry to bother you this much, guess I went some over my limit here.
  14. I found something that I think is a really bad fix. But at least it works: public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (ExtendedPlayer.get(player).getCulture() >= 100) { ExtendedPlayer.get(player).consumeCulture(100); player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 2400, 0, false)); MovingObjectPosition objectMouseOver; player.eyeHeight += 1.6F; objectMouseOver = player.rayTrace(300, 1); player.eyeHeight -= 1.6F; Vec3 vec3 = player.getPosition(1); System.out.println((world.isRemote ? "client y=" : "server y =") + vec3.yCoord); if (objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectType.BLOCK) { int i = objectMouseOver.blockX; int j = objectMouseOver.blockY; int k = objectMouseOver.blockZ; world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k)); } } else { if (world.isRemote) { player.addChatComponentMessage(new ChatComponentText("You don't have enough culture.")); } ExtendedPlayer.get(player).setCulture(100); } return itemStack; } This didn't seem to work that well...
  15. Thanks that helped alot, I just had to change some stuff so that it doesn't print stuff when it shouldn't. For people here is the code that worked: public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (ExtendedPlayer.get(player).getCulture() >= 100) { ExtendedPlayer.get(player).consumeCulture(100); // player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 2400, 0, false)); MovingObjectPosition objectMouseOver; Minecraft mc = Minecraft.getMinecraft(); objectMouseOver = mc.thePlayer.rayTrace(300, 1); if (objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectType.BLOCK) { int i = objectMouseOver.blockX; int j = objectMouseOver.blockY; int k = objectMouseOver.blockZ; world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k)); if (world.isRemote) { player.addChatComponentMessage(new ChatComponentText("Pew! X: " + i + ", Y: " + j + ", Z: " + k)); } } } else { if (world.isRemote) { player.addChatComponentMessage(new ChatComponentText("You don't have enough culture.")); } ExtendedPlayer.get(player).setCulture(100); } return itemStack; }
  16. You can drop all the ExtendedPlayer stuff. It's not needed and comes from my own created system.
  17. I'm not talking about the item taking damage, but that the lightning, when it strikes doesn't hurt entities at all, neither set things on fire.
  18. Hi, I am trying to make an item spawn lightning, and it all works just fine. But where the lightning spawns it doesn't set anything on fire, neither does it deal damage to entities it hits. What am I doing wrong? Before it didn't spawn the lightning but spawned fire now it is the opposite. Here is the code: public class ItemTalisman extends ItemPC { public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (!world.isRemote) { return itemStack; } if (ExtendedPlayer.get(player).getCulture() >= 100) { ExtendedPlayer.get(player).consumeCulture(100); // player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 2400, 0, false)); MovingObjectPosition objectMouseOver; Minecraft mc = Minecraft.getMinecraft(); objectMouseOver = mc.thePlayer.rayTrace(300, 1); if (objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectType.BLOCK) { int i = objectMouseOver.blockX; int j = objectMouseOver.blockY; int k = objectMouseOver.blockZ; world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k)); player.addChatComponentMessage(new ChatComponentText("Pew! X: " + i + ", Y: " + j + ", Z: " + k)); } } else { player.addChatComponentMessage(new ChatComponentText("You don't have enough culture.")); ExtendedPlayer.get(player).setCulture(100); } return itemStack; } }
  19. He said that. Sorry my bad... I typed to fast for me to see it. I meant INSTANCE without the ().
  20. Didn't he just say that it is: NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
  21. Here is the code that worked: public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (!world.isRemote) { return itemStack; } if (ExtendedPlayer.get(player).getCulture() >= 100) { ExtendedPlayer.get(player).consumeCulture(100); MovingObjectPosition objectMouseOver; Minecraft mc = Minecraft.getMinecraft(); objectMouseOver = mc.thePlayer.rayTrace(300, 1); if (objectMouseOver != null && objectMouseOver.typeOfHit == MovingObjectType.BLOCK) { int i = objectMouseOver.blockX; int j = objectMouseOver.blockY; int k = objectMouseOver.blockZ; world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k)); player.addChatComponentMessage(new ChatComponentText("Pew! X: " + i + ", Y: " + j + ", Z: " + k)); } } else { player.addChatComponentMessage(new ChatComponentText("You don't have enough culture.")); ExtendedPlayer.get(player).setCulture(100); } return itemStack; }
×
×
  • Create New...

Important Information

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