Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main.core.main;
- import java.util.Random;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
- import org.bukkit.entity.Entity;
- import me.libraryaddict.disguise.disguisetypes.DisguiseType;
- import me.libraryaddict.disguise.disguisetypes.MobDisguise;
- import net.minecraft.server.v1_16_R2.ChatComponentText;
- import net.minecraft.server.v1_16_R2.EntityHuman;
- import net.minecraft.server.v1_16_R2.EntityTypes;
- import net.minecraft.server.v1_16_R2.EntityZombie;
- import net.minecraft.server.v1_16_R2.GenericAttributes;
- import net.minecraft.server.v1_16_R2.PathfinderGoalHurtByTarget;
- import net.minecraft.server.v1_16_R2.PathfinderGoalLookAtPlayer;
- import net.minecraft.server.v1_16_R2.PathfinderGoalMeleeAttack;
- import net.minecraft.server.v1_16_R2.PathfinderGoalRandomLookaround;
- import net.minecraft.server.v1_16_R2.WorldServer;
- public class CustomZombie extends EntityZombie {
- private final String name;
- private final double damage;
- private final double xp;
- private final double health;
- private final int coins;
- public CustomZombie(String name, double damage, double xp, double health, int coins) {
- super(EntityTypes.ZOMBIE, ((CraftWorld) Bukkit.getWorld("world")).getHandle());
- this.name = name;
- this.damage = damage;
- this.xp = xp;
- this.health = health;
- this.coins = coins;
- this.setCustomName(new ChatComponentText(name));
- this.setCustomNameVisible(true);
- this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(11);
- this.getAttributeInstance(GenericAttributes.MAX_HEALTH).setValue(health);
- this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(damage);
- // set tags
- this.getBukkitEntity().addScoreboardTag("MONSTER:NAME:" + name);
- this.getBukkitEntity().addScoreboardTag("MONSTER:DAMAGE:" + damage);
- this.getBukkitEntity().addScoreboardTag("MONSTER:XP:" + xp);
- this.getBukkitEntity().addScoreboardTag("MONSTER:HEALTH:" + health);
- this.getBukkitEntity().addScoreboardTag("MONSTER:COINS:" + coins);
- }
- public void spawn(double x, double y, double z, int amount, DisguiseType type) {
- final Location loc0 = new Location(Bukkit.getWorld("world"), x, y, z);
- int count = 0;
- while(count < amount) {
- Bukkit.getServer().broadcastMessage("1");
- int rX = new Random().nextInt(5); // TODO: INCREASE
- int rZ = new Random().nextInt(5); // TODO: INCREASE
- Location loc1 = new Location(loc0.getWorld(), loc0.getX() + rX, loc0.getY(), loc0.getZ() + rZ);
- this.setPosition(loc1.getX(), loc1.getY(), loc1.getZ());
- MobDisguise mobDisguise = new MobDisguise(type);
- mobDisguise.setEntity(this.getBukkitEntity());
- mobDisguise.startDisguise();
- WorldServer world = ((CraftWorld) Bukkit.getWorld("world")).getHandle();
- world.addEntity(this);
- count++;
- }
- // spawn(x, y, z , amount, type);
- }
- public int getMoney() {
- return coins;
- }
- public String getName() {
- return name;
- }
- public double getDamage() {
- return damage;
- }
- public double getXp() {
- return xp;
- }
- public double getHP() {
- return health;
- }
- public static CustomZombie from(Entity entity) {
- String name = null;
- double damage = -1;
- double xp = -1;
- double health = -1;
- int coins = -1;
- for (String tag : entity.getScoreboardTags()) {
- String[] parts = tag.split(":", 3);
- if (parts.length == 3 && parts[0].equals("MONSTER")) {
- if (parts[1].equals("NAME")) {
- name = parts[2];
- } else if (parts[1].equals("DAMAGE")) {
- damage = Double.parseDouble(parts[2]);
- } else if (parts[1].equals("XP")) {
- xp = Double.parseDouble(parts[2]);
- } else if (parts[1].equals("HEALTH")) {
- health =Double.parseDouble(parts[2]);
- } else if (parts[1].equals("COINS")) {
- coins = Integer.parseInt(parts[2]);
- }
- }
- }
- if (name != null) {
- return new CustomZombie(name, damage, xp, health, coins);
- }
- return null;
- }
- @Override
- public String toString() {
- return "Monster{name='" + name + "', damage=" + damage + ", xp=" + xp + ", health=" + health + ", coins="
- + coins + "}";
- }
- @Override
- public void initPathfinder() {
- this.goalSelector.a(0, new PathfinderGoalHurtByTarget(this));
- this.goalSelector.a(1, new PathfinderGoalMeleeAttack(this, 1, true));
- this.goalSelector.a(1, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 10.0F));
- this.goalSelector.a(2, new PathfinderGoalRandomLookaround(this));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement