From 968d325a154482d8d3eddd1710055d34cb763cbf Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 17 Feb 2013 20:30:18 +0800 Subject: [PATCH] Fix speed modifier, add preliminary BlockBreaker class --- .../net/citizensnpcs/npc/ai/BlockBreaker.java | 92 +++++++++++++++++++ .../npc/ai/CitizensNavigator.java | 3 +- .../npc/entity/BatController.java | 5 + .../npc/entity/BlazeController.java | 5 + .../npc/entity/CaveSpiderController.java | 5 + .../npc/entity/ChickenController.java | 5 + .../npc/entity/CowController.java | 5 + .../npc/entity/CreeperController.java | 5 + .../npc/entity/EnderDragonController.java | 5 + .../npc/entity/EndermanController.java | 5 + .../npc/entity/EntityHumanNPC.java | 2 +- .../npc/entity/GhastController.java | 6 +- .../npc/entity/GiantController.java | 5 + .../npc/entity/IronGolemController.java | 5 + .../npc/entity/MagmaCubeController.java | 5 + .../npc/entity/MushroomCowController.java | 5 + .../npc/entity/OcelotController.java | 5 + .../npc/entity/PigController.java | 5 + .../npc/entity/PigZombieController.java | 5 + .../npc/entity/SheepController.java | 5 + .../npc/entity/SilverfishController.java | 5 + .../npc/entity/SkeletonController.java | 5 + .../npc/entity/SlimeController.java | 5 + .../npc/entity/SnowmanController.java | 5 + .../npc/entity/SpiderController.java | 5 + .../npc/entity/SquidController.java | 9 +- .../npc/entity/VillagerController.java | 5 + .../npc/entity/WitchController.java | 5 + .../npc/entity/WitherController.java | 5 + .../npc/entity/WolfController.java | 5 + .../npc/entity/ZombieController.java | 5 + 31 files changed, 236 insertions(+), 6 deletions(-) create mode 100644 src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java diff --git a/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java b/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java new file mode 100644 index 000000000..cb010c114 --- /dev/null +++ b/src/main/java/net/citizensnpcs/npc/ai/BlockBreaker.java @@ -0,0 +1,92 @@ +package net.citizensnpcs.npc.ai; + +import net.minecraft.server.v1_4_R1.Block; +import net.minecraft.server.v1_4_R1.Enchantment; +import net.minecraft.server.v1_4_R1.EnchantmentManager; +import net.minecraft.server.v1_4_R1.EntityHuman; +import net.minecraft.server.v1_4_R1.EntityLiving; +import net.minecraft.server.v1_4_R1.ItemStack; +import net.minecraft.server.v1_4_R1.Material; +import net.minecraft.server.v1_4_R1.MobEffectList; + +public class BlockBreaker { + private EntityLiving entity; + private ItemStack in; + private int lastDigTick, currentTick; + + public boolean destroyable(Block block) { + if (block.material.isAlwaysDestroyable()) { + return true; + } else { + return in != null ? in.b(block) : false; + } + } + + public void dig(int i, int j, int k, int l) { + if (true) { + entity.world.douseFire(null, i, j, k, l); + lastDigTick = currentTick; + float f = 1.0F; + int i1 = entity.world.getTypeId(i, j, k); + if (i1 > 0) { + Block.byId[i1].attack(entity.world, i, j, k, null); + // Allow fire punching to be blocked + entity.world.douseFire((EntityHuman) null, i, j, k, l); + } + if (i1 > 0) { + f = getStr(Block.byId[i1]); + } + EntityHuman m; + if (i1 > 0 && f >= 1.0F) { + // this.breakBlock(i, j, k); + } else { + // this.d = true; + // this.f = i; + // this.g = j; + // this.h = k; + int j1 = (int) (f * 10.0F); + entity.world.g(entity.id, i, j, k, j1); + // entity.o = j1; + } + } + } + + public float getStr(Block block) { + float base = block.m(null, 0, 0, 0); + return base < 0.0F ? 0.0F : (!destroyable(block) ? 1.0F / base / 100.0F : strengthMod(block) / base / 30.0F); + } + + public float strengthMod(Block block) { + float f = in.a(block); + int i = EnchantmentManager.getEnchantmentLevel(Enchantment.DURABILITY.id, in); + ItemStack itemstack = in; + + if (i > 0 && itemstack != null) { + float f1 = i * i + 1; + + if (!itemstack.b(block) && f <= 1.0F) { + f += f1 * 0.08F; + } else { + f += f1; + } + } + + if (entity.hasEffect(MobEffectList.FASTER_DIG)) { + f *= 1.0F + (entity.getEffect(MobEffectList.FASTER_DIG).getAmplifier() + 1) * 0.2F; + } + + if (entity.hasEffect(MobEffectList.SLOWER_DIG)) { + f *= 1.0F - (entity.getEffect(MobEffectList.SLOWER_DIG).getAmplifier() + 1) * 0.2F; + } + + if (entity.a(Material.WATER) && !EnchantmentManager.hasWaterWorkerEnchantment(entity)) { + f /= 5.0F; + } + + if (!entity.onGround) { + f /= 5.0F; + } + + return f; + } +} \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index cd964fff9..93a544d74 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -31,7 +31,6 @@ public class CitizensNavigator implements Navigator, Runnable { private int lastX, lastY, lastZ; private NavigatorParameters localParams = defaultParams; private final NPC npc; - private int stationaryTicks; public CitizensNavigator(NPC npc) { @@ -56,7 +55,7 @@ public class CitizensNavigator implements Navigator, Runnable { @Override public NavigatorParameters getLocalParameters() { if (!isNavigating()) - throw new IllegalStateException("not navigating"); + return defaultParams; return localParams; } diff --git a/src/main/java/net/citizensnpcs/npc/entity/BatController.java b/src/main/java/net/citizensnpcs/npc/entity/BatController.java index dabe6c7f8..9cb02be71 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/BatController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/BatController.java @@ -57,6 +57,11 @@ public class BatController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { if (npc == null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java b/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java index 0b91f511d..4a856a22e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/BlazeController.java @@ -57,6 +57,11 @@ public class BlazeController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bn() { if (npc != null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java b/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java index 680536c83..342c830ed 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CaveSpiderController.java @@ -57,6 +57,11 @@ public class CaveSpiderController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java b/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java index 105a1ea96..ad799cdc9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/ChickenController.java @@ -57,6 +57,11 @@ public class ChickenController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CowController.java b/src/main/java/net/citizensnpcs/npc/entity/CowController.java index 07d39f2d4..60ee3a934 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CowController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CowController.java @@ -57,6 +57,11 @@ public class CowController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java b/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java index 329cbd8bd..8fa2b0a39 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CreeperController.java @@ -64,6 +64,11 @@ public class CreeperController extends MobEntityController { super.a(entitylightning); } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java index bdaacfe0f..436756a42 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EnderDragonController.java @@ -56,6 +56,11 @@ public class EnderDragonController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bn() { if (npc == null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java index 7720d8dd3..879fa7ff1 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java @@ -57,6 +57,11 @@ public class EndermanController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index dc8d1ae56..e39828c14 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -47,7 +47,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { @Override public float bB() { - return super.bB() * npc.getNavigator().getDefaultParameters().speed(); + return super.bB() * npc.getNavigator().getLocalParameters().speed(); } @Override diff --git a/src/main/java/net/citizensnpcs/npc/entity/GhastController.java b/src/main/java/net/citizensnpcs/npc/entity/GhastController.java index 88bfa0741..75bd9f3c7 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/GhastController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/GhastController.java @@ -39,10 +39,14 @@ public class GhastController extends MobEntityController { this.npc = (CitizensNPC) npc; if (npc != null) { NMS.clearGoals(goalSelector, targetSelector); - } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bn() { if (npc != null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/GiantController.java b/src/main/java/net/citizensnpcs/npc/entity/GiantController.java index d35d20e4b..a4b61220e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/GiantController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/GiantController.java @@ -43,6 +43,11 @@ public class GiantController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bn() { if (npc == null) diff --git a/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java b/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java index c7708db15..ba58b4c61 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/IronGolemController.java @@ -42,6 +42,11 @@ public class IronGolemController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java b/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java index c6207d2de..ebf9cb439 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/MagmaCubeController.java @@ -44,6 +44,11 @@ public class MagmaCubeController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java b/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java index 5f72777ae..680f2cdb3 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/MushroomCowController.java @@ -44,6 +44,11 @@ public class MushroomCowController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java b/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java index bef81aada..3e1529c2a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/OcelotController.java @@ -43,6 +43,11 @@ public class OcelotController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/PigController.java b/src/main/java/net/citizensnpcs/npc/entity/PigController.java index 76b4d4011..c6f706db4 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/PigController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/PigController.java @@ -50,6 +50,11 @@ public class PigController extends MobEntityController { super.a(entitylightning); } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java b/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java index bd7def044..a7c4a75e1 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/PigZombieController.java @@ -44,6 +44,11 @@ public class PigZombieController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SheepController.java b/src/main/java/net/citizensnpcs/npc/entity/SheepController.java index 1d7020570..eae009924 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SheepController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SheepController.java @@ -43,6 +43,11 @@ public class SheepController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java b/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java index 996464100..1b59212d4 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SilverfishController.java @@ -43,6 +43,11 @@ public class SilverfishController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java b/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java index cbc05b383..4c420684f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SkeletonController.java @@ -43,6 +43,11 @@ public class SkeletonController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java b/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java index 822575601..92263686c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SlimeController.java @@ -45,6 +45,11 @@ public class SlimeController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java b/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java index 2862a9353..1ca81a48f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SnowmanController.java @@ -43,6 +43,11 @@ public class SnowmanController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java b/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java index ff56aea5e..b02ccbe66 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SpiderController.java @@ -43,6 +43,11 @@ public class SpiderController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/SquidController.java b/src/main/java/net/citizensnpcs/npc/entity/SquidController.java index 9972a7882..8f8ec1732 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/SquidController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/SquidController.java @@ -43,11 +43,16 @@ public class SquidController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bn() { - if (npc != null) + if (npc != null) { npc.update(); - else + } else super.bn(); } diff --git a/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java b/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java index 0faedaa62..ee2bf9a58 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/VillagerController.java @@ -51,6 +51,11 @@ public class VillagerController extends MobEntityController { return false; // block trades } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitchController.java b/src/main/java/net/citizensnpcs/npc/entity/WitchController.java index 8a32cec29..af776db30 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitchController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitchController.java @@ -43,6 +43,11 @@ public class WitchController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java index e8afa00bf..8c2953cf2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java @@ -43,6 +43,11 @@ public class WitherController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/WolfController.java b/src/main/java/net/citizensnpcs/npc/entity/WolfController.java index b31b4db5f..49b2b7c5e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WolfController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WolfController.java @@ -43,6 +43,11 @@ public class WolfController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl(); diff --git a/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java b/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java index d858395f9..54059a078 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/ZombieController.java @@ -43,6 +43,11 @@ public class ZombieController extends MobEntityController { } } + @Override + public float bB() { + return super.bB() * npc.getNavigator().getLocalParameters().speed(); + } + @Override public void bl() { super.bl();