Advertisement
Guest User

Untitled

a guest
Aug 25th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. package main.core.main;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
  8. import org.bukkit.entity.Entity;
  9.  
  10. import me.libraryaddict.disguise.disguisetypes.DisguiseType;
  11. import me.libraryaddict.disguise.disguisetypes.MobDisguise;
  12. import net.minecraft.server.v1_16_R2.ChatComponentText;
  13. import net.minecraft.server.v1_16_R2.EntityHuman;
  14. import net.minecraft.server.v1_16_R2.EntityTypes;
  15. import net.minecraft.server.v1_16_R2.EntityZombie;
  16. import net.minecraft.server.v1_16_R2.GenericAttributes;
  17. import net.minecraft.server.v1_16_R2.PathfinderGoalHurtByTarget;
  18. import net.minecraft.server.v1_16_R2.PathfinderGoalLookAtPlayer;
  19. import net.minecraft.server.v1_16_R2.PathfinderGoalMeleeAttack;
  20. import net.minecraft.server.v1_16_R2.PathfinderGoalRandomLookaround;
  21. import net.minecraft.server.v1_16_R2.WorldServer;
  22.  
  23. public class CustomZombie extends EntityZombie {
  24.  
  25. private final String name;
  26. private final double damage;
  27. private final double xp;
  28. private final double health;
  29. private final int coins;
  30.  
  31. public CustomZombie(String name, double damage, double xp, double health, int coins) {
  32.  
  33. super(EntityTypes.ZOMBIE, ((CraftWorld) Bukkit.getWorld("world")).getHandle());
  34.  
  35. this.name = name;
  36. this.damage = damage;
  37. this.xp = xp;
  38. this.health = health;
  39. this.coins = coins;
  40.  
  41. this.setCustomName(new ChatComponentText(name));
  42. this.setCustomNameVisible(true);
  43.  
  44. this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(11);
  45. this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(health);
  46. this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(damage);
  47.  
  48.  
  49. // set tags
  50. this.getBukkitEntity().addScoreboardTag("MONSTER:NAME:" + name);
  51. this.getBukkitEntity().addScoreboardTag("MONSTER:DAMAGE:" + damage);
  52. this.getBukkitEntity().addScoreboardTag("MONSTER:XP:" + xp);
  53. this.getBukkitEntity().addScoreboardTag("MONSTER:HEALTH:" + health);
  54. this.getBukkitEntity().addScoreboardTag("MONSTER:COINS:" + coins);
  55.  
  56.  
  57.  
  58.  
  59.  
  60. }
  61.  
  62. public void spawn(double x, double y, double z, int amount, DisguiseType type) {
  63.  
  64. final Location loc0 = new Location(Bukkit.getWorld("world"), x, y, z);
  65.  
  66. int count = 0;
  67.  
  68. while(count < amount) {
  69.  
  70. Bukkit.getServer().broadcastMessage("1");
  71.  
  72. int rX = new Random().nextInt(5); // TODO: INCREASE
  73.  
  74. int rZ = new Random().nextInt(5); // TODO: INCREASE
  75.  
  76. Location loc1 = new Location(loc0.getWorld(), loc0.getX() + rX, loc0.getY(), loc0.getZ() + rZ);
  77.  
  78. this.setPosition(loc1.getX(), loc1.getY(), loc1.getZ());
  79.  
  80.  
  81.  
  82.  
  83. MobDisguise mobDisguise = new MobDisguise(type);
  84. mobDisguise.setEntity(this.getBukkitEntity());
  85. mobDisguise.startDisguise();
  86.  
  87. WorldServer world = ((CraftWorld) Bukkit.getWorld("world")).getHandle();
  88.  
  89.  
  90. world.addEntity(this);
  91.  
  92. count++;
  93. }
  94.  
  95. // spawn(x, y, z , amount, type);
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. }
  104.  
  105. public int getMoney() {
  106. return coins;
  107. }
  108.  
  109. public String getName() {
  110. return name;
  111. }
  112.  
  113. public double getDamage() {
  114. return damage;
  115. }
  116.  
  117. public double getXp() {
  118. return xp;
  119. }
  120.  
  121. public double getHP() {
  122. return health;
  123. }
  124.  
  125.  
  126. public static CustomZombie from(Entity entity) {
  127. String name = null;
  128. double damage = -1;
  129. double xp = -1;
  130. double health = -1;
  131. int coins = -1;
  132.  
  133. for (String tag : entity.getScoreboardTags()) {
  134. String[] parts = tag.split(":", 3);
  135. if (parts.length == 3 && parts[0].equals("MONSTER")) {
  136. if (parts[1].equals("NAME")) {
  137. name = parts[2];
  138. } else if (parts[1].equals("DAMAGE")) {
  139. damage = Double.parseDouble(parts[2]);
  140. } else if (parts[1].equals("XP")) {
  141. xp = Double.parseDouble(parts[2]);
  142. } else if (parts[1].equals("HEALTH")) {
  143. health =Double.parseDouble(parts[2]);
  144. } else if (parts[1].equals("COINS")) {
  145. coins = Integer.parseInt(parts[2]);
  146. }
  147.  
  148. }
  149. }
  150.  
  151. if (name != null) {
  152. return new CustomZombie(name, damage, xp, health, coins);
  153. }
  154. return null;
  155. }
  156.  
  157. @Override
  158. public String toString() {
  159. return "Monster{name='" + name + "', damage=" + damage + ", xp=" + xp + ", health=" + health + ", coins="
  160. + coins + "}";
  161. }
  162.  
  163. @Override
  164. public void initPathfinder() {
  165.  
  166. this.goalSelector.a(0, new PathfinderGoalHurtByTarget(this));
  167. this.goalSelector.a(1, new PathfinderGoalMeleeAttack(this, 1, true));
  168. this.goalSelector.a(1, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 10.0F));
  169. this.goalSelector.a(2, new PathfinderGoalRandomLookaround(this));
  170. }
  171.  
  172.  
  173.  
  174. }
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement