diff --git a/src/minecraft/assemblyline/common/machine/command/CommandGrab.java b/src/minecraft/assemblyline/common/machine/command/CommandGrab.java index b044e61af..bdc399012 100644 --- a/src/minecraft/assemblyline/common/machine/command/CommandGrab.java +++ b/src/minecraft/assemblyline/common/machine/command/CommandGrab.java @@ -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 diff --git a/src/minecraft/assemblyline/common/machine/command/GrabDictionary.java b/src/minecraft/assemblyline/common/machine/command/GrabDictionary.java new file mode 100644 index 000000000..ce2896008 --- /dev/null +++ b/src/minecraft/assemblyline/common/machine/command/GrabDictionary.java @@ -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 grabList = new ArrayList(); + private Class entityClass; + private String name; + + public GrabDictionary(String name, Class Class) + { + this.entityClass = Class; + this.name = name; + } + + public static List 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 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 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); + } +}