mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 00:19:05 +00:00
NPC flight fixes and a minor change to the createIItemStack function.
This commit is contained in:
1 parent
02d225a269
commit
115b66d0c6
4 files changed
+193
-17
No files matched your search
@@ -262,7 +262,7 @@ public class FlyPathFinder extends PathFinder
|
||||
/**
|
||||
* Returns a mapped point or creates and adds one
|
||||
*/
|
||||
private final FlyPathPoint openPoint(int p_75854_1_, int p_75854_2_, int p_75854_3_)
|
||||
private FlyPathPoint openPoint(int p_75854_1_, int p_75854_2_, int p_75854_3_)
|
||||
{
|
||||
int l = FlyPathPoint.makeHash(p_75854_1_, p_75854_2_, p_75854_3_);
|
||||
FlyPathPoint pathpoint = (FlyPathPoint)this.pointMap.lookup(l);
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package noppes.npcs.ai.pathfinder;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.passive.EntityChicken;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.pathfinding.PathEntity;
|
||||
import net.minecraft.pathfinding.PathNavigate;
|
||||
@@ -118,7 +121,7 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
*/
|
||||
public FlyPathEntity getPathToXYZ(double p_75488_1_, double p_75488_3_, double p_75488_5_)
|
||||
{
|
||||
return this.getEntityPathToXYZ(this.theEntity, MathHelper.floor_double(p_75488_1_), (int)p_75488_3_, MathHelper.floor_double(p_75488_5_), this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
|
||||
return !this.canNavigate() ? null : this.getEntityPathToXYZ(this.theEntity, MathHelper.floor_double(p_75488_1_), (int)p_75488_3_, MathHelper.floor_double(p_75488_5_), this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +138,7 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
*/
|
||||
public FlyPathEntity getPathToEntityLiving(Entity p_75494_1_)
|
||||
{
|
||||
return this.getPathEntityToEntity(this.theEntity, p_75494_1_, this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
|
||||
return !this.canNavigate() ? null : this.getPathEntityToEntity(this.theEntity, p_75494_1_, this.getPathSearchRange(), this.canPassOpenWoodenDoors, this.canPassClosedWoodenDoors, this.avoidsWater, this.canSwim);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,13 +199,26 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
return this.currentPath;
|
||||
}
|
||||
|
||||
private boolean isInLiquid()
|
||||
{
|
||||
return this.theEntity.isInWater() || this.theEntity.handleLavaMovement();
|
||||
}
|
||||
|
||||
private boolean canNavigate()
|
||||
{
|
||||
return !this.isInLiquid() || (this.canSwim && this.isInLiquid());
|
||||
}
|
||||
|
||||
public void onUpdateNavigation()
|
||||
{
|
||||
++this.totalTicks;
|
||||
|
||||
if (!this.noPath())
|
||||
{
|
||||
this.pathFollow();
|
||||
if (this.canNavigate())
|
||||
{
|
||||
this.pathFollow();
|
||||
}
|
||||
|
||||
if (!this.noPath())
|
||||
{
|
||||
@@ -245,7 +261,7 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.totalTicks - this.ticksAtLastPos > 100)
|
||||
if (this.totalTicks - this.ticksAtLastPos > 50)
|
||||
{
|
||||
if (vec3.squareDistanceTo(this.lastPosCheck) < 2.25D)
|
||||
{
|
||||
@@ -314,11 +330,148 @@ public class PathNavigateFlying extends PathNavigate {
|
||||
*/
|
||||
private boolean isDirectPathBetweenPoints(Vec3 p_75493_1_, Vec3 p_75493_2_, int p_75493_3_, int p_75493_4_, int p_75493_5_)
|
||||
{
|
||||
int l = MathHelper.floor_double(p_75493_1_.xCoord);
|
||||
int i1 = MathHelper.floor_double(p_75493_1_.zCoord);
|
||||
double d0 = p_75493_2_.xCoord - p_75493_1_.xCoord;
|
||||
double d1 = p_75493_2_.zCoord - p_75493_1_.zCoord;
|
||||
double d2 = d0 * d0 + d1 * d1;
|
||||
|
||||
return !(d2 < 1.0E-8D);
|
||||
if (d2 < 1.0E-8D)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
double d3 = 1.0D / Math.sqrt(d2);
|
||||
d0 *= d3;
|
||||
d1 *= d3;
|
||||
p_75493_3_ += 2;
|
||||
p_75493_5_ += 2;
|
||||
|
||||
if (!this.isSafeToStandAt(l, (int)p_75493_1_.yCoord, i1, p_75493_3_, p_75493_4_, p_75493_5_, p_75493_1_, d0, d1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_75493_3_ -= 2;
|
||||
p_75493_5_ -= 2;
|
||||
double d4 = 1.0D / Math.abs(d0);
|
||||
double d5 = 1.0D / Math.abs(d1);
|
||||
double d6 = (double)(l * 1) - p_75493_1_.xCoord;
|
||||
double d7 = (double)(i1 * 1) - p_75493_1_.zCoord;
|
||||
|
||||
if (d0 >= 0.0D)
|
||||
{
|
||||
++d6;
|
||||
}
|
||||
|
||||
if (d1 >= 0.0D)
|
||||
{
|
||||
++d7;
|
||||
}
|
||||
|
||||
d6 /= d0;
|
||||
d7 /= d1;
|
||||
int j1 = d0 < 0.0D ? -1 : 1;
|
||||
int k1 = d1 < 0.0D ? -1 : 1;
|
||||
int l1 = MathHelper.floor_double(p_75493_2_.xCoord);
|
||||
int i2 = MathHelper.floor_double(p_75493_2_.zCoord);
|
||||
int j2 = l1 - l;
|
||||
int k2 = i2 - i1;
|
||||
|
||||
do
|
||||
{
|
||||
if (j2 * j1 <= 0 && k2 * k1 <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (d6 < d7)
|
||||
{
|
||||
d6 += d4;
|
||||
l += j1;
|
||||
j2 = l1 - l;
|
||||
}
|
||||
else
|
||||
{
|
||||
d7 += d5;
|
||||
i1 += k1;
|
||||
k2 = i2 - i1;
|
||||
}
|
||||
}
|
||||
while (this.isSafeToStandAt(l, (int)p_75493_1_.yCoord, i1, p_75493_3_, p_75493_4_, p_75493_5_, p_75493_1_, d0, d1));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSafeToStandAt(int p_75483_1_, int p_75483_2_, int p_75483_3_, int p_75483_4_, int p_75483_5_, int p_75483_6_, Vec3 p_75483_7_, double p_75483_8_, double p_75483_10_)
|
||||
{
|
||||
int k1 = p_75483_1_ - p_75483_4_ / 2;
|
||||
int l1 = p_75483_3_ - p_75483_6_ / 2;
|
||||
|
||||
if (!this.isPositionClear(k1, p_75483_2_, l1, p_75483_4_, p_75483_5_, p_75483_6_, p_75483_7_, p_75483_8_, p_75483_10_))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i2 = k1; i2 < k1 + p_75483_4_; ++i2)
|
||||
{
|
||||
for (int j2 = l1; j2 < l1 + p_75483_6_; ++j2)
|
||||
{
|
||||
double d2 = (double)i2 + 0.5D - p_75483_7_.xCoord;
|
||||
double d3 = (double)j2 + 0.5D - p_75483_7_.zCoord;
|
||||
|
||||
if (d2 * p_75483_8_ + d3 * p_75483_10_ >= 0.0D)
|
||||
{
|
||||
Block block = this.worldObj.getBlock(i2, p_75483_2_ - 1, j2);
|
||||
Material material = block.getMaterial();
|
||||
|
||||
if (material == Material.water && !this.theEntity.isInWater())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (material == Material.lava)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPositionClear(int p_75496_1_, int p_75496_2_, int p_75496_3_, int p_75496_4_, int p_75496_5_, int p_75496_6_, Vec3 p_75496_7_, double p_75496_8_, double p_75496_10_)
|
||||
{
|
||||
for (int k1 = p_75496_1_; k1 < p_75496_1_ + p_75496_4_; ++k1)
|
||||
{
|
||||
for (int l1 = p_75496_2_; l1 < p_75496_2_ + p_75496_5_; ++l1)
|
||||
{
|
||||
for (int i2 = p_75496_3_; i2 < p_75496_3_ + p_75496_6_; ++i2)
|
||||
{
|
||||
double d2 = (double)k1 + 0.5D - p_75496_7_.xCoord;
|
||||
double d3 = (double)i2 + 0.5D - p_75496_7_.zCoord;
|
||||
|
||||
if (d2 * p_75496_8_ + d3 * p_75496_10_ >= 0.0D)
|
||||
{
|
||||
Block block = this.worldObj.getBlock(k1, l1, i2);
|
||||
|
||||
if (!block.getBlocksMovement(this.worldObj, k1, l1, i2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public FlyPathEntity getPathEntityToEntity(Entity p_72865_1_, Entity p_72865_2_, float p_72865_3_, boolean p_72865_4_, boolean p_72865_5_, boolean p_72865_6_, boolean p_72865_7_)
|
||||
|
||||
@@ -174,6 +174,9 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
}
|
||||
|
||||
public IItemStack getIItemStack(ItemStack itemstack) {
|
||||
if(itemstack == null)
|
||||
return null;
|
||||
|
||||
if (itemstack.getItem() instanceof ItemScripted) {
|
||||
return new ScriptCustomItem(itemstack);
|
||||
} else if(itemstack.getItem() instanceof ItemArmor) {
|
||||
@@ -192,17 +195,7 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
if (item instanceof ItemScripted) {
|
||||
return new ScriptCustomItem(new ItemStack(item, size, damage));
|
||||
} else if(item instanceof ItemArmor) {
|
||||
return new ScriptItemArmor(new ItemStack(item, size, damage));
|
||||
} else if(item instanceof ItemBook) {
|
||||
return new ScriptItemBook(new ItemStack(item, size, damage));
|
||||
} else if(item instanceof ItemBlock) {
|
||||
return new ScriptItemBlock(new ItemStack(item, size, damage));
|
||||
} else {
|
||||
return new ScriptItemStack(new ItemStack(item, size, damage));
|
||||
}
|
||||
return getIItemStack(new ItemStack(item, size, damage));
|
||||
}
|
||||
|
||||
public IWorld getIWorld(WorldServer world) {
|
||||
|
||||
@@ -10,18 +10,26 @@ import java.io.File;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.controllers.*;
|
||||
import noppes.npcs.scripted.gui.ScriptGui;
|
||||
import noppes.npcs.scripted.interfaces.entity.ICustomNpc;
|
||||
import noppes.npcs.scripted.interfaces.entity.IEntity;
|
||||
import noppes.npcs.scripted.interfaces.entity.IPlayer;
|
||||
import noppes.npcs.scripted.interfaces.gui.ICustomGui;
|
||||
import noppes.npcs.scripted.interfaces.handler.*;
|
||||
import noppes.npcs.scripted.interfaces.item.IItemStack;
|
||||
import noppes.npcs.scripted.interfaces.overlay.ICustomOverlay;
|
||||
import noppes.npcs.scripted.overlay.ScriptOverlay;
|
||||
|
||||
public abstract class AbstractNpcAPI {
|
||||
private static AbstractNpcAPI instance = null;
|
||||
@@ -29,6 +37,16 @@ public abstract class AbstractNpcAPI {
|
||||
public AbstractNpcAPI() {
|
||||
}
|
||||
|
||||
public abstract IFactionHandler getFactions();
|
||||
|
||||
public abstract IRecipeHandler getRecipes();
|
||||
|
||||
public abstract IQuestHandler getQuests();
|
||||
|
||||
public abstract IDialogHandler getDialogs();
|
||||
|
||||
public abstract ICloneHandler getClones();
|
||||
|
||||
public abstract ICustomNpc createNPC(World var1);
|
||||
|
||||
public abstract ICustomNpc spawnNPC(World var1, int var2, int var3, int var4);
|
||||
@@ -90,9 +108,21 @@ public abstract class AbstractNpcAPI {
|
||||
|
||||
public abstract IItemStack createItem(String id, int damage, int size);
|
||||
|
||||
public abstract void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch);
|
||||
|
||||
public abstract void playSoundToNearExcept(IPlayer player, String sound, float volume, float pitch);
|
||||
|
||||
public abstract String getMOTD();
|
||||
|
||||
public abstract void setMOTD(String motd);
|
||||
|
||||
public abstract IParticle createParticle(String directory);
|
||||
|
||||
public abstract IParticle createEntityParticle(String directory);
|
||||
|
||||
public abstract int getServerTime();
|
||||
|
||||
public abstract ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame);
|
||||
|
||||
public abstract ICustomOverlay createCustomOverlay(int id);
|
||||
}
|
||||
Reference in new issue
Block a user