use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.
the class ItemBlockReinforcedWoodSlabs method canPlaceBlockOnSide.
@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
BlockPos blockpos1 = pos;
IProperty iproperty = singleSlab.getVariantProperty();
Object object = singleSlab.getVariant(stack);
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == singleSlab) {
boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty))
return true;
}
pos = pos.offset(side);
IBlockState iblockstate1 = worldIn.getBlockState(pos);
return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class MinecraftTypeHelper method attemptToGetAsVariant.
/**
* Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br>
* (eg blue_orchid vs orchidBlue etc.)
* @param part the string (potentially in the 'wrong' format, eg 'orchidBlue')
* @param is the ItemStack from which this string came (eg from is.getUnlocalisedName)
* @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values.
*/
public static Variation attemptToGetAsVariant(String part, ItemStack is) {
if (is.getItem() instanceof ItemBlock) {
// Unlocalised name doesn't always match the names we use in types.xsd
// (which are the names displayed by Minecraft when using the F3 debug etc.)
ItemBlock ib = (ItemBlock) (is.getItem());
IBlockState bs = ib.block.getStateFromMeta(is.getMetadata());
for (IProperty prop : bs.getProperties().keySet()) {
Comparable<?> comp = bs.getValue(prop);
Variation var = attemptToGetAsVariant(comp.toString());
if (var != null)
return var;
}
return null;
} else
return attemptToGetAsVariant(part);
}
use of net.minecraft.block.properties.IProperty 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;
}
use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class BlockDrawingHelper method setBlockState.
public void setBlockState(World w, BlockPos pos, XMLBlockState state) {
if (!state.isValid())
return;
// Do some depressingly necessary specific stuff here for different block types:
if (state.getBlock() instanceof BlockRailBase && state.variant != null) {
// Caller has specified a variant - is it a shape variant?
try {
ShapeTypes shape = ShapeTypes.fromValue(state.variant.getValue());
if (shape != null) {
// Yes, user has requested a particular shape.
// Minecraft won't honour this - and, worse, it may get altered by neighbouring pieces that are added later.
// So we don't bother trying to get this right now - we add it as a state check, and set it correctly
// after drawing has finished.
StateCheck sc = new StateCheck();
sc.pos = pos;
sc.desiredState = state.state;
sc.propertiesToCheck = new ArrayList<IProperty>();
sc.propertiesToCheck.add(((BlockRailBase) state.getBlock()).getShapeProperty());
this.checkList.add(sc);
}
} catch (IllegalArgumentException e) {
// Wasn't a shape variation. Ignore.
}
}
// Actually set the block state into the world:
w.setBlockState(pos, state.state);
// And now do the necessary post-placement processing:
if (state.type == BlockType.MOB_SPAWNER) {
TileEntity te = w.getTileEntity(pos);
if (// Ought to be!
te != null && te instanceof TileEntityMobSpawner) {
// Attempt to use the variation to control what type of mob this spawns:
try {
EntityTypes entvar = EntityTypes.fromValue(state.variant.getValue());
((TileEntityMobSpawner) te).getSpawnerBaseLogic().setEntityId(new ResourceLocation(entvar.value()));
} catch (Exception e) {
// Do nothing - user has requested a non-entity variant.
}
}
}
if (state.type == BlockType.NOTEBLOCK) {
TileEntity te = w.getTileEntity(pos);
if (te != null && te instanceof TileEntityNote && state.variant != null) {
try {
NoteTypes note = NoteTypes.fromValue(state.variant.getValue());
if (note != null) {
// User has requested a particular note.
((TileEntityNote) te).note = (byte) note.ordinal();
}
} catch (IllegalArgumentException e) {
// Wasn't a note variation. Ignore.
}
}
}
}
use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class CraftingHelper method dumpItemProperties.
/**
* Little utility method for dumping out a list of all the Minecraft items, plus as many useful attributes as
* we can find for them. This is primarily used by decision_tree_test.py but might be useful for real-world applications too.
* @param filename location to save the dumped list.
* @throws IOException
*/
public static void dumpItemProperties(String filename) throws IOException {
FileOutputStream fos = new FileOutputStream("..//..//build//install//Python_Examples//item_database.json");
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter writer = new BufferedWriter(osw);
JsonArray itemTypes = new JsonArray();
for (ResourceLocation i : Item.REGISTRY.getKeys()) {
Item item = Item.REGISTRY.getObject(i);
if (item != null) {
JsonObject json = new JsonObject();
json.addProperty("type", Item.REGISTRY.getNameForObject(item).toString().replace("minecraft:", ""));
json.addProperty("damageable", item.isDamageable());
json.addProperty("rendersIn3D", item.isFull3D());
json.addProperty("repairable", item.isRepairable());
CreativeTabs tab = item.getCreativeTab();
json.addProperty("tab", ((tab != null) ? item.getCreativeTab().getTabLabel() : "none"));
ItemStack is = item.getDefaultInstance();
json.addProperty("stackable", is.isStackable());
json.addProperty("enchantable", is.isItemEnchantable());
// Enum has four types, but only two (COMMON and RARE) appear to be used.
json.addProperty("rare", (is.getRarity() == EnumRarity.RARE));
json.addProperty("action", is.getItemUseAction().toString());
json.addProperty("hasSubtypes", item.getHasSubtypes());
json.addProperty("maxDamage", is.getMaxDamage());
json.addProperty("maxUseDuration", is.getMaxItemUseDuration());
json.addProperty("block", item instanceof ItemBlock);
json.addProperty("hasContainerItem", item.hasContainerItem());
if (item instanceof ItemBlock) {
ItemBlock ib = (ItemBlock) item;
Block b = ib.getBlock();
IBlockState bs = b.getDefaultState();
json.addProperty("slipperiness", b.slipperiness);
json.addProperty("hardness", bs.getBlockHardness(null, null));
json.addProperty("causesSuffocation", bs.causesSuffocation());
json.addProperty("canProvidePower", bs.canProvidePower());
json.addProperty("translucent", bs.isTranslucent());
Material mat = bs.getMaterial();
if (mat != null) {
json.addProperty("canBurn", mat.getCanBurn());
json.addProperty("isLiquid", mat.isLiquid());
json.addProperty("blocksMovement", mat.blocksMovement());
json.addProperty("needsNoTool", mat.isToolNotRequired());
json.addProperty("isReplaceable", mat.isReplaceable());
json.addProperty("pistonPushable", mat.getMobilityFlag() == EnumPushReaction.NORMAL);
json.addProperty("woodenMaterial", mat == Material.WOOD);
json.addProperty("ironMaterial", mat == Material.IRON);
json.addProperty("glassyMaterial", mat == Material.GLASS);
json.addProperty("clothMaterial", mat == Material.CLOTH);
}
boolean hasDirection = false;
boolean hasColour = false;
boolean hasVariant = false;
for (IProperty prop : bs.getProperties().keySet()) {
System.out.println(Item.REGISTRY.getNameForObject(item).toString() + " -- " + prop);
if (prop instanceof PropertyDirection)
hasDirection = true;
if (prop instanceof PropertyEnum && prop.getName().equals("color"))
hasColour = true;
if (prop instanceof PropertyEnum && prop.getName().equals("variant")) {
hasVariant = true;
json.addProperty("variant", bs.getValue(prop).toString());
}
}
json.addProperty("hasDirection", hasDirection);
json.addProperty("hasColour", hasColour);
json.addProperty("hasVariant", hasVariant);
}
itemTypes.add(json);
}
}
writer.write(itemTypes.toString());
writer.close();
}
Aggregations