Solved Making a player an IronGolem without utilizing Packets?

Discussion in 'Plugin Development' started by MayoDwarf, May 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MayoDwarf

    Anyway to possibly do this? I want to make the player an IronGolem without packets or using another plugin as they lack possibilities. Thanks.
     
  2. Offline

    raGan.

  3. Offline

    MayoDwarf

    raGan.
    Well can anyone help me with the packets? I want to make the player a Iron Golem and I want to give the Iron Golem the name of the player. How can I do this? any help is appreciated. Thanks
     
  4. Offline

    raGan.

    I never did disguise before, so I can't tell you for sure, but you can probably catch all packets about a player sent to other players and change them to packets related to that particular mob, but you would probably also need to separately handle damaging, potions and possibly other interactions as well.
    In other words, it's a lot of works, so it might be a better solution to look for a library or a plugin that does it and has an API.
     
  5. Offline

    MayoDwarf

    raGan. I was going to use DisguiseCraft, however the only problem with that is that I can't set the display name of the mob... I also can't utilize it too well because I do not believe it is detected in events... :(
     
  6. Offline

    blablubbabc

  7. Offline

    MayoDwarf

    blablubbabc How would I mimic the player? I tried teleporting the golem to the player every move event with the player invisible, but that lagged and crashed the server out terribly. What's your thoughts and ideas about? Thanks for your help though. It's appreciated much!
     
  8. Offline

    blablubbabc

    Well, I would have tried teleporting the golem to the player's location as well, about every tick or so. I doubt that this would lag the server that much (or even crash it) ..
     
  9. Offline

    MayoDwarf

    blablubbabc Well it does... Would you like to see my code?
     
  10. Offline

    TGRHavoc

    The "playerMoveEvent" is fired like a million time a second and even if the player moves the mouse, I'm not surprised the server crashed :p
     
  11. Offline

    MayoDwarf

    TGRHavoc Well I checked the getFrom getTo so it's not every second really. Only every time they walk.
    CODE:
    Code:java
    1. package com.core.mayodwarf.golemfall.titans;
    2.  
    3. import com.core.mayodwarf.golemfall.main.Main;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.*;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEntityEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.event.player.PlayerMoveEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. import java.util.HashMap;
    19.  
    20. /**
    21. * Created with IntelliJ IDEA.
    22. * User: MayoDwarf
    23. * Date: 5/1/14
    24. * Time: 5:13 PM
    25. * To change this template use File | Settings | File Templates.
    26. */
    27. public class SummonGolem implements Listener {
    28. private HashMap<String, GolemType> gType = new HashMap<String, GolemType>();
    29. private HashMap<String, IronGolem> golem = new HashMap<String, IronGolem>();
    30. Main main;
    31. public SummonGolem(Main main) {
    32. this.main = main;
    33. }
    34. public void summonGolem(Player p, Location tFall, GolemType gt) {
    35. IronGolem ig = (IronGolem) p.getWorld().spawnEntity(new Location(p.getWorld(), tFall.getX(), 255, tFall.getZ(), tFall.getYaw(), tFall.getPitch()), EntityType.IRON_GOLEM);
    36. ig.setCustomName(ChatColor.DARK_RED+""+p.getDisplayName());
    37. ig.setCustomNameVisible(true);
    38. ig.setPlayerCreated(false);
    39. ig.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, Integer.MAX_VALUE));
    40. gType.put(p.getDisplayName(), gt);
    41. golem.put(p.getDisplayName(), ig);
    42. }
    43. public void enterGolem(Player p, Entity e) {
    44. if(e instanceof IronGolem) {
    45. IronGolem ig = (IronGolem) e;
    46. if(golem.get(p.getDisplayName()) == ig) {
    47. EntityHider entityHider = new EntityHider(main, EntityHider.Policy.BLACKLIST);
    48. entityHider.hideEntity(p, ig);
    49. }
    50. }
    51. }
    52. @EventHandler
    53. public void onInteract(PlayerInteractEntityEvent evt) {
    54. Player p = evt.getPlayer();
    55. Entity e = evt.getRightClicked();
    56. if(e instanceof IronGolem) {
    57. IronGolem ig = (IronGolem) e;
    58. if(ChatColor.stripColor(ig.getCustomName()).equals(p.getDisplayName())) {
    59. enterGolem(p, e);
    60. }
    61. }
    62. }
    63. @EventHandler
    64. public void onMove(PlayerMoveEvent evt) {
    65. Location from = evt.getFrom();
    66. Location to = evt.getTo();
    67. if(golem.containsKey(evt.getPlayer().getDisplayName())) {
    68. if(from.getZ() < to.getZ()) {
    69. golem.get(evt.getPlayer().getDisplayName()).teleport(from);
    70. } else
    71. if(from.getX() < to.getX()) {
    72. golem.get(evt.getPlayer().getDisplayName()).teleport(from);
    73. }
    74. }
    75. }
    76. @EventHandler
    77. public void onClick(PlayerInteractEvent evt) {
    78. Player p = evt.getPlayer();
    79. ItemStack i = p.getItemInHand();
    80. if(evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
    81. if(i.getType() == Material.NETHER_STAR) {
    82. if(i.getAmount() == 1) {
    83. summonGolem(p, evt.getClickedBlock().getLocation(), GolemType.ATTACK);
    84. }
    85. }
    86. }
    87. }
    88. }
    blablubbabc
     
  12. Offline

    TGRHavoc

    MayoDwarf
    That will only work if either the players' z increases or if their x increases? If the player walks either WEST or SOUTH the Iron Golem won't get teleported...
     
  13. Offline

    blablubbabc

    Did you get any errors / stacktrace for your crash?

    Also note that if the player doesn't move at all you won't teleport the golem. So I would go with the teleport-each-tick attempt.
     
  14. Offline

    MayoDwarf

    blablubbabc TGRHavoc Better? --->
    Code:java
    1. public void enterGolem(final Player p, Entity e) {
    2. if(e instanceof IronGolem) {
    3. final IronGolem ig = (IronGolem) e;
    4. if(golem.get(p.getDisplayName()) == ig) {
    5. EntityHider entityHider = new EntityHider(main, EntityHider.Policy.BLACKLIST);
    6. entityHider.hideEntity(p, ig);
    7. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, Integer.MAX_VALUE));
    8. ItemStack chainGun = new ItemStack(Material.WOOD_HOE);
    9. ItemStack rocketSalvo = new ItemStack(Material.WOOD_AXE);
    10. ItemMeta cIM = chainGun.getItemMeta();
    11. ItemMeta rIM = rocketSalvo.getItemMeta();
    12. cIM.setDisplayName(ChatColor.LIGHT_PURPLE+"XO-16 Chaingun");
    13. rIM.setDisplayName(ChatColor.DARK_PURPLE+"Rocket Salvo");
    14. rocketSalvo.setItemMeta(rIM);
    15. chainGun.setItemMeta(cIM);
    16. p.getInventory().setItem(0, chainGun);
    17. p.getInventory().setItem(1, rocketSalvo);
    18. Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() {
    19. @Override
    20. public void run() {
    21. ig.teleport(p);
    22. }
    23. }, 20, 20);
    24. }
    25. }
    26. }


    blablubbabc Error I keep getting is io.netty.handler.timeout.ReadTimeoutException -.-

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  15. Offline

    TGRHavoc

    MayoDwarf
    Any line? Copy and paste the full stack trace.
     
  16. Offline

    MayoDwarf

    TGRHavoc This is it and then it crashes my mine craft and I can't join the server and no commands in console work after it happens:
    Code:java
    1. [15:33:54 WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2982ms behind, skipping 59 tick(s)
     
  17. Offline

    TGRHavoc

    MayoDwarf
    Some other people have had the same problem. Try doing what they did.
     
  18. Offline

    MayoDwarf

    TGRHavoc I summon a titan and this happens:
    Code:java
    1. [15:33:54] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 2982ms behind, skipping 59 tick(s)
    and then I enter the titan and it happens again, but this time my screen freezes and I can't move or anything... -.- I'm so frustrated with this...
     
  19. Offline

    TGRHavoc

    MayoDwarf
    The process might be too intensive for your system causing the server to slow and and the Minecraft client to crash..
     
  20. Offline

    MayoDwarf

    TGRHavoc How much ram do you suggest for this?
     
  21. Offline

    TGRHavoc

    MayoDwarf
    I honestly don't have a foggiest. Maybe a minimum of 6GB on the system in total.. (A total guess)
     
  22. Offline

    MayoDwarf

    TGRHavoc blablubbabc Are you guys sure this is the best way? It seems it lags the server out every time though?
     
  23. Offline

    TGRHavoc

    MayoDwarf
    You could try increasing the time intervals and seeing if that is less intensive on the system..
     
  24. Offline

    MayoDwarf

    TGRHavoc There has got to be a better way. This is way too extensive on any system...
     
  25. Offline

    blablubbabc

    I still doubt it's an issue with teleporting the golem around.. I will do some own quick tests on this and report back.
     
  26. Offline

    unon1100

    Instead of creating a runnable, try using PlayerMoveEvent
     
  27. Offline

    MayoDwarf

    unon1100 blablubbabc TGRHavoc Seems it's not an issue with teleporting the golem at all. It's doing without any of the teleporting. I keep getting that io.netty.handler exception and it keeps saying "is the server overloaded" thing in console and then it basically lags and times out... Anyone have any idea why? -.-
     
  28. Offline

    TGRHavoc

    MayoDwarf
    Are you running an intensive task anywhere in the plugin?
     
  29. Offline

    MayoDwarf

    TGRHavoc I'll give you all my code and as you can see that's a nope:
    Code:java
    1. package com.core.mayodwarf.golemfall.titans;
    2.  
    3. import com.core.mayodwarf.golemfall.main.Main;
    4. import org.bukkit.*;
    5. import org.bukkit.entity.*;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEntityEvent;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.event.player.PlayerMoveEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.FireworkMeta;
    14. import org.bukkit.inventory.meta.ItemMeta;
    15. import org.bukkit.potion.PotionEffect;
    16. import org.bukkit.potion.PotionEffectType;
    17.  
    18. import java.util.HashMap;
    19.  
    20. /**
    21. * Created with IntelliJ IDEA.
    22. * User: MayoDwarf
    23. * Date: 5/1/14
    24. * Time: 5:13 PM
    25. * To change this template use File | Settings | File Templates.
    26. */
    27. public class SummonGolem implements Listener {
    28. private HashMap<String, GolemType> gType = new HashMap<String, GolemType>();
    29. private HashMap<String, IronGolem> golem = new HashMap<String, IronGolem>();
    30. Main main;
    31. public SummonGolem(Main main) {
    32. this.main = main;
    33. }
    34. public void summonGolem(Player p, Location tFall, GolemType gt) {
    35. IronGolem ig = (IronGolem) p.getWorld().spawnEntity(new Location(p.getWorld(), tFall.getX(), 200, tFall.getZ(), tFall.getYaw(), tFall.getPitch()), EntityType.IRON_GOLEM);
    36. ig.setCustomName(ChatColor.DARK_RED+""+p.getDisplayName());
    37. ig.setCustomNameVisible(true);
    38. ig.setPlayerCreated(true);
    39. ig.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, Integer.MAX_VALUE));
    40. gType.put(p.getDisplayName(), gt);
    41. golem.put(p.getDisplayName(), ig);
    42. }
    43. public void enterGolem(final Player p, Entity e) {
    44. if(e instanceof IronGolem) {
    45. final IronGolem ig = (IronGolem) e;
    46. if(golem.get(p.getDisplayName()) == ig) {
    47. p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, Integer.MAX_VALUE));
    48. ItemStack chainGun = new ItemStack(Material.WOOD_HOE);
    49. ItemStack rocketSalvo = new ItemStack(Material.WOOD_AXE);
    50. ItemMeta cIM = chainGun.getItemMeta();
    51. ItemMeta rIM = rocketSalvo.getItemMeta();
    52. cIM.setDisplayName(ChatColor.LIGHT_PURPLE+"XO-16 Chaingun");
    53. rIM.setDisplayName(ChatColor.DARK_PURPLE+"Rocket Salvo");
    54. rocketSalvo.setItemMeta(rIM);
    55. chainGun.setItemMeta(cIM);
    56. p.getInventory().setItem(0, chainGun);
    57. p.getInventory().setItem(1, rocketSalvo);
    58. }
    59. }
    60. }
    61. @EventHandler
    62. public void onInteract(PlayerInteractEntityEvent evt) {
    63. Player p = evt.getPlayer();
    64. Entity e = evt.getRightClicked();
    65. if(e instanceof IronGolem) {
    66. IronGolem ig = (IronGolem) e;
    67. if(ChatColor.stripColor(ig.getCustomName()).equals(p.getDisplayName())) {
    68. enterGolem(p, e);
    69. }
    70. }
    71. }
    72. @EventHandler
    73. public void onMove(PlayerMoveEvent evt) {
    74. Player p = evt.getPlayer();
    75. Location from = evt.getFrom();
    76. Location to = evt.getTo();
    77. if(golem.containsKey(p.getDisplayName())) {
    78. if(from.getX() < to.getX()) {
    79. golem.get(p.getDisplayName()).teleport(from);
    80. } else
    81. if(from.getZ() < to.getZ()) {
    82. golem.get(p.getDisplayName()).teleport(from);
    83. }
    84. }
    85. }
    86. @EventHandler
    87. public void onClick(PlayerInteractEvent evt) {
    88. Player p = evt.getPlayer();
    89. ItemStack i = p.getItemInHand();
    90. if(evt.getAction() == Action.RIGHT_CLICK_BLOCK) {
    91. if(i.getType() == Material.NETHER_STAR) {
    92. summonGolem(p, evt.getClickedBlock().getLocation(), GolemType.ATTACK);
    93. }
    94. }
    95. }
    96. }
     
  30. Offline

    blablubbabc

    MayoDwarf
    Yep, I can confirm it's no issue with the golem. I got it working in the meantime: the golem is moving nicely with the player. Though the golem is still a bit randomly looking around while the player is not moving, but I guess this can fixed somehow. The EntityHider works as well.
     
Thread Status:
Not open for further replies.

Share This Page