From a44430faac4273a7a01972da454ba667a1233917 Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Fri, 9 Aug 2019 23:00:18 +0800 Subject: [PATCH 01/12] fix #112 --- .../entities/monster/walking/Enderman.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index d103ddb14..4be82f24d 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -3,9 +3,11 @@ import cn.nukkit.Player; import cn.nukkit.block.BlockWater; import cn.nukkit.entity.Entity; +import cn.nukkit.entity.EntityCreature; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.item.Item; +import cn.nukkit.level.Level; import cn.nukkit.level.Sound; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.NukkitMath; @@ -22,6 +24,8 @@ public class Enderman extends WalkingMonster { public static final int NETWORK_ID = 38; + private boolean angry = false; + public Enderman(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @@ -104,7 +108,17 @@ public void attackEntity(Entity player) { public boolean attack(EntityDamageEvent ev) { super.attack(ev); if (!ev.isCancelled()) { + + if(ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){ + if(!isAngry()) { + setAngry(true); + } + } + if (ev.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { + if(!isAngry()) { + setAngry(true); + } ev.setCancelled(true); tp(); } else if (Utils.rand(1, 10) == 1) { @@ -139,11 +153,22 @@ public boolean entityBaseTick(int tickDiff) { if (this.level.getBlock(new Vector3(NukkitMath.floorDouble(this.x), (int) this.y, NukkitMath.floorDouble(this.z))) instanceof BlockWater) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); + if(isAngry()) { + setAngry(false); + } tp(); } else if (Utils.rand(0, 500) == 20) { tp(); } + if(this.age % 20 == 0 && this.level.isRaining() || this.level.isThundering()){ + this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); + if(isAngry()) { + setAngry(false); + } + tp(); + } + return super.entityBaseTick(tickDiff); } @@ -155,10 +180,29 @@ private void tp() { @Override public boolean canDespawn() { - if (this.getLevel().getName().equals("end")) { + if (this.getLevel().getDimension() == Level.DIMENSION_THE_END) { return false; } return super.canDespawn(); } + + public void makeVibrating(boolean bool){ + this.setDataFlag(DATA_FLAGS,DATA_FLAG_VIBRATING,bool); + } + + public boolean isAngry(){ + return angry; + } + + public void setAngry(boolean bool) { + this.angry = bool; + makeVibrating(bool); + } + + @Override + public boolean targetOption(EntityCreature creature, double distance) { + if(!angry)return false; + return super.targetOption(creature, distance); + } } From f1092ac6c24559032ca97fa7ab472518a1db3078 Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Sat, 10 Aug 2019 12:02:54 +0800 Subject: [PATCH 02/12] improve enderman --- .../nukkitcoders/mobplugin/EventListener.java | 34 +++++++++++++++++++ .../entities/monster/walking/Enderman.java | 10 ++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/nukkitcoders/mobplugin/EventListener.java b/src/main/java/nukkitcoders/mobplugin/EventListener.java index 90f62e0fc..de901fa17 100644 --- a/src/main/java/nukkitcoders/mobplugin/EventListener.java +++ b/src/main/java/nukkitcoders/mobplugin/EventListener.java @@ -6,9 +6,11 @@ import cn.nukkit.block.BlockAir; import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.entity.Entity; +import cn.nukkit.entity.EntityCreature; import cn.nukkit.entity.projectile.EntityEgg; import cn.nukkit.entity.projectile.EntityEnderPearl; import cn.nukkit.event.EventHandler; +import cn.nukkit.event.EventPriority; import cn.nukkit.event.Listener; import cn.nukkit.event.block.BlockBreakEvent; import cn.nukkit.event.block.BlockPlaceEvent; @@ -16,9 +18,12 @@ import cn.nukkit.event.entity.EntityDeathEvent; import cn.nukkit.event.entity.ProjectileHitEvent; import cn.nukkit.event.player.PlayerInteractEvent; +import cn.nukkit.event.player.PlayerMoveEvent; import cn.nukkit.event.server.DataPacketReceiveEvent; import cn.nukkit.item.Item; +import cn.nukkit.math.AxisAlignedBB; import cn.nukkit.math.BlockFace; +import cn.nukkit.math.SimpleAxisAlignedBB; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.EntityEventPacket; import cn.nukkit.network.protocol.PlayerInputPacket; @@ -27,6 +32,7 @@ import nukkitcoders.mobplugin.entities.animal.walking.Chicken; import nukkitcoders.mobplugin.entities.animal.walking.Llama; import nukkitcoders.mobplugin.entities.block.BlockEntitySpawner; +import nukkitcoders.mobplugin.entities.monster.walking.Enderman; import nukkitcoders.mobplugin.entities.monster.walking.Silverfish; import nukkitcoders.mobplugin.event.entity.SpawnGolemEvent; import nukkitcoders.mobplugin.event.spawner.SpawnerChangeTypeEvent; @@ -208,4 +214,32 @@ public void DataPacketReceiveEvent(DataPacketReceiveEvent ev) { } } } + + @EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true) + public void stareEnderman(PlayerMoveEvent event){ + if(event.getPlayer().getLevel().getCurrentTick() % 20 == 0){ + Player player = event.getPlayer(); + double kk = Math.tan(player.getPitch() * -1 * Math.PI / 180); + AxisAlignedBB aab = new SimpleAxisAlignedBB( + player.getX() - 0.6f, + player.getY() + 1.45f, + player.getZ() - 0.6f, + player.getX() + 0.6f, + player.getY() + 2.9f, + player.getZ() + 0.6f + ); + for(int i = 0; i < 8;i++){ + aab.offset(-Math.sin(player.getYaw() * Math.PI / 180) * i, i * kk, Math.cos(player.getYaw() * Math.PI / 180) * i); + Entity entities[] = player.getLevel().getCollidingEntities(aab); + if(entities.length > 0){ + for (Entity e : entities) { + if (e instanceof Enderman) { + ((Enderman) e).stareToAngry(); + } + } + } + } + } + } + } diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index 4be82f24d..308612d98 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -161,7 +161,7 @@ public boolean entityBaseTick(int tickDiff) { tp(); } - if(this.age % 20 == 0 && this.level.isRaining() || this.level.isThundering()){ + if(this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())){ this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); if(isAngry()) { setAngry(false); @@ -188,7 +188,7 @@ public boolean canDespawn() { } public void makeVibrating(boolean bool){ - this.setDataFlag(DATA_FLAGS,DATA_FLAG_VIBRATING,bool); + this.setDataFlag(DATA_FLAGS,67,bool); } public boolean isAngry(){ @@ -205,4 +205,10 @@ public boolean targetOption(EntityCreature creature, double distance) { if(!angry)return false; return super.targetOption(creature, distance); } + + public void stareToAngry(){ + if(!isAngry()) { + setAngry(true); + } + } } From dd417ca21ed32041a1e2e02dc3acc97f536a97fd Mon Sep 17 00:00:00 2001 From: zzz <1173572640@qq.com> Date: Mon, 12 Aug 2019 01:51:37 +0000 Subject: [PATCH 03/12] Revert "update" --- .circleci/config.yml | 2 +- pom.xml | 2 +- src/main/java/nukkitcoders/mobplugin/MobPlugin.java | 2 +- .../nukkitcoders/mobplugin/entities/animal/walking/Cow.java | 2 +- .../mobplugin/entities/animal/walking/Mooshroom.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 02cb65416..4022bc666 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,4 +24,4 @@ jobs: - run: mvn clean package - store_artifacts: - path: target/MobPlugin-1.10.1.jar + path: target/MobPlugin-1.10.jar diff --git a/pom.xml b/pom.xml index d91754619..00dcbffc8 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ nukkitcoders.mobplugin MobPlugin - 1.10.1 + 1.10 install ${basedir}/src/main/java diff --git a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java index fcbfc00c7..a6680350c 100644 --- a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java +++ b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java @@ -93,7 +93,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } - switch (args[0].toLowerCase()) { + switch (args[0]) { case "spawn": if (args.length == 1) { sender.sendMessage("Usage: /mob spawn "); diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java index a7c45799d..3be28221c 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java @@ -53,8 +53,8 @@ public void initEntity() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); + player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java index a99ebd1f2..8c6c1392c 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java @@ -84,12 +84,12 @@ public int getKillExperience() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BOWL, 0), true)) { - player.getInventory().addItem(Item.get(Item.MUSHROOM_STEW, 0, 1)); player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); + player.getInventory().addItem(Item.get(Item.MUSHROOM_STEW, 0, 1)); return true; } else if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); + player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { From 53ecfcf672852073ef148e97c739de804c618d8c Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Tue, 13 Aug 2019 00:21:43 +0800 Subject: [PATCH 04/12] format indent --- .../nukkitcoders/mobplugin/EventListener.java | 11 ++++---- .../entities/monster/walking/Enderman.java | 26 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/nukkitcoders/mobplugin/EventListener.java b/src/main/java/nukkitcoders/mobplugin/EventListener.java index de901fa17..6bcb2e60b 100644 --- a/src/main/java/nukkitcoders/mobplugin/EventListener.java +++ b/src/main/java/nukkitcoders/mobplugin/EventListener.java @@ -6,7 +6,6 @@ import cn.nukkit.block.BlockAir; import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.entity.Entity; -import cn.nukkit.entity.EntityCreature; import cn.nukkit.entity.projectile.EntityEgg; import cn.nukkit.entity.projectile.EntityEnderPearl; import cn.nukkit.event.EventHandler; @@ -215,9 +214,9 @@ public void DataPacketReceiveEvent(DataPacketReceiveEvent ev) { } } - @EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true) - public void stareEnderman(PlayerMoveEvent event){ - if(event.getPlayer().getLevel().getCurrentTick() % 20 == 0){ + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void stareEnderman(PlayerMoveEvent event) { + if (event.getPlayer().getLevel().getCurrentTick() % 20 == 0) { Player player = event.getPlayer(); double kk = Math.tan(player.getPitch() * -1 * Math.PI / 180); AxisAlignedBB aab = new SimpleAxisAlignedBB( @@ -228,10 +227,10 @@ public void stareEnderman(PlayerMoveEvent event){ player.getY() + 2.9f, player.getZ() + 0.6f ); - for(int i = 0; i < 8;i++){ + for (int i = 0; i < 8; i++) { aab.offset(-Math.sin(player.getYaw() * Math.PI / 180) * i, i * kk, Math.cos(player.getYaw() * Math.PI / 180) * i); Entity entities[] = player.getLevel().getCollidingEntities(aab); - if(entities.length > 0){ + if (entities.length > 0) { for (Entity e : entities) { if (e instanceof Enderman) { ((Enderman) e).stareToAngry(); diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index 308612d98..b29ae4eca 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -55,7 +55,7 @@ protected void initEntity() { this.setMaxHealth(40); super.initEntity(); - this.setDamage(new float[] { 0, 4, 7, 10 }); + this.setDamage(new float[]{0, 4, 7, 10}); } public void attackEntity(Entity player) { @@ -109,14 +109,14 @@ public boolean attack(EntityDamageEvent ev) { super.attack(ev); if (!ev.isCancelled()) { - if(ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){ - if(!isAngry()) { + if (ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) { + if (!isAngry()) { setAngry(true); } } if (ev.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { - if(!isAngry()) { + if (!isAngry()) { setAngry(true); } ev.setCancelled(true); @@ -153,7 +153,7 @@ public boolean entityBaseTick(int tickDiff) { if (this.level.getBlock(new Vector3(NukkitMath.floorDouble(this.x), (int) this.y, NukkitMath.floorDouble(this.z))) instanceof BlockWater) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); - if(isAngry()) { + if (isAngry()) { setAngry(false); } tp(); @@ -161,9 +161,9 @@ public boolean entityBaseTick(int tickDiff) { tp(); } - if(this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())){ + if (this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); - if(isAngry()) { + if (isAngry()) { setAngry(false); } tp(); @@ -187,11 +187,11 @@ public boolean canDespawn() { return super.canDespawn(); } - public void makeVibrating(boolean bool){ - this.setDataFlag(DATA_FLAGS,67,bool); + public void makeVibrating(boolean bool) { + this.setDataFlag(DATA_FLAGS, 67, bool); } - public boolean isAngry(){ + public boolean isAngry() { return angry; } @@ -202,12 +202,12 @@ public void setAngry(boolean bool) { @Override public boolean targetOption(EntityCreature creature, double distance) { - if(!angry)return false; + if (!angry) return false; return super.targetOption(creature, distance); } - public void stareToAngry(){ - if(!isAngry()) { + public void stareToAngry() { + if (!isAngry()) { setAngry(true); } } From 3c9f5a7952503b5af0519edd6c65899c0768301f Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Fri, 9 Aug 2019 23:00:18 +0800 Subject: [PATCH 05/12] fix #112 --- .../entities/monster/walking/Enderman.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index d103ddb14..4be82f24d 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -3,9 +3,11 @@ import cn.nukkit.Player; import cn.nukkit.block.BlockWater; import cn.nukkit.entity.Entity; +import cn.nukkit.entity.EntityCreature; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.item.Item; +import cn.nukkit.level.Level; import cn.nukkit.level.Sound; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.NukkitMath; @@ -22,6 +24,8 @@ public class Enderman extends WalkingMonster { public static final int NETWORK_ID = 38; + private boolean angry = false; + public Enderman(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @@ -104,7 +108,17 @@ public void attackEntity(Entity player) { public boolean attack(EntityDamageEvent ev) { super.attack(ev); if (!ev.isCancelled()) { + + if(ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){ + if(!isAngry()) { + setAngry(true); + } + } + if (ev.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { + if(!isAngry()) { + setAngry(true); + } ev.setCancelled(true); tp(); } else if (Utils.rand(1, 10) == 1) { @@ -139,11 +153,22 @@ public boolean entityBaseTick(int tickDiff) { if (this.level.getBlock(new Vector3(NukkitMath.floorDouble(this.x), (int) this.y, NukkitMath.floorDouble(this.z))) instanceof BlockWater) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); + if(isAngry()) { + setAngry(false); + } tp(); } else if (Utils.rand(0, 500) == 20) { tp(); } + if(this.age % 20 == 0 && this.level.isRaining() || this.level.isThundering()){ + this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); + if(isAngry()) { + setAngry(false); + } + tp(); + } + return super.entityBaseTick(tickDiff); } @@ -155,10 +180,29 @@ private void tp() { @Override public boolean canDespawn() { - if (this.getLevel().getName().equals("end")) { + if (this.getLevel().getDimension() == Level.DIMENSION_THE_END) { return false; } return super.canDespawn(); } + + public void makeVibrating(boolean bool){ + this.setDataFlag(DATA_FLAGS,DATA_FLAG_VIBRATING,bool); + } + + public boolean isAngry(){ + return angry; + } + + public void setAngry(boolean bool) { + this.angry = bool; + makeVibrating(bool); + } + + @Override + public boolean targetOption(EntityCreature creature, double distance) { + if(!angry)return false; + return super.targetOption(creature, distance); + } } From 56f4a3419389332c4fca08178a75d8e42d1df265 Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Sat, 10 Aug 2019 12:02:54 +0800 Subject: [PATCH 06/12] improve enderman --- .../nukkitcoders/mobplugin/EventListener.java | 34 +++++++++++++++++++ .../entities/monster/walking/Enderman.java | 10 ++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/nukkitcoders/mobplugin/EventListener.java b/src/main/java/nukkitcoders/mobplugin/EventListener.java index 90f62e0fc..de901fa17 100644 --- a/src/main/java/nukkitcoders/mobplugin/EventListener.java +++ b/src/main/java/nukkitcoders/mobplugin/EventListener.java @@ -6,9 +6,11 @@ import cn.nukkit.block.BlockAir; import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.entity.Entity; +import cn.nukkit.entity.EntityCreature; import cn.nukkit.entity.projectile.EntityEgg; import cn.nukkit.entity.projectile.EntityEnderPearl; import cn.nukkit.event.EventHandler; +import cn.nukkit.event.EventPriority; import cn.nukkit.event.Listener; import cn.nukkit.event.block.BlockBreakEvent; import cn.nukkit.event.block.BlockPlaceEvent; @@ -16,9 +18,12 @@ import cn.nukkit.event.entity.EntityDeathEvent; import cn.nukkit.event.entity.ProjectileHitEvent; import cn.nukkit.event.player.PlayerInteractEvent; +import cn.nukkit.event.player.PlayerMoveEvent; import cn.nukkit.event.server.DataPacketReceiveEvent; import cn.nukkit.item.Item; +import cn.nukkit.math.AxisAlignedBB; import cn.nukkit.math.BlockFace; +import cn.nukkit.math.SimpleAxisAlignedBB; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.EntityEventPacket; import cn.nukkit.network.protocol.PlayerInputPacket; @@ -27,6 +32,7 @@ import nukkitcoders.mobplugin.entities.animal.walking.Chicken; import nukkitcoders.mobplugin.entities.animal.walking.Llama; import nukkitcoders.mobplugin.entities.block.BlockEntitySpawner; +import nukkitcoders.mobplugin.entities.monster.walking.Enderman; import nukkitcoders.mobplugin.entities.monster.walking.Silverfish; import nukkitcoders.mobplugin.event.entity.SpawnGolemEvent; import nukkitcoders.mobplugin.event.spawner.SpawnerChangeTypeEvent; @@ -208,4 +214,32 @@ public void DataPacketReceiveEvent(DataPacketReceiveEvent ev) { } } } + + @EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true) + public void stareEnderman(PlayerMoveEvent event){ + if(event.getPlayer().getLevel().getCurrentTick() % 20 == 0){ + Player player = event.getPlayer(); + double kk = Math.tan(player.getPitch() * -1 * Math.PI / 180); + AxisAlignedBB aab = new SimpleAxisAlignedBB( + player.getX() - 0.6f, + player.getY() + 1.45f, + player.getZ() - 0.6f, + player.getX() + 0.6f, + player.getY() + 2.9f, + player.getZ() + 0.6f + ); + for(int i = 0; i < 8;i++){ + aab.offset(-Math.sin(player.getYaw() * Math.PI / 180) * i, i * kk, Math.cos(player.getYaw() * Math.PI / 180) * i); + Entity entities[] = player.getLevel().getCollidingEntities(aab); + if(entities.length > 0){ + for (Entity e : entities) { + if (e instanceof Enderman) { + ((Enderman) e).stareToAngry(); + } + } + } + } + } + } + } diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index 4be82f24d..308612d98 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -161,7 +161,7 @@ public boolean entityBaseTick(int tickDiff) { tp(); } - if(this.age % 20 == 0 && this.level.isRaining() || this.level.isThundering()){ + if(this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())){ this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); if(isAngry()) { setAngry(false); @@ -188,7 +188,7 @@ public boolean canDespawn() { } public void makeVibrating(boolean bool){ - this.setDataFlag(DATA_FLAGS,DATA_FLAG_VIBRATING,bool); + this.setDataFlag(DATA_FLAGS,67,bool); } public boolean isAngry(){ @@ -205,4 +205,10 @@ public boolean targetOption(EntityCreature creature, double distance) { if(!angry)return false; return super.targetOption(creature, distance); } + + public void stareToAngry(){ + if(!isAngry()) { + setAngry(true); + } + } } From 2a51e950659618f292410e123f2273b7b28fe9d9 Mon Sep 17 00:00:00 2001 From: zzz <1173572640@qq.com> Date: Mon, 12 Aug 2019 01:51:37 +0000 Subject: [PATCH 07/12] Revert "update" --- .circleci/config.yml | 2 +- pom.xml | 2 +- src/main/java/nukkitcoders/mobplugin/MobPlugin.java | 2 +- .../nukkitcoders/mobplugin/entities/animal/walking/Cow.java | 2 +- .../mobplugin/entities/animal/walking/Mooshroom.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 02cb65416..4022bc666 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,4 +24,4 @@ jobs: - run: mvn clean package - store_artifacts: - path: target/MobPlugin-1.10.1.jar + path: target/MobPlugin-1.10.jar diff --git a/pom.xml b/pom.xml index d91754619..00dcbffc8 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ nukkitcoders.mobplugin MobPlugin - 1.10.1 + 1.10 install ${basedir}/src/main/java diff --git a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java index fcbfc00c7..a6680350c 100644 --- a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java +++ b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java @@ -93,7 +93,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } - switch (args[0].toLowerCase()) { + switch (args[0]) { case "spawn": if (args.length == 1) { sender.sendMessage("Usage: /mob spawn "); diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java index a7c45799d..3be28221c 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java @@ -53,8 +53,8 @@ public void initEntity() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); + player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java index a99ebd1f2..8c6c1392c 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java @@ -84,12 +84,12 @@ public int getKillExperience() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BOWL, 0), true)) { - player.getInventory().addItem(Item.get(Item.MUSHROOM_STEW, 0, 1)); player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); + player.getInventory().addItem(Item.get(Item.MUSHROOM_STEW, 0, 1)); return true; } else if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); + player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { From b933e85e9e0119be4e3646cfbe955279bde4e78b Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Tue, 13 Aug 2019 00:21:43 +0800 Subject: [PATCH 08/12] format indent --- .../nukkitcoders/mobplugin/EventListener.java | 11 ++++---- .../entities/monster/walking/Enderman.java | 26 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/nukkitcoders/mobplugin/EventListener.java b/src/main/java/nukkitcoders/mobplugin/EventListener.java index de901fa17..6bcb2e60b 100644 --- a/src/main/java/nukkitcoders/mobplugin/EventListener.java +++ b/src/main/java/nukkitcoders/mobplugin/EventListener.java @@ -6,7 +6,6 @@ import cn.nukkit.block.BlockAir; import cn.nukkit.blockentity.BlockEntity; import cn.nukkit.entity.Entity; -import cn.nukkit.entity.EntityCreature; import cn.nukkit.entity.projectile.EntityEgg; import cn.nukkit.entity.projectile.EntityEnderPearl; import cn.nukkit.event.EventHandler; @@ -215,9 +214,9 @@ public void DataPacketReceiveEvent(DataPacketReceiveEvent ev) { } } - @EventHandler(priority = EventPriority.NORMAL,ignoreCancelled = true) - public void stareEnderman(PlayerMoveEvent event){ - if(event.getPlayer().getLevel().getCurrentTick() % 20 == 0){ + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void stareEnderman(PlayerMoveEvent event) { + if (event.getPlayer().getLevel().getCurrentTick() % 20 == 0) { Player player = event.getPlayer(); double kk = Math.tan(player.getPitch() * -1 * Math.PI / 180); AxisAlignedBB aab = new SimpleAxisAlignedBB( @@ -228,10 +227,10 @@ public void stareEnderman(PlayerMoveEvent event){ player.getY() + 2.9f, player.getZ() + 0.6f ); - for(int i = 0; i < 8;i++){ + for (int i = 0; i < 8; i++) { aab.offset(-Math.sin(player.getYaw() * Math.PI / 180) * i, i * kk, Math.cos(player.getYaw() * Math.PI / 180) * i); Entity entities[] = player.getLevel().getCollidingEntities(aab); - if(entities.length > 0){ + if (entities.length > 0) { for (Entity e : entities) { if (e instanceof Enderman) { ((Enderman) e).stareToAngry(); diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index 308612d98..b29ae4eca 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -55,7 +55,7 @@ protected void initEntity() { this.setMaxHealth(40); super.initEntity(); - this.setDamage(new float[] { 0, 4, 7, 10 }); + this.setDamage(new float[]{0, 4, 7, 10}); } public void attackEntity(Entity player) { @@ -109,14 +109,14 @@ public boolean attack(EntityDamageEvent ev) { super.attack(ev); if (!ev.isCancelled()) { - if(ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){ - if(!isAngry()) { + if (ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) { + if (!isAngry()) { setAngry(true); } } if (ev.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { - if(!isAngry()) { + if (!isAngry()) { setAngry(true); } ev.setCancelled(true); @@ -153,7 +153,7 @@ public boolean entityBaseTick(int tickDiff) { if (this.level.getBlock(new Vector3(NukkitMath.floorDouble(this.x), (int) this.y, NukkitMath.floorDouble(this.z))) instanceof BlockWater) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); - if(isAngry()) { + if (isAngry()) { setAngry(false); } tp(); @@ -161,9 +161,9 @@ public boolean entityBaseTick(int tickDiff) { tp(); } - if(this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())){ + if (this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); - if(isAngry()) { + if (isAngry()) { setAngry(false); } tp(); @@ -187,11 +187,11 @@ public boolean canDespawn() { return super.canDespawn(); } - public void makeVibrating(boolean bool){ - this.setDataFlag(DATA_FLAGS,67,bool); + public void makeVibrating(boolean bool) { + this.setDataFlag(DATA_FLAGS, 67, bool); } - public boolean isAngry(){ + public boolean isAngry() { return angry; } @@ -202,12 +202,12 @@ public void setAngry(boolean bool) { @Override public boolean targetOption(EntityCreature creature, double distance) { - if(!angry)return false; + if (!angry) return false; return super.targetOption(creature, distance); } - public void stareToAngry(){ - if(!isAngry()) { + public void stareToAngry() { + if (!isAngry()) { setAngry(true); } } From 56ad4886b3ee2cf2b290ce61fcfa7b00f6bd829d Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Tue, 13 Aug 2019 13:01:56 +0800 Subject: [PATCH 09/12] update --- .circleci/config.yml | 2 +- pom.xml | 2 +- src/main/java/nukkitcoders/mobplugin/MobPlugin.java | 2 +- .../nukkitcoders/mobplugin/entities/animal/walking/Cow.java | 2 +- .../mobplugin/entities/animal/walking/Mooshroom.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4022bc666..02cb65416 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,4 +24,4 @@ jobs: - run: mvn clean package - store_artifacts: - path: target/MobPlugin-1.10.jar + path: target/MobPlugin-1.10.1.jar diff --git a/pom.xml b/pom.xml index 00dcbffc8..d91754619 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ nukkitcoders.mobplugin MobPlugin - 1.10 + 1.10.1 install ${basedir}/src/main/java diff --git a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java index a6680350c..fcbfc00c7 100644 --- a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java +++ b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java @@ -93,7 +93,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } - switch (args[0]) { + switch (args[0].toLowerCase()) { case "spawn": if (args.length == 1) { sender.sendMessage("Usage: /mob spawn "); diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java index 3be28221c..a7c45799d 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java @@ -53,8 +53,8 @@ public void initEntity() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); + player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java index 8c6c1392c..a99ebd1f2 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java @@ -84,12 +84,12 @@ public int getKillExperience() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BOWL, 0), true)) { - player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); player.getInventory().addItem(Item.get(Item.MUSHROOM_STEW, 0, 1)); + player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); return true; } else if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); + player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { From f787c5c9ecff8d534cb2622af6e7f914292fd7a3 Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Tue, 13 Aug 2019 14:25:27 +0800 Subject: [PATCH 10/12] update --- .../nukkitcoders/mobplugin/EventListener.java | 34 ++++++++++++ .../entities/monster/walking/Enderman.java | 55 ++++++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/main/java/nukkitcoders/mobplugin/EventListener.java b/src/main/java/nukkitcoders/mobplugin/EventListener.java index 90f62e0fc..abbe08a77 100644 --- a/src/main/java/nukkitcoders/mobplugin/EventListener.java +++ b/src/main/java/nukkitcoders/mobplugin/EventListener.java @@ -9,6 +9,7 @@ import cn.nukkit.entity.projectile.EntityEgg; import cn.nukkit.entity.projectile.EntityEnderPearl; import cn.nukkit.event.EventHandler; +import cn.nukkit.event.EventPriority; import cn.nukkit.event.Listener; import cn.nukkit.event.block.BlockBreakEvent; import cn.nukkit.event.block.BlockPlaceEvent; @@ -16,9 +17,12 @@ import cn.nukkit.event.entity.EntityDeathEvent; import cn.nukkit.event.entity.ProjectileHitEvent; import cn.nukkit.event.player.PlayerInteractEvent; +import cn.nukkit.event.player.PlayerMoveEvent; import cn.nukkit.event.server.DataPacketReceiveEvent; import cn.nukkit.item.Item; +import cn.nukkit.math.AxisAlignedBB; import cn.nukkit.math.BlockFace; +import cn.nukkit.math.SimpleAxisAlignedBB; import cn.nukkit.nbt.tag.CompoundTag; import cn.nukkit.network.protocol.EntityEventPacket; import cn.nukkit.network.protocol.PlayerInputPacket; @@ -27,6 +31,7 @@ import nukkitcoders.mobplugin.entities.animal.walking.Chicken; import nukkitcoders.mobplugin.entities.animal.walking.Llama; import nukkitcoders.mobplugin.entities.block.BlockEntitySpawner; +import nukkitcoders.mobplugin.entities.monster.walking.Enderman; import nukkitcoders.mobplugin.entities.monster.walking.Silverfish; import nukkitcoders.mobplugin.event.entity.SpawnGolemEvent; import nukkitcoders.mobplugin.event.spawner.SpawnerChangeTypeEvent; @@ -208,4 +213,33 @@ public void DataPacketReceiveEvent(DataPacketReceiveEvent ev) { } } } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void stareEnderman(PlayerMoveEvent event) { + if (event.getPlayer().getLevel().getCurrentTick() % 20 == 0) { + Player player = event.getPlayer(); + double kk = Math.tan(player.getPitch() * -1 * Math.PI / 180); + AxisAlignedBB aab = new SimpleAxisAlignedBB( + player.getX() - 0.6f, + player.getY() + 1.45f, + player.getZ() - 0.6f, + player.getX() + 0.6f, + player.getY() + 2.9f, + player.getZ() + 0.6f + ); + for (int i = 0; i < 8; i++) { + aab.offset(-Math.sin(player.getYaw() * Math.PI / 180) * i, i * kk, Math.cos(player.getYaw() * Math.PI / 180) * i); + Entity entities[] = player.getLevel().getCollidingEntities(aab); + if (entities.length > 0) { + for (Entity e : entities) { + if (e instanceof Enderman) { + ((Enderman) e).stareToAngry(); + } + } + } + } + } + } + } + diff --git a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java index d103ddb14..443e9edad 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/monster/walking/Enderman.java @@ -3,9 +3,11 @@ import cn.nukkit.Player; import cn.nukkit.block.BlockWater; import cn.nukkit.entity.Entity; +import cn.nukkit.entity.EntityCreature; import cn.nukkit.event.entity.EntityDamageByEntityEvent; import cn.nukkit.event.entity.EntityDamageEvent; import cn.nukkit.item.Item; +import cn.nukkit.level.Level; import cn.nukkit.level.Sound; import cn.nukkit.level.format.FullChunk; import cn.nukkit.math.NukkitMath; @@ -22,6 +24,8 @@ public class Enderman extends WalkingMonster { public static final int NETWORK_ID = 38; + private boolean angry = false; + public Enderman(FullChunk chunk, CompoundTag nbt) { super(chunk, nbt); } @@ -51,7 +55,7 @@ protected void initEntity() { this.setMaxHealth(40); super.initEntity(); - this.setDamage(new float[] { 0, 4, 7, 10 }); + this.setDamage(new float[]{0, 4, 7, 10}); } public void attackEntity(Entity player) { @@ -104,7 +108,17 @@ public void attackEntity(Entity player) { public boolean attack(EntityDamageEvent ev) { super.attack(ev); if (!ev.isCancelled()) { + + if (ev.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) { + if (!isAngry()) { + setAngry(true); + } + } + if (ev.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { + if (!isAngry()) { + setAngry(true); + } ev.setCancelled(true); tp(); } else if (Utils.rand(1, 10) == 1) { @@ -139,11 +153,22 @@ public boolean entityBaseTick(int tickDiff) { if (this.level.getBlock(new Vector3(NukkitMath.floorDouble(this.x), (int) this.y, NukkitMath.floorDouble(this.z))) instanceof BlockWater) { this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); + if (isAngry()) { + setAngry(false); + } tp(); } else if (Utils.rand(0, 500) == 20) { tp(); } + if (this.age % 20 == 0 && (this.level.isRaining() || this.level.isThundering())) { + this.attack(new EntityDamageEvent(this, EntityDamageEvent.DamageCause.DROWNING, 2)); + if (isAngry()) { + setAngry(false); + } + tp(); + } + return super.entityBaseTick(tickDiff); } @@ -155,10 +180,36 @@ private void tp() { @Override public boolean canDespawn() { - if (this.getLevel().getName().equals("end")) { + if (this.getLevel().getDimension() == Level.DIMENSION_THE_END) { return false; } return super.canDespawn(); } + + public void makeVibrating(boolean bool) { + this.setDataFlag(DATA_FLAGS, 67, bool); + } + + public boolean isAngry() { + return angry; + } + + public void setAngry(boolean bool) { + this.angry = bool; + makeVibrating(bool); + } + + @Override + public boolean targetOption(EntityCreature creature, double distance) { + if (!angry) return false; + return super.targetOption(creature, distance); + } + + public void stareToAngry() { + if (!isAngry()) { + setAngry(true); + } + } } + From ec93d4ad5f044edad3acc6c294e4e957820d81ad Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Tue, 13 Aug 2019 14:42:33 +0800 Subject: [PATCH 11/12] update --- .circleci/config.yml | 2 +- pom.xml | 2 +- src/main/java/nukkitcoders/mobplugin/MobPlugin.java | 2 +- .../nukkitcoders/mobplugin/entities/animal/walking/Cow.java | 2 +- .../mobplugin/entities/animal/walking/Mooshroom.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4022bc666..02cb65416 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,4 +24,4 @@ jobs: - run: mvn clean package - store_artifacts: - path: target/MobPlugin-1.10.jar + path: target/MobPlugin-1.10.1.jar diff --git a/pom.xml b/pom.xml index 00dcbffc8..d91754619 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ nukkitcoders.mobplugin MobPlugin - 1.10 + 1.10.1 install ${basedir}/src/main/java diff --git a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java index a6680350c..fcbfc00c7 100644 --- a/src/main/java/nukkitcoders/mobplugin/MobPlugin.java +++ b/src/main/java/nukkitcoders/mobplugin/MobPlugin.java @@ -93,7 +93,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return true; } - switch (args[0]) { + switch (args[0].toLowerCase()) { case "spawn": if (args.length == 1) { sender.sendMessage("Usage: /mob spawn "); diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java index 3be28221c..a7c45799d 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Cow.java @@ -53,8 +53,8 @@ public void initEntity() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); + player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { diff --git a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java index 8c6c1392c..a99ebd1f2 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/animal/walking/Mooshroom.java @@ -84,12 +84,12 @@ public int getKillExperience() { public boolean onInteract(Player player, Item item) { super.onInteract(player, item); if (item.equals(Item.get(Item.BOWL, 0), true)) { - player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); player.getInventory().addItem(Item.get(Item.MUSHROOM_STEW, 0, 1)); + player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); return true; } else if (item.equals(Item.get(Item.BUCKET, 0), true)) { - player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); player.getInventory().addItem(Item.get(Item.BUCKET, 1, 1)); + player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); this.level.addSound(this, Sound.MOB_COW_MILK); return true; } else if (item.equals(Item.get(Item.WHEAT, 0)) && !this.isBaby()) { From 224bce0e2c45b0ce272ec933979c8098afbbb2c5 Mon Sep 17 00:00:00 2001 From: zzz1999 <1173572640@qq.com> Date: Sat, 24 Aug 2019 02:56:36 +0800 Subject: [PATCH 12/12] update --- .../mobplugin/entities/WalkingEntity.java | 56 +++++++++++++++---- .../mobplugin/route/RouteFinder.java | 12 ++-- .../mobplugin/route/WalkerRouteFinder.java | 11 ++-- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/main/java/nukkitcoders/mobplugin/entities/WalkingEntity.java b/src/main/java/nukkitcoders/mobplugin/entities/WalkingEntity.java index f3ef0c7b5..56c484dbb 100644 --- a/src/main/java/nukkitcoders/mobplugin/entities/WalkingEntity.java +++ b/src/main/java/nukkitcoders/mobplugin/entities/WalkingEntity.java @@ -3,8 +3,10 @@ import cn.nukkit.block.*; import cn.nukkit.entity.Entity; import cn.nukkit.entity.EntityCreature; +import cn.nukkit.level.Location; import cn.nukkit.level.format.FullChunk; import cn.nukkit.level.particle.BubbleParticle; +import cn.nukkit.level.particle.DestroyBlockParticle; import cn.nukkit.math.NukkitMath; import cn.nukkit.math.Vector2; import cn.nukkit.math.Vector3; @@ -73,20 +75,50 @@ protected void checkTarget() { if (Utils.rand(1, 100) > 5) { return; } - x = Utils.rand(10, 30); - z = Utils.rand(10, 30); - this.target = this.add(Utils.rand() ? x : -x, Utils.rand(-20.0, 20.0) / 10, Utils.rand() ? z : -z); + x = Utils.rand(1, 3); + z = Utils.rand(1, 3); + Location tempLoc = this.add(Utils.rand() ? x : -x, Utils.rand(-20.0, 20.0) / 10, Utils.rand() ? z : -z); + if(route!=null){ + route.setDestination(tempLoc); + route.research(); + if(!route.isReachable()){ + route.resetNodes(); + target = this.getLocation(); + } + } + //System.out.println("cc"+this.getLocation()+route.nodes+route.isReachable()+route.hasNext()); + //level.addParticle(new DestroyBlockParticle(tempLoc,Block.get(Block.DIAMOND_BLOCK))); } else if (Utils.rand(1, 100) == 1) { - x = Utils.rand(10, 30); - z = Utils.rand(10, 30); + x = Utils.rand(1, 3); + z = Utils.rand(1, 3); this.stayTime = Utils.rand(100, 200); - this.target = this.add(Utils.rand() ? x : -x, Utils.rand(-20.0, 20.0) / 10, Utils.rand() ? z : -z); + Location tempLoc = this.add(Utils.rand() ? x : -x, Utils.rand(-20.0, 20.0) / 10, Utils.rand() ? z : -z); + if(route!=null){ + route.setDestination(tempLoc); + route.research(); + if(!route.isReachable()){ + route.resetNodes(); + target = this.getLocation(); + } + } + //System.out.println("dd"+this.getLocation()+route.nodes+route.isReachable()+route.hasNext()); + //level.addParticle(new DestroyBlockParticle(tempLoc,Block.get(Block.DIAMOND_BLOCK))); } else if (this.moveTime <= 0 || this.target == null) { - x = Utils.rand(20, 100); - z = Utils.rand(20, 100); + x = Utils.rand(2, 10); + z = Utils.rand(2, 10); this.stayTime = 0; - this.moveTime = Utils.rand(100, 200); - this.target = this.add(Utils.rand() ? x : -x, 0, Utils.rand() ? z : -z); + this.moveTime = Utils.rand(300, 1200); + Location tempLoc = this.add(Utils.rand() ? x : -x, 0, Utils.rand() ? z : -z); + if(route!=null){ + route.setDestination(tempLoc); + route.research(); + if(!route.isReachable()){ + route.resetNodes(); + target = this.getLocation(); + } + } + //System.out.println("ee"+this.getLocation()+route.nodes+route.isReachable()+route.hasNext()); + //level.addParticle(new DestroyBlockParticle(tempLoc,Block.get(Block.DIAMOND_BLOCK))); } } @@ -134,7 +166,9 @@ public Vector3 updateMove(int tickDiff) { } if (this.age % 10 == 0 && this.route != null && !this.route.isSearching()) { - RouteFinderThreadPool.executeRouteFinderThread(new RouteFinderSearchTask(this.route)); + if(followTarget != null) { + RouteFinderThreadPool.executeRouteFinderThread(new RouteFinderSearchTask(this.route)); + } if (this.route.hasNext()) { this.target = this.route.next(); } diff --git a/src/main/java/nukkitcoders/mobplugin/route/RouteFinder.java b/src/main/java/nukkitcoders/mobplugin/route/RouteFinder.java index d32ae13c4..27a284714 100644 --- a/src/main/java/nukkitcoders/mobplugin/route/RouteFinder.java +++ b/src/main/java/nukkitcoders/mobplugin/route/RouteFinder.java @@ -143,7 +143,7 @@ public void resetNodes() { this.nodes.clear(); this.current = 0; this.interrupt = false; - this.destination = null; + //this.destination = null; }finally { this.lock.writeLock().unlock(); } @@ -153,7 +153,7 @@ public void resetNodes() { public void research() { this.resetNodes(); - this.search(); + this.reachable = this.search(); } public boolean hasNext() { @@ -177,7 +177,11 @@ public boolean isInterrupted() { return this.interrupt; } - public boolean interrupt() { - return this.interrupt ^= true; + public void interrupt() { + this.setInterrupt(true); + } + + public void setInterrupt(boolean interrupt){ + this.interrupt = interrupt; } } diff --git a/src/main/java/nukkitcoders/mobplugin/route/WalkerRouteFinder.java b/src/main/java/nukkitcoders/mobplugin/route/WalkerRouteFinder.java index 273e2bb7c..555983f72 100644 --- a/src/main/java/nukkitcoders/mobplugin/route/WalkerRouteFinder.java +++ b/src/main/java/nukkitcoders/mobplugin/route/WalkerRouteFinder.java @@ -1,6 +1,9 @@ package nukkitcoders.mobplugin.route; import cn.nukkit.block.Block; +import cn.nukkit.event.block.BlockBreakEvent; +import cn.nukkit.item.Item; +import cn.nukkit.level.particle.ItemBreakParticle; import cn.nukkit.math.AxisAlignedBB; import cn.nukkit.math.SimpleAxisAlignedBB; import cn.nukkit.math.Vector3; @@ -9,6 +12,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.PriorityQueue; /** @@ -87,7 +91,6 @@ public boolean search() { } else { this.searching = false; this.finished = true; - this.reachable = false; this.addNode(new Node(destination)); return false; } @@ -331,7 +334,7 @@ private boolean hasBarrier(Vector3 pos1, Vector3 pos2) { if (traverseDirection) { double loopStart = Math.min(pos1.getX(), pos2.getX()); double loopEnd = Math.max(pos1.getX(), pos2.getX()); - ArrayList list = new ArrayList<>(); + List list = new ArrayList<>(); for (double i = Math.ceil(loopStart); i <= Math.floor(loopEnd); i += 1.0) { double result; if ((result = Utils.calLinearFunction(pos1, pos2, i, Utils.ACCORDING_X_OBTAIN_Y)) != Double.MAX_VALUE) @@ -341,7 +344,7 @@ private boolean hasBarrier(Vector3 pos1, Vector3 pos2) { } else { double loopStart = Math.min(pos1.getZ(), pos2.getZ()); double loopEnd = Math.max(pos1.getZ(), pos2.getZ()); - ArrayList list = new ArrayList<>(); + List list = new ArrayList<>(); for (double i = Math.ceil(loopStart); i <= Math.floor(loopEnd); i += 1.0) { double result; if ((result = Utils.calLinearFunction(pos1, pos2, i, Utils.ACCORDING_Y_OBTAIN_X)) != Double.MAX_VALUE) @@ -354,7 +357,7 @@ private boolean hasBarrier(Vector3 pos1, Vector3 pos2) { } - private boolean hasBlocksAround(ArrayList list) { + private boolean hasBlocksAround(List list) { double radius = (this.entity.getWidth() * this.entity.getScale()) / 2 + 0.1; double height = this.entity.getHeight() * this.entity.getScale(); for (Vector3 vector3 : list) {