Move FlyingUtil methods to NMS and Util

This commit is contained in:
fullwall 2013-11-05 21:38:08 +08:00
parent 4c9d80a464
commit 5a9fb3e1ab
29 changed files with 99 additions and 133 deletions

View File

@ -22,7 +22,6 @@ import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.Packet34EntityTeleport;
import org.bukkit.Bukkit;
@ -269,7 +268,7 @@ public class CitizensNPC extends AbstractNPC {
EntityType type = getTrait(MobType.class).getType();
if (type == null)
return;
if (FlyingUtil.isAlwaysFlyable(type)) {
if (Util.isAlwaysFlyable(type)) {
data().setPersistent(NPC.FLYABLE_METADATA, true);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityCaveSpider;
import net.minecraft.server.v1_6_R3.World;
@ -129,7 +128,7 @@ public class CaveSpiderController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityChicken;
import net.minecraft.server.v1_6_R3.World;
@ -114,7 +113,7 @@ public class ChickenController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityCow;
import net.minecraft.server.v1_6_R3.World;
@ -117,7 +116,7 @@ public class CowController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityCreeper;
import net.minecraft.server.v1_6_R3.EntityLightning;
import net.minecraft.server.v1_6_R3.World;
@ -123,7 +122,7 @@ public class CreeperController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityEnderman;
import net.minecraft.server.v1_6_R3.World;
@ -135,7 +134,7 @@ public class EndermanController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -14,7 +14,6 @@ import net.citizensnpcs.npc.network.EmptyNetworkManager;
import net.citizensnpcs.npc.network.EmptySocket;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.citizensnpcs.util.nms.PlayerControllerJump;
import net.citizensnpcs.util.nms.PlayerControllerLook;
import net.citizensnpcs.util.nms.PlayerControllerMove;
@ -105,7 +104,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityGiantZombie;
import net.minecraft.server.v1_6_R3.World;
@ -103,7 +102,7 @@ public class GiantController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -8,7 +8,6 @@ import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.trait.HorseModifiers;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityHorse;
import net.minecraft.server.v1_6_R3.World;
@ -115,7 +114,7 @@ public class HorseController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityIronGolem;
import net.minecraft.server.v1_6_R3.World;
@ -100,7 +99,7 @@ public class IronGolemController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityMagmaCube;
import net.minecraft.server.v1_6_R3.World;
@ -111,7 +110,7 @@ public class MagmaCubeController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityMushroomCow;
import net.minecraft.server.v1_6_R3.World;
@ -101,7 +100,7 @@ public class MushroomCowController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityOcelot;
import net.minecraft.server.v1_6_R3.World;
@ -101,7 +100,7 @@ public class OcelotController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityLightning;
import net.minecraft.server.v1_6_R3.EntityPig;
import net.minecraft.server.v1_6_R3.World;
@ -107,7 +106,7 @@ public class PigController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityPigZombie;
import net.minecraft.server.v1_6_R3.World;
@ -111,7 +110,7 @@ public class PigZombieController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySheep;
import net.minecraft.server.v1_6_R3.World;
@ -101,7 +100,7 @@ public class SheepController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySilverfish;
import net.minecraft.server.v1_6_R3.World;
@ -110,7 +109,7 @@ public class SilverfishController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySkeleton;
import net.minecraft.server.v1_6_R3.World;
@ -100,7 +99,7 @@ public class SkeletonController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySlime;
import net.minecraft.server.v1_6_R3.World;
@ -112,7 +111,7 @@ public class SlimeController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySnowman;
import net.minecraft.server.v1_6_R3.World;
@ -100,7 +99,7 @@ public class SnowmanController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySpider;
import net.minecraft.server.v1_6_R3.World;
@ -110,7 +109,7 @@ public class SpiderController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntitySquid;
import net.minecraft.server.v1_6_R3.World;
@ -101,7 +100,7 @@ public class SquidController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityHuman;
import net.minecraft.server.v1_6_R3.EntityVillager;
import net.minecraft.server.v1_6_R3.World;
@ -108,7 +107,7 @@ public class VillagerController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityWitch;
import net.minecraft.server.v1_6_R3.World;
@ -100,7 +99,7 @@ public class WitchController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityWolf;
import net.minecraft.server.v1_6_R3.World;
@ -101,7 +100,7 @@ public class WolfController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -7,7 +7,6 @@ import net.citizensnpcs.npc.MobEntityController;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.citizensnpcs.util.nms.FlyingUtil;
import net.minecraft.server.v1_6_R3.EntityZombie;
import net.minecraft.server.v1_6_R3.World;
@ -101,7 +100,7 @@ public class ZombieController extends MobEntityController {
if (npc == null || !npc.isFlyable()) {
super.e(f, f1);
} else {
FlyingUtil.moveLogic(this, f, f1);
NMS.flyingMoveLogic(this, f, f1);
}
}

View File

@ -12,6 +12,7 @@ import java.util.WeakHashMap;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.minecraft.server.Block;
import net.minecraft.server.v1_6_R3.AttributeInstance;
import net.minecraft.server.v1_6_R3.ControllerJump;
import net.minecraft.server.v1_6_R3.DamageSource;
@ -52,6 +53,65 @@ public class NMS {
// util class
}
public static void flyingMoveLogic(EntityLiving entity, float f, float f1) {
if (entity.G()) {
entity.a(f, f1, 0.02F);
entity.move(entity.motX, entity.motY, entity.motZ);
entity.motX *= 0.800000011920929D;
entity.motY *= 0.800000011920929D;
entity.motZ *= 0.800000011920929D;
} else if (entity.I()) {
entity.a(f, f1, 0.02F);
entity.move(entity.motX, entity.motY, entity.motZ);
entity.motX *= 0.5D;
entity.motY *= 0.5D;
entity.motZ *= 0.5D;
} else {
float f2 = 0.91F;
if (entity.onGround) {
f2 = 0.54600006F;
int i = entity.world.getTypeId(MathHelper.floor(entity.locX),
MathHelper.floor(entity.boundingBox.b) - 1, MathHelper.floor(entity.locZ));
if (i > 0) {
f2 = Block.byId[i].frictionFactor * 0.91F;
}
}
float f3 = 0.16277136F / (f2 * f2 * f2);
entity.a(f, f1, entity.onGround ? 0.1F * f3 : 0.02F);
f2 = 0.91F;
if (entity.onGround) {
f2 = 0.54600006F;
int j = entity.world.getTypeId(MathHelper.floor(entity.locX),
MathHelper.floor(entity.boundingBox.b) - 1, MathHelper.floor(entity.locZ));
if (j > 0) {
f2 = Block.byId[j].frictionFactor * 0.91F;
}
}
entity.move(entity.motX, entity.motY, entity.motZ);
entity.motX *= f2;
entity.motY *= f2;
entity.motZ *= f2;
}
entity.aF = entity.aG;
double d0 = entity.locX - entity.lastX;
double d1 = entity.locZ - entity.lastZ;
float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
if (f4 > 1.0F) {
f4 = 1.0F;
}
entity.aG += (f4 - entity.aG) * 0.4F;
entity.aH += entity.aG;
}
public static void addOrRemoveFromPlayerList(org.bukkit.entity.Entity entity, boolean remove) {
if (entity == null)
return;

View File

@ -23,6 +23,19 @@ public class Util {
private Util() {
}
public static boolean isAlwaysFlyable(EntityType type) {
switch (type) {
case BAT:
case BLAZE:
case GHAST:
case ENDER_DRAGON:
case WITHER:
return true;
default:
return false;
}
}
public static void assumePose(Entity entity, float yaw, float pitch) {
NMS.look(entity, yaw, pitch);
}

View File

@ -1,81 +0,0 @@
package net.citizensnpcs.util.nms;
import net.minecraft.server.Block;
import net.minecraft.server.MathHelper;
import net.minecraft.server.v1_6_R3.EntityLiving;
import org.bukkit.entity.EntityType;
public class FlyingUtil {
public static boolean isAlwaysFlyable(EntityType type) {
switch (type) {
case BAT:
case BLAZE:
case GHAST:
case ENDER_DRAGON:
case WITHER:
return true;
default:
return false;
}
}
public static void moveLogic(EntityLiving entity, float f, float f1) {
if (entity.G()) {
entity.a(f, f1, 0.02F);
entity.move(entity.motX, entity.motY, entity.motZ);
entity.motX *= 0.800000011920929D;
entity.motY *= 0.800000011920929D;
entity.motZ *= 0.800000011920929D;
} else if (entity.I()) {
entity.a(f, f1, 0.02F);
entity.move(entity.motX, entity.motY, entity.motZ);
entity.motX *= 0.5D;
entity.motY *= 0.5D;
entity.motZ *= 0.5D;
} else {
float f2 = 0.91F;
if (entity.onGround) {
f2 = 0.54600006F;
int i = entity.world.getTypeId(MathHelper.floor(entity.locX),
MathHelper.floor(entity.boundingBox.b) - 1, MathHelper.floor(entity.locZ));
if (i > 0) {
f2 = Block.byId[i].frictionFactor * 0.91F;
}
}
float f3 = 0.16277136F / (f2 * f2 * f2);
entity.a(f, f1, entity.onGround ? 0.1F * f3 : 0.02F);
f2 = 0.91F;
if (entity.onGround) {
f2 = 0.54600006F;
int j = entity.world.getTypeId(MathHelper.floor(entity.locX),
MathHelper.floor(entity.boundingBox.b) - 1, MathHelper.floor(entity.locZ));
if (j > 0) {
f2 = Block.byId[j].frictionFactor * 0.91F;
}
}
entity.move(entity.motX, entity.motY, entity.motZ);
entity.motX *= f2;
entity.motY *= f2;
entity.motZ *= f2;
}
entity.aF = entity.aG;
double d0 = entity.locX - entity.lastX;
double d1 = entity.locZ - entity.lastZ;
float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
if (f4 > 1.0F) {
f4 = 1.0F;
}
entity.aG += (f4 - entity.aG) * 0.4F;
entity.aH += entity.aG;
}
}