Merge branch 'master' of https://github.com/aidancbrady/Mekanism
This commit is contained in:
commit
6ff12e2c81
2 changed files with 163 additions and 5 deletions
|
@ -57,10 +57,11 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
|
||||||
|
|
||||||
getNavigator().setAvoidsWater(true);
|
getNavigator().setAvoidsWater(true);
|
||||||
|
|
||||||
tasks.addTask(1, new RobitAIFollow(this, 1.0F, 10.0F, 2.0F));
|
tasks.addTask(1, new RobitAIPickup(this, 1.0F));
|
||||||
tasks.addTask(2, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
|
tasks.addTask(2, new RobitAIFollow(this, 1.0F, 10.0F, 2.0F));
|
||||||
tasks.addTask(2, new EntityAILookIdle(this));
|
tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
|
||||||
tasks.addTask(3, new EntityAISwimming(this));
|
tasks.addTask(3, new EntityAILookIdle(this));
|
||||||
|
tasks.addTask(4, new EntityAISwimming(this));
|
||||||
|
|
||||||
setAlwaysRenderNameTag(true);
|
setAlwaysRenderNameTag(true);
|
||||||
}
|
}
|
||||||
|
|
157
common/mekanism/common/RobitAIPickup.java
Normal file
157
common/mekanism/common/RobitAIPickup.java
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
package mekanism.common;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.entity.ai.EntityAIBase;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.pathfinding.PathNavigate;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class RobitAIPickup extends EntityAIBase
|
||||||
|
{
|
||||||
|
|
||||||
|
//Written by pixlepix (I'm in mekanism! Yay!)
|
||||||
|
//Boilerplate copied from RobitAIFollow
|
||||||
|
/** The robit entity. */
|
||||||
|
private EntityRobit theRobit;
|
||||||
|
|
||||||
|
|
||||||
|
/** The world the robit is located in. */
|
||||||
|
private World theWorld;
|
||||||
|
|
||||||
|
/** How fast the robit can travel. */
|
||||||
|
private float moveSpeed;
|
||||||
|
|
||||||
|
/** The robit's pathfinder. */
|
||||||
|
private PathNavigate thePathfinder;
|
||||||
|
|
||||||
|
/** The ticker for updates. */
|
||||||
|
private int ticker;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Whether or not this robit avoids water. */
|
||||||
|
private boolean avoidWater;
|
||||||
|
private EntityItem closest;
|
||||||
|
|
||||||
|
public RobitAIPickup(EntityRobit entityRobit, float speed)
|
||||||
|
{
|
||||||
|
theRobit = entityRobit;
|
||||||
|
theWorld = entityRobit.worldObj;
|
||||||
|
moveSpeed = speed;
|
||||||
|
thePathfinder = entityRobit.getNavigator();
|
||||||
|
setMutexBits(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldExecute()
|
||||||
|
{
|
||||||
|
EntityPlayer player = theRobit.getOwner();
|
||||||
|
|
||||||
|
if(player == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!theRobit.getDropPickup()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(theRobit.worldObj.provider.dimensionId != player.worldObj.provider.dimensionId)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(closest!=null&&closest.getDistanceSqToEntity(closest)>100&&this.thePathfinder.getPathToXYZ(closest.posX, closest.posY, closest.posZ)!=null){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
List items=theRobit.worldObj.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(theRobit.posX-10, theRobit.posY-10, theRobit.posZ-10, theRobit.posX+10, theRobit.posY+10, theRobit.posZ+10));
|
||||||
|
Iterator iter=items.iterator();
|
||||||
|
//Cached for slight performance
|
||||||
|
double closestDistance=-1;
|
||||||
|
while(iter.hasNext()){
|
||||||
|
|
||||||
|
EntityItem entity=(EntityItem) iter.next();
|
||||||
|
double distance=theRobit.getDistanceSqToEntity(entity);
|
||||||
|
if(distance<100){
|
||||||
|
if(closestDistance==-1||distance<closestDistance){
|
||||||
|
if(this.thePathfinder.getPathToXYZ(entity.posX, entity.posY, entity.posZ)!=null){
|
||||||
|
closest=entity;
|
||||||
|
closestDistance=distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(closest==null){
|
||||||
|
//No valid items
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean continueExecuting()
|
||||||
|
{
|
||||||
|
return !closest.isDead && !thePathfinder.noPath() && theRobit.getDistanceSqToEntity(closest) > (100) && theRobit.getFollowing() && theRobit.getEnergy() > 0 && closest.worldObj.provider.dimensionId == theRobit.worldObj.provider.dimensionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startExecuting()
|
||||||
|
{
|
||||||
|
ticker = 0;
|
||||||
|
avoidWater = theRobit.getNavigator().getAvoidsWater();
|
||||||
|
theRobit.getNavigator().setAvoidsWater(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetTask()
|
||||||
|
{
|
||||||
|
thePathfinder.clearPathEntity();
|
||||||
|
theRobit.getNavigator().setAvoidsWater(avoidWater);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTask()
|
||||||
|
{
|
||||||
|
|
||||||
|
System.out.println(6);
|
||||||
|
theRobit.getLookHelper().setLookPositionWithEntity(closest, 6.0F, theRobit.getVerticalFaceSpeed()/10);
|
||||||
|
if(!theRobit.getDropPickup()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(--ticker <= 0)
|
||||||
|
{
|
||||||
|
ticker = 10;
|
||||||
|
|
||||||
|
if(!thePathfinder.tryMoveToEntityLiving(closest, moveSpeed))
|
||||||
|
{
|
||||||
|
if(theRobit.getDistanceSqToEntity(closest) >= 144.0D)
|
||||||
|
{
|
||||||
|
int x = MathHelper.floor_double(closest.posX) - 2;
|
||||||
|
int y = MathHelper.floor_double(closest.posZ) - 2;
|
||||||
|
int z = MathHelper.floor_double(closest.boundingBox.minY);
|
||||||
|
|
||||||
|
for(int l = 0; l <= 4; ++l)
|
||||||
|
{
|
||||||
|
for(int i1 = 0; i1 <= 4; ++i1)
|
||||||
|
{
|
||||||
|
if((l < 1 || i1 < 1 || l > 3 || i1 > 3) && theWorld.doesBlockHaveSolidTopSurface(x + l, z - 1, y + i1) && !theWorld.isBlockNormalCube(x + l, z, y + i1) && !theWorld.isBlockNormalCube(x + l, z + 1, y + i1))
|
||||||
|
{
|
||||||
|
|
||||||
|
System.out.println(7);
|
||||||
|
theRobit.setLocationAndAngles((x + l) + 0.5F, z, (y + i1) + 0.5F, theRobit.rotationYaw, theRobit.rotationPitch);
|
||||||
|
thePathfinder.clearPathEntity();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue