Search in sources :

Example 1 with StateValue

use of com.almuradev.content.type.block.state.value.StateValue in project Almura by AlmuraDev.

the class StatefulLazyBlockState method createState.

@Override
<T extends Comparable<T>> IBlockState createState() {
    final Block block = (Block) this.block.require();
    IBlockState state = block.getDefaultState();
    for (final Map.Entry<IProperty<? extends Comparable<?>>, StateValue<? extends Comparable<?>>> entry : this.properties.get().entrySet()) {
        @Nullable final IProperty<T> property = (IProperty<T>) entry.getKey();
        if (property != null) {
            @Nullable final T value = ((StateValue<T>) entry.getValue()).get(property);
            if (value != null) {
                state = state.withProperty(property, value);
            }
        }
    }
    return state;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) 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) Nullable(javax.annotation.Nullable)

Example 2 with StateValue

use of com.almuradev.content.type.block.state.value.StateValue 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)

Aggregations

StateValue (com.almuradev.content.type.block.state.value.StateValue)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.block.Block)2 IProperty (net.minecraft.block.properties.IProperty)2 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)1 IBlockState (net.minecraft.block.state.IBlockState)1