Search in sources :

Example 31 with IProperty

use of net.minecraft.block.properties.IProperty in project Immersive-Tech by FerroO2000.

the class BlockMetalDevice method createBlockState.

@Override
protected BlockStateContainer createBlockState() {
    BlockStateContainer base = super.createBlockState();
    IUnlistedProperty[] unlisted = (base instanceof ExtendedBlockState) ? ((ExtendedBlockState) base).getUnlistedProperties().toArray(new IUnlistedProperty[0]) : new IUnlistedProperty[0];
    unlisted = Arrays.copyOf(unlisted, unlisted.length + 1);
    unlisted[unlisted.length - 1] = IEProperties.CONNECTIONS;
    return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted);
}
Also used : IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) IProperty(net.minecraft.block.properties.IProperty) ExtendedBlockState(net.minecraftforge.common.property.ExtendedBlockState) BlockStateContainer(net.minecraft.block.state.BlockStateContainer)

Example 32 with IProperty

use of net.minecraft.block.properties.IProperty in project BloodMagic by WayofTime.

the class BloodMagicCorePlugin method parseState.

private static IBlockState parseState(String blockInfo) {
    String[] split = blockInfo.split("\\[");
    // Make sure brackets are removed from state
    split[1] = split[1].substring(0, split[1].lastIndexOf("]"));
    // Find the block
    Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0]));
    if (block == Blocks.AIR)
        // The block is air, so we're looking at invalid data
        return Blocks.AIR.getDefaultState();
    BlockStateContainer blockState = block.getBlockState();
    IBlockState returnState = blockState.getBaseState();
    // Force our values into the state
    // Splits up each value
    String[] stateValues = split[1].split(",");
    for (String value : stateValues) {
        // Separates property and value
        String[] valueSplit = value.split("=");
        IProperty property = blockState.getProperty(valueSplit[0]);
        if (property != null)
            // Force the property into the state
            returnState = returnState.withProperty(property, (Comparable) property.parseValue(valueSplit[1]).get());
    }
    return returnState;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) BlockStateContainer(net.minecraft.block.state.BlockStateContainer)

Example 33 with IProperty

use of net.minecraft.block.properties.IProperty in project MC-Prefab by Brian-Wuest.

the class BuildBlock method SetBlockState.

public static BuildBlock SetBlockState(StructureConfiguration configuration, World world, BlockPos originalPos, EnumFacing assumedNorth, BuildBlock block, Block foundBlock, IBlockState blockState, Structure structure) {
    try {
        if (!block.blockStateData.equals("")) {
            return BuildBlock.SetBlockStateFromTagData(configuration, world, originalPos, assumedNorth, block, foundBlock, blockState, structure);
        }
        EnumFacing vineFacing = BuildBlock.getVineFacing(configuration, foundBlock, block, structure.getClearSpace().getShape().getDirection());
        EnumAxis logFacing = BuildBlock.getLogFacing(configuration, foundBlock, block, structure.getClearSpace().getShape().getDirection());
        Axis boneFacing = BuildBlock.getBoneFacing(configuration, foundBlock, block, structure.getClearSpace().getShape().getDirection());
        BlockQuartz.EnumType quartzFacing = BuildBlock.getQuartsFacing(configuration, foundBlock, block, structure.getClearSpace().getShape().getDirection());
        EnumOrientation leverOrientation = BuildBlock.getLeverOrientation(configuration, foundBlock, block, structure.getClearSpace().getShape().getDirection());
        // If this block has custom processing for block state just continue onto the next block. The sub-class is expected to place the block.
        if (block.getProperties().size() > 0) {
            Collection<IProperty<?>> properties = blockState.getPropertyKeys();
            // applied.
            for (IProperty<?> property : properties) {
                BuildProperty buildProperty = block.getProperty(property.getName());
                // Make sure that this property exists in our file. The only way it wouldn't be there would be if a mod adds properties to vanilla blocks.
                if (buildProperty != null) {
                    try {
                        Optional<?> propertyValue = property.parseValue(buildProperty.getValue());
                        if (!propertyValue.isPresent() || propertyValue.getClass().getName().equals("com.google.common.base.Absent")) {
                            FMLLog.log.warn("Property value for property name [" + property.getName() + "] for block [" + block.getBlockName() + "] is considered Absent, figure out why.");
                            continue;
                        }
                        Comparable<?> comparable = property.getValueClass().cast(propertyValue.get());
                        if (comparable == null) {
                            continue;
                        }
                        comparable = BuildBlock.setComparable(comparable, foundBlock, property, configuration, block, assumedNorth, propertyValue, vineFacing, logFacing, boneFacing, quartzFacing, leverOrientation, structure);
                        if (comparable == null) {
                            continue;
                        }
                        try {
                            if (blockState.getValue(property) != comparable) {
                                blockState = BuildBlock.setProperty(blockState, property, comparable);
                            }
                        } catch (Exception ex) {
                            System.out.println("Error setting properly value for property name [" + property.getName() + "] property value [" + buildProperty.getValue() + "] for block [" + block.getBlockName() + "] The default value will be used.");
                        }
                    } catch (Exception ex) {
                        if (property != null && buildProperty != null) {
                            System.out.println("Error getting properly value for property name [" + property.getName() + "] property value [" + buildProperty.getValue() + "] for block [" + block.getBlockName() + "]");
                            throw ex;
                        }
                    }
                } else {
                // System.out.println("Property: [" + property.getName() + "] does not exist for Block: [" + block.getBlockName() + "] this is usually due to mods adding properties to vanilla blocks.");
                }
            }
        }
        block.setBlockState(blockState);
        return block;
    } catch (Exception ex) {
        System.out.println("Error setting block state for block [" + block.getBlockName() + "] for structure configuration class [" + configuration.getClass().getName() + "]");
        throw ex;
    }
}
Also used : EnumAxis(net.minecraft.block.BlockLog.EnumAxis) EnumFacing(net.minecraft.util.EnumFacing) BlockQuartz(net.minecraft.block.BlockQuartz) NBTException(net.minecraft.nbt.NBTException) IProperty(net.minecraft.block.properties.IProperty) EnumOrientation(net.minecraft.block.BlockLever.EnumOrientation) EnumAxis(net.minecraft.block.BlockLog.EnumAxis) Axis(net.minecraft.util.EnumFacing.Axis)

