net.minecraft.block.properties.IProperty Java Examples

The following examples show how to use net.minecraft.block.properties.IProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockRelay.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
public IProperty<Boolean> getProperty(EnumFacing facing) {
	switch (facing) {
		case EAST:
			return EAST;
		case WEST:
			return WEST;
		case NORTH:
			return NORTH;
		case SOUTH:
			return SOUTH;
		case UP:
			return UP;
		case DOWN:
			return DOWN;
		default:
			return EAST;
	}
}
 
Example #2
Source File: MinecraftTypeHelper.java    From malmo with MIT License 6 votes vote down vote up
/** Test whether this block has a colour attribute which matches the list of allowed colours
 * @param bs blockstate to test
 * @param allowedColours list of allowed Colour enum values
 * @return true if the block matches.
 */
public static boolean blockColourMatches(IBlockState bs, List<Colour> allowedColours)
{
    for (IProperty prop : bs.getProperties().keySet())
    {
        if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class)
        {
            // The block in question has a colour, so check it is a specified one:
            net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)bs.getValue(prop);
            for (Colour col : allowedColours)
            {
                if (current.getName().equalsIgnoreCase(col.name()))
                    return true;
            }
        }
    } 
    return false;
}
 
Example #3
Source File: BlockUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static <T extends Comparable<T>> List<IBlockState> getFilteredStates(Collection<IBlockState> initialStates, String propName, String propValue)
{
    List<IBlockState> list = new ArrayList<>();

    for (IBlockState state : initialStates)
    {
        @SuppressWarnings("unchecked")
        IProperty<T> prop = (IProperty<T>) state.getBlock().getBlockState().getProperty(propName);

        if (prop != null)
        {
            Optional<T> value = prop.parseValue(propValue);

            if (value.isPresent() && state.getValue(prop).equals(value.get()))
            {
                list.add(state);
            }
        }
    }

    return list;
}
 
Example #4
Source File: MinecraftTypeHelper.java    From malmo with MIT License 6 votes vote down vote up
/** Test whether this block has a variant attribute which matches the list of allowed variants
 * @param bs the blockstate to test
 * @param allowedVariants list of allowed Variant enum values
 * @return true if the block matches.
 */
public static boolean blockVariantMatches(IBlockState bs, List<Variation> allowedVariants)
{
    for (IProperty prop : bs.getProperties().keySet())
    {
        if (prop.getName().equals("variant") && prop.getValueClass().isEnum())
        {
            Object current = bs.getValue(prop);
            if (current != null)
            {
                for (Variation var : allowedVariants)
                {
                    if (var.getValue().equalsIgnoreCase(current.toString()))
                        return true;
                }
            }
        }
    }
    return false;
}
 
Example #5
Source File: NumericalBlockState.java    From VanillaFix with MIT License 6 votes vote down vote up
public static <T extends Comparable<T>> void makePropertyInfo(IProperty<T> property) {
    if (propertyWidths.containsKey(property)) {
        return;
    }

    Collection<T> allowedValues = property.getAllowedValues();

    // Calculate width of the property's number in the bit field
    propertyWidths.put(property, MathHelper.log2(allowedValues.size()) + 1);

    // Fill the 'number -> value' and 'value -> number' maps
    int i = 0;
    for (T value : allowedValues) {
        numberToValue.put(new Pair<>(property, i), value);
        valueToNumber.put(new Pair<>(property, value), i);
        i++;
    }
}
 
Example #6
Source File: BlockFarmland.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/

@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[] { META_PROPERTY });
}
 
Example #7
Source File: BlockFirepit.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/


@Override
protected BlockStateContainer createBlockState()
{
	return new ExtendedBlockState(this, new IProperty[]{LIT, TOOL}, new IUnlistedProperty[]{});
}
 
Example #8
Source File: BlockCropsTest.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testProperties()
{
    ContentBlockCrops content = new ContentBlockCrops();
    content.id = "test_properties";
    content.maxAge = 9;

    Block block = content.createBlock();
    Collection<IProperty<?>> properties = block.getBlockState().getProperties();
    assertEquals(1, properties.size());
    assertSame(properties.iterator().next(), BlockHelper.getCropAgeProperty(9));
}
 
Example #9
Source File: BlockSand.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/

@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[]{META_PROPERTY});
}
 
Example #10
Source File: MixinBlockStateContainer.java    From VanillaFix with MIT License 5 votes vote down vote up
@Overwrite(remap = false)
protected BlockStateContainer.StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties) {
    if (!isNumerical) {
        return new BlockStateContainer.StateImplementation(block, properties);
    }

    return null;
}
 
Example #11
Source File: BlockLeaves2.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/

@Override
protected BlockStateContainer createBlockState()
{
	return new ExtendedBlockState(this, new IProperty[]{META_PROPERTY, BlockLeaves.FANCY}, new IUnlistedProperty[]{ B3DLoader.B3DFrameProperty.INSTANCE });
}
 
