Solved Zombie PathfinderGoal

Discussion in 'Plugin Development' started by ColaCraft, Mar 20, 2014.

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

    ColaCraft

    Hey guys, I don't expect a whole lot of you to know this, but I am unsure what I have done wrong with this.

    Pretty much I want this Zombie to break blocks when he gets close to the player to get to the player.

    This is the PathfinderGoal class:

    Code:java
    1. package me.porterk.mg.pfg;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.entity.Player;
    5.  
    6. import net.minecraft.server.v1_7_R1.Block;
    7. import net.minecraft.server.v1_7_R1.EntityInsentient;
    8. import net.minecraft.server.v1_7_R1.MathHelper;
    9. import net.minecraft.server.v1_7_R1.PathfinderGoal;
    10.  
    11. public class PathfinderGoalBreak extends PathfinderGoal{
    12.  
    13. protected EntityInsentient a;
    14. protected Block block;
    15.  
    16. public PathfinderGoalBreak(EntityInsentient entityinsentient) {
    17. this.a = entityinsentient;
    18. }
    19.  
    20. @Override
    21. public boolean a() {
    22. // TODO Auto-generated method stub
    23. return false;
    24. }
    25.  
    26. @Override
    27. public void e(){
    28. int direction = MathHelper.floor((double)((a.yaw * 4F) / 360F) + 0.5D) & 3;
    29. int x = (int) a.locX;
    30. int y = MathHelper.floor((int) a.locY + a.getHeadHeight());
    31. int z = (int) a.locZ;
    32. int l;
    33.  
    34.  
    35. if(a.getGoalTarget() != null){
    36.  
    37. Location p = a.getGoalTarget().getBukkitEntity().getLocation();
    38.  
    39. Location b;
    40.  
    41. org.bukkit.World world = (org.bukkit.World) a.world;
    42.  
    43. switch(direction)
    44. {
    45. case 0: //Direction 0 = +Z
    46. {
    47. block = a.world.getType(x, y, z +1);
    48.  
    49. b = new Location(world, x, y, z +1);
    50.  
    51. l = world.getBlockAt(x, y, z +1).getTypeId();
    52.  
    53. if(l > 0){
    54.  
    55. if(a.getGoalTarget() instanceof Player){
    56.  
    57. world.getBlockAt(x, y, z +1).breakNaturally();
    58.  
    59. a.world.broadcastEntityEffect(a, (byte) 14);
    60. }
    61.  
    62. }
    63.  
    64. break;
    65. }
    66. case 1: //Direction 1 = -X
    67. {
    68. block = a.world.getType(x -1, y, z);
    69.  
    70. b = new Location(world, x -1, y, z);
    71.  
    72. l = world.getBlockAt(x, y, z +1).getTypeId();
    73.  
    74. if(l > 0){
    75.  
    76. if(a.getGoalTarget() instanceof Player){
    77.  
    78. world.getBlockAt(x -1, y, z).breakNaturally();
    79.  
    80. a.world.broadcastEntityEffect(a, (byte) 14);
    81.  
    82. }
    83.  
    84. }
    85. break;
    86. }
    87. case 2: //Direction 2 = -Z
    88. {
    89. block = a.world.getType(x, y, z -1);
    90.  
    91. b = new Location(world, x, y, z -1);
    92.  
    93. l = world.getBlockAt(x, y, z +1).getTypeId();
    94.  
    95. if(l > 0){
    96.  
    97. if(a.getGoalTarget() instanceof Player){
    98.  
    99. world.getBlockAt(x, y, z -1).breakNaturally();
    100.  
    101. a.world.broadcastEntityEffect(a, (byte) 14);
    102.  
    103. }
    104.  
    105. }
    106. break;
    107. }
    108. case 3: //Direction 3 = +X
    109. {
    110. block = a.world.getType(x + 1, y, z);
    111.  
    112. b = new Location(world, x + 1, y, z);
    113.  
    114. l = world.getBlockAt(x, y, z +1).getTypeId();
    115.  
    116. if(l > 0){
    117.  
    118. if(a.getGoalTarget() instanceof Player){
    119.  
    120. world.getBlockAt(x, y, z -1).breakNaturally();
    121.  
    122. a.world.broadcastEntityEffect(a, (byte) 14);
    123.  
    124. }
    125.  
    126. }
    127. break;
    128. }
    129.  
    130. }
    131.  
    132.  
    133. }
    134. }
    135.  
    136. }


    As of right now, it isn't doing anything, and I am unsure what I am doing wrong- this is my first attempt at a PathfinderGoal class. Am I using the right methods and such? I have no idea what I've done wrong. (Yes I am making it a goal for my Zombie.)

    xTrollxDudex
    chasechocolate
    Garris0n

    Thanks guys!
     
  2. Offline

    xTrollxDudex

    ColaCraft
    My name has an x in it. Return true for the a method.
     
    ColaCraft likes this.
  3. Offline

    ColaCraft

    Sigh.

    You're talking about e(){} right? I need to make it public boolean e()?

    I added return true; to the end and it asked be to change the return type to boolean (logical), but when I did that it asked me to change it back to void.

    *facepalm* sorry if I'm not picking up what you're putting down, I'm a little tired.

    xTrollxDudex

    :/ I completely misread everything you said.

    My bad. Thanks.

    Okay- I changed the return to true and they still don't break (or appear to break) blocks when they are close to the player.

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

    Garris0n

    Can you post them in github gists or fix the formatting? It's hard to read like that. Also, can you post your Zombie class as well?
     
    ColaCraft likes this.
  5. Offline

    ColaCraft

  6. Offline

    xTrollxDudex

    ColaCraft
    You should have methods a, b, c, d, and e.
     
    ColaCraft likes this.
  7. Offline

    ColaCraft

    Even if I'm not using the methods? Should I just leave them empty?

    I've forgotten the deobsfucations for those
     
  8. Offline

    xTrollxDudex

    ColaCraft
    Wait... Never mind, I missed something...
     
    ColaCraft likes this.
  9. Offline

    ColaCraft

    Hmmm... What do you suggest I do bro?
     
  10. Offline

    xTrollxDudex

    ColaCraft
    Make sure the block you are calculating isn't air...
     
    ColaCraft likes this.
  11. Offline

    ColaCraft

    I'm already doing that with

    if(l>0){}
     
  12. Offline

    xTrollxDudex

    ColaCraft
    It probably return false everytime...
     
    ColaCraft likes this.
  13. Offline

    ColaCraft

    Okay, I'll try seeing if the block isn't air.

    How do you figure it returns false though?
     
  14. Offline

    xTrollxDudex

    ColaCraft likes this.
  15. Offline

    ColaCraft

    Meh. I can't get it to return true.. ever.

    I've tried getting the material, the block, seeing if it's buldable, breakable-- nothing gives.

    Either it's not registering the block, or the switch is messed up.
     
  16. Offline

    xTrollxDudex

    ColaCraft
    Code:
    [Head] | Assume this is one block
       |      |
      /\ <-- getLocation returns this block
    Are you sure that there is a block at where getLocation plus the offset is?
     
    ColaCraft likes this.
  17. Offline

    ColaCraft

    It returns the block the mob's feet is in or the block it's on top of?

    I'm not sure if that even matters- they haven't done anything even if I'm on a 3-4 block wall.

    I'll put in some debug messages to see if the switch even works.

    xTrollxDudex
     
  18. Offline

    xTrollxDudex

    ColaCraft
    The block at the mob's feet level
     
    ColaCraft likes this.
  19. Offline

    ColaCraft

    Okay. I put in debug messages and the switch works perfectly, it probably is the y cord thing

    xTrollxDudex

    Narrowed it down to the if(a.getGoalTarget() instanceof Player){}

    Any reason that wouldn't work?

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

    xTrollxDudex

    ColaCraft
    EntityPlayer *

    That's an NMS method.
     
    Garris0n and ColaCraft like this.
  21. Offline

    ColaCraft

    Checking now.

    xTrollxDudex

    Thanks so much! I liked all your posts on here.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page