improving grab command

Adding support to the command to specify what entity that it should
grab, as well as a way to register more Entities by name for the grab
command
This commit is contained in:
Rseifert 2013-02-12 23:24:45 -05:00
parent c6e07dfc5a
commit 44d59abac5
2 changed files with 117 additions and 2 deletions

View file

@ -1,8 +1,11 @@
package assemblyline.common.machine.command;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.util.AxisAlignedBB;
@ -16,8 +19,13 @@ import universalelectricity.core.vector.Vector3;
public class CommandGrab extends Command
{
public static final float radius = 0.5f;
public static final float radius = 0.5f;
/**
* If the grab command is specific to one entity this tell whether or not to grab the child version of that entity.
*/
public boolean child;
/**
* The item to be collected.
*/
@ -26,7 +34,34 @@ public class CommandGrab extends Command
public CommandGrab()
{
super();
this.entityToInclude = Entity.class;
// TODO convert these predefined words to the minecraft translater
this.entityToInclude = EntityItem.class;
String firstWord = this.getArg(0);
String secondWord = this.getArg(1);
// find if grabbing the baby version of an Entity
if (firstWord != null && firstWord.equalsIgnoreCase("baby"))
{
child = true;
firstWord = secondWord;
}
else if (firstWord != null && firstWord.equalsIgnoreCase("baby"))
{
child = true;
}
else
{
child = false;
}
// find if we are grabing something else than an EntityItem
if (firstWord != null)
{
if (firstWord.equalsIgnoreCase("chicken"))
{
this.entityToInclude = EntityChicken.class;
}
}
}
@Override

View file

@ -0,0 +1,80 @@
package assemblyline.common.machine.command;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.EntityChicken;
public class GrabDictionary
{
private static List<GrabDictionary> grabList = new ArrayList<GrabDictionary>();
private Class<? extends Entity> entityClass;
private String name;
public GrabDictionary(String name, Class<? extends Entity> Class)
{
this.entityClass = Class;
this.name = name;
}
public static List<GrabDictionary> getList()
{
return grabList;
}
public static GrabDictionary get(String name)
{
for (GrabDictionary ref : grabList)
{
if (ref.getName().equalsIgnoreCase(name)) { return ref; }
}
return new GrabDictionary("Entity", Entity.class);
}
/**
* gets the name of the Entity
*
* @return "" if null
*/
public String getName()
{
if (name != null)
return this.name;
return "";
}
/**
* gets the Entity Class
*
* @return Entity.class if null
*/
public Class<? extends Entity> getEntityClass()
{
if (this.entityClass != null)
return this.entityClass;
return Entity.class;
}
/**
* registers an entity by a name to its class allowing it to be
* called by the grab command to be picked up
*/
public static void registerGrabableEntity(String name, Class<? extends Entity> eClass)
{
GrabDictionary newGrab = new GrabDictionary(name, eClass);
if (!GrabDictionary.grabList.contains(newGrab))
{
for (GrabDictionary ref : grabList)
{
if (ref.getName().equalsIgnoreCase(name)) { return; }
}
GrabDictionary.getList().add(newGrab);
}
}
public static void registerList()
{
registerGrabableEntity("chicken", EntityChicken.class);
}
}