Example #12
Source File: NumericalExtendedBlockState.java    From VanillaFix with MIT License 5 votes vote down vote up
@Override
public <T extends Comparable<T>, V extends T> IBlockState withProperty(IProperty<T> property, V value) {
    IBlockState clean = normalState.withProperty(property, value);
    if (clean == normalState) {
        return this;
    }

    if (this == cleanState) { // no dynamic properties present, looking up in the normal table
        return getClean(clean, unlistedProperties);
    }

    return new NumericalExtendedBlockState(clean, unlistedProperties, cleanState);
}
 
Example #13
Source File: BlockBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected BlockStateContainer createBlockState()
{
    return new ExtendedBlockState(this, new IProperty[] { FACING_H, CREATIVE,
            LABEL_UP, LABEL_DOWN, LABEL_FRONT, LABEL_BACK, LABEL_LEFT, LABEL_RIGHT },
            new IUnlistedProperty<?>[] { CAMOBLOCKSTATE, CAMOBLOCKSTATEEXTENDED });
}
 
Example #14
Source File: BlockPlanks.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/

@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[]{META_PROPERTY});
}
 
Example #15
Source File: MixinExtendedBlockState.java    From VanillaFix with MIT License 5 votes vote down vote up
@Override
protected IBlockState createState(ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties) {
    if (getClass() != MixinExtendedBlockState.class) {
        return createState(getBlock(), properties, unlistedProperties);
    }

    IBlockState normalState = super.createState(properties, unlistedProperties);
    if (unlistedProperties == null || unlistedProperties.isEmpty()) {
        return normalState;
    }

    return NumericalExtendedBlockState.getClean(normalState, unlistedProperties);
}
 
Example #16
Source File: NumericalBlockState.java    From VanillaFix with MIT License 5 votes vote down vote up
@Override
public ImmutableMap<IProperty<?>, Comparable<?>> getProperties() {
    ImmutableMap.Builder<IProperty<?>, Comparable<?>> properties = ImmutableMap.builder();

    for (IProperty<?> property : container.getProperties()) {
        properties.put(property, getValue(property));
    }

    return properties.build();
}
 
Example #17
Source File: BlockGravel.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/*******************************************************************************
 * 3. Blockstate 
 *******************************************************************************/

@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[]{META_PROPERTY});
}
 
Example #18
Source File: BlockTorchTest.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testProperties()
{
    ContentBlockTorch content = new ContentBlockTorch();
    content.id = "test_getSubtype";

    Block block = content.createBlock();
    Collection<IProperty<?>> properties = block.getBlockState().getProperties();
    assertEquals(1, properties.size());
}
 
Example #19
Source File: Scrubber.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public ExtendedBlockState createBlockState() {
    return new ExtendedBlockState(this, new IProperty[] { FACING, Properties.StaticProperty }, new IUnlistedProperty[]{ Properties.AnimationProperty });
}
 
Example #20
Source File: BlockSlab.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IProperty<?>[] getProperties()
{
    return new IProperty[] {HALF};
}
 
Example #21
Source File: Collector.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] { HAS_ITEMS });
}
 
Example #22
Source File: Harvester.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public ExtendedBlockState createBlockState() {
    return new ExtendedBlockState(this, new IProperty[] { FACING, Properties.StaticProperty },
            new IUnlistedProperty[] { Properties.AnimationProperty });
}
 
Example #23
Source File: BlockStairsTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[] { BlockStairs.FACING, BlockStairs.HALF, BlockStairs.SHAPE });
}
 
Example #24
Source File: BlockFuelTank.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
protected BlockStateContainer createBlockState() {
	return new BlockStateContainer(this, new IProperty[]{TANKSTATES});
}
 
Example #25
Source File: NumericalBlockState.java    From VanillaFix with MIT License 4 votes vote down vote up
@Override
public Collection<IProperty<?>> getPropertyKeys() {
    return container.getProperties();
}
 
Example #26
Source File: BlockComponentBox.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[] {FACING});
}
 
Example #27
Source File: NumericalExtendedBlockState.java    From VanillaFix with MIT License 4 votes vote down vote up
@Override
public <T extends Comparable<T>> T getValue(IProperty<T> property) {
    return normalState.getValue(property);
}
 
Example #28
Source File: BiomassGenerator.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
protected BlockStateContainer createBlockState() {
    return new BlockStateContainer(this, new IProperty[] { FACING });
}
 
Example #29
Source File: BlockLogNatural2.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected BlockStateContainer createBlockState()
{
	return new BlockStateContainer(this, new IProperty[]{WOOD});
}
 
Example #30
Source File: Wind.java    From EmergingTechnology with MIT License 4 votes vote down vote up
@Override
public ExtendedBlockState createBlockState() {
    return new ExtendedBlockState(this, new IProperty[] { FACING, Properties.StaticProperty }, new IUnlistedProperty[]{ Properties.AnimationProperty });
}