Example 34 with IProperty

use of net.minecraft.block.properties.IProperty in project Ceramics by KnightMiner.

the class PropertyStateMapper method getModelResourceLocation.

@Nonnull
@Override
protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState state) {
    ResourceLocation res = new ResourceLocation(state.getBlock().getRegistryName().getResourceDomain(), name + state.getValue(prop).getName());
    // if we ignore all properites, just use normal
    if (ignoreAll) {
        return new ModelResourceLocation(res, "normal");
    }
    LinkedHashMap<IProperty<?>, Comparable<?>> map = Maps.newLinkedHashMap(state.getProperties());
    map.remove(prop);
    for (IProperty<?> ignored : ignore) {
        map.remove(ignored);
    }
    return new ModelResourceLocation(res, this.getPropertyString(map));
}
Also used : IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Nonnull(javax.annotation.Nonnull)

Example 35 with IProperty

use of net.minecraft.block.properties.IProperty in project ImmersiveEngineering by BluSunrize.

the class BlockConnector method createBlockState.

@Override
protected BlockStateContainer createBlockState() {
    BlockStateContainer base = super.createBlockState();
    IUnlistedProperty[] unlisted = (base instanceof ExtendedBlockState) ? ((ExtendedBlockState) base).getUnlistedProperties().toArray(new IUnlistedProperty[0]) : new IUnlistedProperty[0];
    unlisted = Arrays.copyOf(unlisted, unlisted.length + 1);
    unlisted[unlisted.length - 1] = IEProperties.CONNECTIONS;
    return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted);
}
Also used : IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) IProperty(net.minecraft.block.properties.IProperty) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ExtendedBlockState(net.minecraftforge.common.property.ExtendedBlockState) BlockStateContainer(net.minecraft.block.state.BlockStateContainer)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)78 IBlockState (net.minecraft.block.state.IBlockState)43 Block (net.minecraft.block.Block)23 EnumFacing (net.minecraft.util.EnumFacing)15 ResourceLocation (net.minecraft.util.ResourceLocation)15 ItemStack (net.minecraft.item.ItemStack)14 Map (java.util.Map)11 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)11 ArrayList (java.util.ArrayList)10 BlockPos (net.minecraft.util.math.BlockPos)10 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)10 TileEntity (net.minecraft.tileentity.TileEntity)8 List (java.util.List)7 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)7 World (net.minecraft.world.World)7 JsonObject (com.google.gson.JsonObject)6 Collectors (java.util.stream.Collectors)6 ExtendedBlockState (net.minecraftforge.common.property.ExtendedBlockState)6 FluidStack (net.minecraftforge.fluids.FluidStack)6 Lists (com.google.common.collect.Lists)5