Fix speed modifier, add preliminary BlockBreaker class

This commit is contained in:
fullwall 2013-02-17 20:30:18 +08:00
parent b58f91a7a2
commit 968d325a15
31 changed files with 236 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -31,7 +31,6 @@ public class CitizensNavigator implements Navigator, Runnable {
private int lastX, lastY, lastZ; private int lastX, lastY, lastZ;
private NavigatorParameters localParams = defaultParams; private NavigatorParameters localParams = defaultParams;
private final NPC npc; private final NPC npc;
private int stationaryTicks; private int stationaryTicks;
public CitizensNavigator(NPC npc) { public CitizensNavigator(NPC npc) {
@ -56,7 +55,7 @@ public class CitizensNavigator implements Navigator, Runnable {
@Override @Override
public NavigatorParameters getLocalParameters() { public NavigatorParameters getLocalParameters() {
if (!isNavigating()) if (!isNavigating())
throw new IllegalStateException("not navigating"); return defaultParams;
return localParams; return localParams;
} }

View File

@ -57,6 +57,11 @@ public class BatController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
if (npc == null) if (npc == null)

View File

@ -57,6 +57,11 @@ public class BlazeController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bn() { public void bn() {
if (npc != null) if (npc != null)

View File

@ -57,6 +57,11 @@ public class CaveSpiderController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -57,6 +57,11 @@ public class ChickenController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -57,6 +57,11 @@ public class CowController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -64,6 +64,11 @@ public class CreeperController extends MobEntityController {
super.a(entitylightning); super.a(entitylightning);
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -56,6 +56,11 @@ public class EnderDragonController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bn() { public void bn() {
if (npc == null) if (npc == null)

View File

@ -57,6 +57,11 @@ public class EndermanController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -47,7 +47,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
@Override @Override
public float bB() { public float bB() {
return super.bB() * npc.getNavigator().getDefaultParameters().speed(); return super.bB() * npc.getNavigator().getLocalParameters().speed();
} }
@Override @Override

View File

@ -39,10 +39,14 @@ public class GhastController extends MobEntityController {
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
if (npc != null) { if (npc != null) {
NMS.clearGoals(goalSelector, targetSelector); NMS.clearGoals(goalSelector, targetSelector);
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bn() { public void bn() {
if (npc != null) if (npc != null)

View File

@ -43,6 +43,11 @@ public class GiantController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bn() { public void bn() {
if (npc == null) if (npc == null)

View File

@ -42,6 +42,11 @@ public class IronGolemController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -44,6 +44,11 @@ public class MagmaCubeController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -44,6 +44,11 @@ public class MushroomCowController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class OcelotController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -50,6 +50,11 @@ public class PigController extends MobEntityController {
super.a(entitylightning); super.a(entitylightning);
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -44,6 +44,11 @@ public class PigZombieController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class SheepController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class SilverfishController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class SkeletonController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -45,6 +45,11 @@ public class SlimeController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class SnowmanController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class SpiderController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,11 +43,16 @@ public class SquidController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bn() { public void bn() {
if (npc != null) if (npc != null) {
npc.update(); npc.update();
else } else
super.bn(); super.bn();
} }

View File

@ -51,6 +51,11 @@ public class VillagerController extends MobEntityController {
return false; // block trades return false; // block trades
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class WitchController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class WitherController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class WolfController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();

View File

@ -43,6 +43,11 @@ public class ZombieController extends MobEntityController {
} }
} }
@Override
public float bB() {
return super.bB() * npc.getNavigator().getLocalParameters().speed();
}
@Override @Override
public void bl() { public void bl() {
super.bl(); super.bl();