use of com.microsoft.Malmo.Schemas.DrawItem in project malmo by Microsoft.
the class MinecraftTypeHelper method getItemStackFromParameterString.
/** Take a string of parameters, delimited by spaces, and create an ItemStack from it.
* @param parameters the item name, variation, colour etc of the required item, separated by spaces.
* @return an Itemstack for these parameters, or null if unrecognised.
*/
public static ItemStack getItemStackFromParameterString(String parameters) {
// Split into parameters:
List<String> params = new ArrayList<String>(Arrays.asList(parameters.split(" ")));
Colour col = null;
Variation var = null;
// See if any parameters appear to be a colour:
Iterator<String> it = params.iterator();
while (it.hasNext() && col == null) {
col = MinecraftTypeHelper.attemptToGetAsColour(it.next());
if (col != null)
// This parameter was a colour - we've parsed it, so remove it.
it.remove();
}
// See if any parameters appear to be a variant:
it = params.iterator();
while (it.hasNext() && var == null) {
var = MinecraftTypeHelper.attemptToGetAsVariant(it.next());
if (var != null)
// This parameter was a variant - we've parsed it, so remove it.
it.remove();
}
// Hopefully we have at most one parameter left, which will be the type.
if (params.size() == 0)
// Dunno what to do, really.
return null;
String itemName = params.get(0);
DrawItem di = new DrawItem();
di.setColour(col);
di.setVariant(var);
di.setType(itemName);
return getItemStackFromDrawItem(di);
}
use of com.microsoft.Malmo.Schemas.DrawItem in project malmo by Microsoft.
the class MinecraftTypeHelper method getItemStackFromDrawItem.
public static ItemStack getItemStackFromDrawItem(DrawItem i) {
ItemStack itemStack = null;
// First see if this is an item:
Item item = MinecraftTypeHelper.ParseItemType(i.getType(), false);
if (item == null) {
// No, so is it a block type?
IBlockState block = MinecraftTypeHelper.ParseBlockType(i.getType());
if (block != null) {
// It is - apply the modifications:
block = BlockDrawingHelper.applyModifications(block, i.getColour(), i.getFace(), i.getVariant());
// And try to return as an item:
if (block != null && block.getBlock() != null && Item.getItemFromBlock(block.getBlock()) != null) {
itemStack = new ItemStack(block.getBlock(), 1, block.getBlock().getMetaFromState(block));
}
}
} else {
if (item.getHasSubtypes() && (i.getColour() != null || i.getVariant() != null)) {
// Attempt to find the subtype for this colour/variant - made tricky
// because Items don't provide any nice property stuff like Blocks do...
List<ItemStack> subItems = new ArrayList<ItemStack>();
item.getSubItems(item, null, subItems);
for (ItemStack is : subItems) {
String fullName = is.getUnlocalizedName();
if (is.getItem() instanceof ItemMonsterPlacer) {
// Special handling for eggs
fullName += "." + ItemMonsterPlacer.getEntityName(is);
}
String[] parts = fullName.split("\\.");
for (int p = 0; p < parts.length; p++) {
Variation v = attemptToGetAsVariant(parts[p], is);
Colour c = attemptToGetAsColour(parts[p]);
if ((v != null && i.getVariant() != null && v.getValue().equals(i.getVariant().getValue())) || (c != null && i.getColour() != null && c == i.getColour())) {
// This is it??
return is;
}
}
System.out.println(parts);
}
}
itemStack = new ItemStack(item);
}
return itemStack;
}
Aggregations