Search in sources :

Example 61 with IProperty

use of net.minecraft.block.properties.IProperty in project Almura by AlmuraDev.

the class StatefulLazyBlockState method resolveProperties.

private <T extends Comparable<T>> Map<IProperty<? extends Comparable<?>>, StateValue<? extends Comparable<?>>> resolveProperties(final Map<String, StateValue<? extends Comparable<?>>> source) {
    final Block block = (Block) this.block.require();
    final Map<IProperty<? extends Comparable<?>>, StateValue<? extends Comparable<?>>> target = new HashMap<>();
    final BlockStateContainer definition = block.getBlockState();
    for (final Map.Entry<String, StateValue<? extends Comparable<?>>> entry : source.entrySet()) {
        @Nullable final IProperty<T> property = (IProperty<T>) definition.getProperty(entry.getKey());
        if (property != null) {
            target.put(property, entry.getValue());
        }
    }
    return target;
}
Also used : HashMap(java.util.HashMap) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) StateValue(com.almuradev.content.type.block.state.value.StateValue) HashMap(java.util.HashMap) Map(java.util.Map) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) Nullable(javax.annotation.Nullable)

Example 62 with IProperty

use of net.minecraft.block.properties.IProperty in project Almura by AlmuraDev.

the class LookingDebugPanel method renderItemStackFromBlock.

private void renderItemStackFromBlock(final IBlockState state, final ItemStack pickStack) {
    this.clipContent = false;
    // Draw what we know of
    if (!pickStack.isEmpty()) {
        this.drawItem(pickStack, 4, this.autoHeight + 4);
        if (pickStack.getItem() instanceof ItemBlock) {
            this.drawText(Text.of(TextColors.WHITE, Block.REGISTRY.getNameForObject(state.getBlock())), 24, this.autoHeight - 14, false, true);
        } else {
            this.drawText(Text.of(TextColors.WHITE, Block.REGISTRY.getNameForObject(state.getBlock())), 24, this.autoHeight - 14, false, true);
        }
    } else {
        this.drawText(Text.of(TextColors.WHITE, Block.REGISTRY.getNameForObject(state.getBlock())), 24, this.autoHeight + 3, false, true);
    }
    final Map<IProperty<?>, Comparable<?>> properties = state.getProperties();
    final boolean hasProperties = !properties.isEmpty();
    if (hasProperties) {
        this.autoHeight -= 2;
    }
    for (final Map.Entry<IProperty<?>, Comparable<?>> entry : properties.entrySet()) {
        final IProperty<?> property = entry.getKey();
        final String name = property.getName();
        final Comparable<?> value = entry.getValue();
        final String describedValue = getName(property, value);
        if (value instanceof Boolean) {
            this.drawText(Text.of(TextColors.WHITE, name, ": ", ((Boolean) value) ? TextColors.GREEN : TextColors.RED, describedValue), 24, this.autoHeight);
        } else {
            this.drawProperty(name, describedValue, 24, pickStack.isEmpty() ? this.autoHeight + 13 : this.autoHeight);
        }
    }
    if (hasProperties) {
        this.autoHeight -= 4;
    }
}
Also used : IProperty(net.minecraft.block.properties.IProperty) NBTTagString(net.minecraft.nbt.NBTTagString) ItemBlock(net.minecraft.item.ItemBlock) Map(java.util.Map)

Example 63 with IProperty

use of net.minecraft.block.properties.IProperty in project Minestuck by mraof.

the class StructureBlockRegistry method getStairs.

public IBlockState getStairs(String name, EnumFacing facing, boolean upsideDown) {
    Rotation rotation;
    switch(facing) {
        case EAST:
            rotation = Rotation.CLOCKWISE_90;
            break;
        case SOUTH:
            rotation = Rotation.CLOCKWISE_180;
            break;
        case WEST:
            rotation = Rotation.COUNTERCLOCKWISE_90;
            break;
        default:
            rotation = Rotation.NONE;
    }
    IBlockState state = getBlockState(name);
    state = state.withRotation(rotation);
    if (upsideDown)
        for (IProperty<?> property : state.getPropertyKeys()) if (property.getValueClass().equals(BlockStairs.EnumHalf.class)) {
            state = state.withProperty((IProperty<BlockStairs.EnumHalf>) property, BlockStairs.EnumHalf.TOP);
            break;
        }
    return state;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) Rotation(net.minecraft.util.Rotation)

Example 64 with IProperty

use of net.minecraft.block.properties.IProperty in project Binnie by ForestryMC.

the class StateMapperFlower method getModelResourceLocation.

@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
    Map<IProperty<?>, Comparable<?>> properties = Maps.newLinkedHashMap(state.getProperties());
    IFlowerType flowerType = (IFlowerType) state.getValue(BlockFlower.FLOWER);
    if (flowerType.getSections() < 2) {
        properties.remove(BlockFlower.SECTION);
    } else if (flowerType.getSections() <= state.getValue(BlockFlower.SECTION)) {
        properties.put(BlockFlower.SECTION, flowerType.getSections() - 1);
    }
    if (state.getValue(BlockFlower.SEED)) {
        properties.remove(BlockFlower.SECTION);
        properties.remove(BlockFlower.FLOWER);
        properties.remove(BlockFlower.FLOWERED);
    } else {
        properties.remove(BlockFlower.SEED);
    }
    return new ModelResourceLocation(Constants.BOTANY_MOD_ID + ":flower", getPropertyString(properties));
}
Also used : IFlowerType(binnie.botany.api.genetics.IFlowerType) IProperty(net.minecraft.block.properties.IProperty) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 65 with IProperty

use of net.minecraft.block.properties.IProperty in project BiomesOPlenty by Glitchfiend.

the class BlockStateUtils method getStateInfoAsString.

// utility function for dumping block state info to a string
public static String getStateInfoAsString(IBlockState state) {
    String desc = state.getBlock().getClass().getName() + "[";
    Iterator it = state.getProperties().entrySet().iterator();
    boolean first = true;
    while (it.hasNext()) {
        if (!first) {
            desc = desc + ",";
        }
        Entry entry = (Entry) it.next();
        IProperty iproperty = (IProperty) entry.getKey();
        Comparable comparable = (Comparable) entry.getValue();
        desc = desc + iproperty.getName() + "=" + iproperty.getName(comparable);
        first = false;
    }
    desc = desc + "]";
    return desc;
}
Also used : Entry(java.util.Map.Entry) IProperty(net.minecraft.block.properties.IProperty) Iterator(java.util.Iterator)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)72 IBlockState (net.minecraft.block.state.IBlockState)39 Block (net.minecraft.block.Block)20 ResourceLocation (net.minecraft.util.ResourceLocation)14 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)11 ItemStack (net.minecraft.item.ItemStack)10 EnumFacing (net.minecraft.util.EnumFacing)10 Map (java.util.Map)9 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)9 ArrayList (java.util.ArrayList)8 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)8 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)7 JsonObject (com.google.gson.JsonObject)6 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)5 ExtendedBlockState (net.minecraftforge.common.property.ExtendedBlockState)5 JsonArray (com.google.gson.JsonArray)4 JsonElement (com.google.gson.JsonElement)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4