fixed Entity IF checks for Grab cmd

This commit is contained in:
Rseifert 2013-02-13 00:55:39 -05:00
parent 00e1fb65e2
commit 22915fbc26
3 changed files with 55 additions and 10 deletions

View file

@ -68,7 +68,7 @@ public abstract class Command
* The parameters this command has, or the properties. Entered by the player in the disk.
* Parameters are entered like a Java function. idle(20) = Idles for 20 seconds.
*/
protected String[] parameters;
private String[] parameters;
/**
* Called by the TaskManager to propagate tick updates

View file

@ -10,6 +10,7 @@ import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import universalelectricity.core.vector.Vector3;
@ -34,13 +35,13 @@ public class CommandGrab extends Command
public CommandGrab()
{
super();
this.entityToInclude = EntityItem.class;
if (this.parameters != null && this.parameters.length > 0 && this.parameters[0] != null)
this.entityToInclude = Entity.class;
if (this.getArgs() != null && this.getArgs().length > 0 && this.getArgs()[0] != null)
{
if (this.getArg(0).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child"))
{
child = true;
if (this.parameters.length > 1 && this.parameters[1] != null)
if (this.getArgs().length > 1 && this.getArgs()[1] != null)
{
this.entityToInclude = GrabDictionary.get(this.getArg(0)).getEntityClass();
}
@ -48,7 +49,7 @@ public class CommandGrab extends Command
else
{
this.entityToInclude = GrabDictionary.get(this.getArg(0)).getEntityClass();
if (this.parameters.length > 1 && this.parameters[1] != null && (this.getArg(1).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child")))
if (this.getArgs().length > 1 && this.getArgs()[1] != null && (this.getArg(1).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child")))
{
child = true;
}
@ -71,10 +72,11 @@ public class CommandGrab extends Command
{
for (int i = 0; i < found.size(); i++)
{
if (found.get(i) != null && !(found.get(i) instanceof EntityArrow) && found.get(i).ridingEntity == null && (found.get(i) instanceof EntityAgeable && (child && ((EntityAgeable) found.get(i)).isChild() || (!child && !((EntityAgeable) found.get(i)).isChild()))))
if (found.get(i) != null && !(found.get(i) instanceof EntityArrow) && found.get(i).ridingEntity == null && (!(found.get(i) instanceof EntityAgeable) || (found.get(i) instanceof EntityAgeable && child != ((EntityAgeable) found.get(i)).isChild())))
{
this.tileEntity.grabEntity(found.get(i));
this.world.playSound(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord, "random.pop", 0.2F, ((this.tileEntity.worldObj.rand.nextFloat() - this.tileEntity.worldObj.rand.nextFloat()) * 0.7F + 1.0F) * 1.0F, true);
return false;
}
}
@ -83,9 +85,36 @@ public class CommandGrab extends Command
return true;
}
@Override
public void readFromNBT(NBTTagCompound taskCompound)
{
super.readFromNBT(taskCompound);
this.child = taskCompound.getBoolean("child");
this.entityToInclude = GrabDictionary.get(taskCompound.getString("name")).getEntityClass();
}
@Override
public void writeToNBT(NBTTagCompound taskCompound)
{
super.writeToNBT(taskCompound);
taskCompound.setBoolean("child", child);
taskCompound.setString("name", ((this.entityToInclude != null) ? GrabDictionary.get(this.entityToInclude).getName() : ""));
}
@Override
public String toString()
{
return "GRAB";
String baby = "";
String entity = "";
if (this.entityToInclude != null)
{
entity = GrabDictionary.get(this.entityToInclude).getName();
if (this.child)
{
// TODO do check for EntityAgable
baby = "baby ";
}
}
return "GRAB " + baby + entity;
}
}

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySkeleton;
@ -35,11 +36,23 @@ public class GrabDictionary
return grabList;
}
public static GrabDictionary get(String name)
public static GrabDictionary get(Object ob)
{
for (GrabDictionary ref : grabList)
if (ob instanceof String)
{
if (ref.getName().equalsIgnoreCase(name)) { return ref; }
String name = (String) ob;
for (GrabDictionary ref : grabList)
{
if (ref.getName().equalsIgnoreCase(name)) { return ref; }
}
}
if(ob instanceof Class)
{
Class<? extends Entity> cc = (Class<? extends Entity>) ob;
for (GrabDictionary ref : grabList)
{
if (ref.getEntityClass() == cc) { return ref; }
}
}
return new GrabDictionary("Entity", Entity.class);
}
@ -99,5 +112,8 @@ public class GrabDictionary
registerGrabableEntity("creeper", EntityCreeper.class);
registerGrabableEntity("spider", EntitySpider.class);
registerGrabableEntity("slime", EntitySlime.class);
registerGrabableEntity("items", EntityItem.class);
registerGrabableEntity("all", Entity.class);
registerGrabableEntity("everything", Entity.class);
}
}