Search in sources :

Example 21 with IProperty

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);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) BlockPos(net.minecraft.util.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 22 with IProperty

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);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ItemBlock(net.minecraft.item.ItemBlock) Variation(com.microsoft.Malmo.Schemas.Variation)

Example 23 with IProperty

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;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) BlockType(com.microsoft.Malmo.Schemas.BlockType) ArrayList(java.util.ArrayList) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 24 with IProperty

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.
            }
        }
    }
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ShapeTypes(com.microsoft.Malmo.Schemas.ShapeTypes) NoteTypes(com.microsoft.Malmo.Schemas.NoteTypes) BlockRailBase(net.minecraft.block.BlockRailBase) TileEntity(net.minecraft.tileentity.TileEntity) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityNote(net.minecraft.tileentity.TileEntityNote) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Example 25 with IProperty

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();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PropertyDirection(net.minecraft.block.properties.PropertyDirection) JsonObject(com.google.gson.JsonObject) Material(net.minecraft.block.material.Material) CreativeTabs(net.minecraft.creativetab.CreativeTabs) PropertyEnum(net.minecraft.block.properties.PropertyEnum) ItemBlock(net.minecraft.item.ItemBlock) BufferedWriter(java.io.BufferedWriter) JsonArray(com.google.gson.JsonArray) Item(net.minecraft.item.Item) IProperty(net.minecraft.block.properties.IProperty) FileOutputStream(java.io.FileOutputStream) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) OutputStreamWriter(java.io.OutputStreamWriter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)29 IBlockState (net.minecraft.block.state.IBlockState)19 ItemStack (net.minecraft.item.ItemStack)8 Block (net.minecraft.block.Block)7 ResourceLocation (net.minecraft.util.ResourceLocation)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)5 TileEntity (net.minecraft.tileentity.TileEntity)5 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)4 JsonObject (com.google.gson.JsonObject)3 Variation (com.microsoft.Malmo.Schemas.Variation)3 ItemBlock (net.minecraft.item.ItemBlock)3 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)2 StateValue (com.almuradev.content.type.block.state.value.StateValue)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BlockType (com.microsoft.Malmo.Schemas.BlockType)2 Colour (com.microsoft.Malmo.Schemas.Colour)2 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2