use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.
the class SnakeDecoratorImplementation method getBlock.
private IBlockState getBlock(SnakeBlock sblock, Random rand) {
String blockName = chooseBlock(sblock.getType(), rand);
Colour blockCol = chooseColour(sblock.getColour(), rand);
Variation blockVar = chooseVariant(sblock.getVariant(), rand);
return BlockDrawingHelper.applyModifications(MinecraftTypeHelper.ParseBlockType(blockName), blockCol, null, blockVar);
}
use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.
the class MazeDecoratorImplementation method getBlock.
private XMLBlockState getBlock(MazeBlock mblock, Random rand) {
BlockType blockName = chooseBlock(mblock.getType(), rand);
Colour blockCol = chooseColour(mblock.getColour(), rand);
Variation blockVar = chooseVariant(mblock.getVariant(), rand);
return new XMLBlockState(blockName, blockCol, null, blockVar);
}
use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.
the class MinecraftTypeHelper method getDrawItemFromItemStack.
/** Attempt to break the item on this itemstack into a type/variant/colour which we can use for communication with the Malmo platform.
* @param is the ItemStack containing the item we are attempting to deconstruct.
* @return an XML DrawItem object containing the item's type, variant, colour etc.
*/
public static DrawItem getDrawItemFromItemStack(ItemStack is) {
if (is == null)
return null;
DrawItem di = new DrawItem();
// Get unlocalised name from the stack, not the stack's item - this ensures we keep the metadata.
String name = is.getUnlocalizedName();
if (is.getHasSubtypes()) {
// If the item has subtypes, then there are varieties - eg different colours, types, etc.
// Attempt to map from these subtypes back to variant/colour.
// Do this by decomposing the unlocalised name:
List<String> itemParts = new ArrayList<String>(Arrays.asList(name.split("\\.")));
if (is.getItem() instanceof ItemMonsterPlacer) {
// Special case for eggs:
itemParts.add(ItemMonsterPlacer.getEntityName(is));
}
// First part will be "tile" or "item".
// Second part will be the item itself (eg "dyePowder" or "stainedGlass" etc).
// Third part will be the variant, colour etc.
Colour col = null;
Variation var = null;
for (int part = 2; part < itemParts.size(); part++) {
String section = itemParts.get(part);
// First see if this matches a colour:
if (col == null) {
col = attemptToGetAsColour(section);
if (// If it wasn't a colour, check to see if it was a variant:
col == null && var == null)
var = attemptToGetAsVariant(section, is);
} else if (var == null)
var = attemptToGetAsVariant(section, is);
}
di.setColour(col);
di.setVariant(var);
}
// Use the item registry name for the item - this is what we use in Types.XSD
Object obj = Item.itemRegistry.getNameForObject(is.getItem());
String publicName;
if (obj instanceof ResourceLocation)
publicName = ((ResourceLocation) obj).getResourcePath();
else
publicName = obj.toString();
di.setType(publicName);
return di;
}
use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.
the class MinecraftTypeHelper method getDrawBlockFromBlockState.
/** Extract the type, variation and facing attributes of a blockstate and return them in a new DrawBlock object.<br>
* @param state the IBlockState to be examined
* @return A DrawBlock object
*/
public static DrawBlock getDrawBlockFromBlockState(IBlockState state, List<IProperty> extraProperties) {
if (state == null)
return null;
DrawBlock block = new DrawBlock();
Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
if (blockName instanceof ResourceLocation) {
String name = ((ResourceLocation) blockName).getResourcePath();
BlockType type = BlockType.fromValue(name);
block.setType(type);
}
Colour col = null;
Variation var = null;
Facing face = null;
// Add properties:
for (IProperty prop : (java.util.Set<IProperty>) state.getProperties().keySet()) {
String propVal = state.getValue(prop).toString();
boolean matched = false;
// Try colour first:
if (col == null) {
col = attemptToGetAsColour(propVal);
if (col != null)
matched = true;
}
// Then variant:
if (!matched && var == null) {
var = attemptToGetAsVariant(propVal);
if (var != null)
matched = true;
}
// Then facing:
if (!matched && face == null) {
face = attemptToGetAsFacing(propVal);
if (face != null)
matched = true;
}
if (!matched) {
if (extraProperties != null)
extraProperties.add(prop);
}
}
if (col != null)
block.setColour(col);
if (var != null)
block.setVariant(var);
if (face != null)
block.setFace(face);
return block;
}
use of com.microsoft.Malmo.Schemas.Variation in project malmo by Microsoft.
the class MovingTargetDecoratorImplementation method isValid.
private boolean isValid(World world, BlockPos pos) {
// In bounds?
if (!blockInBounds(pos, this.arenaBounds))
return false;
// Already in path?
if (this.path.contains(pos))
return false;
// Does there need to be air above the target?
if (this.targetParams.isRequiresAirAbove() && !world.isAirBlock(pos.up()))
return false;
// Check the current block is "permeable"...
IBlockState block = world.getBlockState(pos);
List<IProperty> extraProperties = new ArrayList<IProperty>();
DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(block, extraProperties);
boolean typesMatch = this.targetParams.getPermeableBlocks().getType().isEmpty();
for (BlockType bt : this.targetParams.getPermeableBlocks().getType()) {
if (db.getType() == bt) {
typesMatch = true;
break;
}
}
if (!typesMatch)
return false;
if (db.getColour() != null) {
boolean coloursMatch = this.targetParams.getPermeableBlocks().getColour().isEmpty();
for (Colour col : this.targetParams.getPermeableBlocks().getColour()) {
if (db.getColour() == col) {
coloursMatch = true;
break;
}
}
if (!coloursMatch)
return false;
}
if (db.getVariant() != null) {
boolean variantsMatch = this.targetParams.getPermeableBlocks().getVariant().isEmpty();
for (Variation var : this.targetParams.getPermeableBlocks().getVariant()) {
if (db.getVariant() == var) {
variantsMatch = true;
break;
}
}
if (!variantsMatch)
return false;
}
return true;
}
Aggregations