Search in sources :

Example 66 with IProperty

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

the class BlockStateUtils method addStatesToList.

// recursively add state values to a list
private static void addStatesToList(IBlockState state, List<IBlockState> list, Stack<IProperty> stack) {
    if (stack.empty()) {
        list.add(state);
        return;
    } else {
        IProperty prop = stack.pop();
        for (Object value : prop.getAllowedValues()) {
            addStatesToList(state.withProperty(prop, (Comparable) value), list, stack);
        }
        stack.push(prop);
    }
}
Also used : IProperty(net.minecraft.block.properties.IProperty)

Example 67 with IProperty

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

the class BlockStateUtils method getStatesSet.

// returns a set of states, one for every possible combination of values from the provided properties
public static ImmutableSet<IBlockState> getStatesSet(IBlockState baseState, IProperty... properties) {
    Stack<IProperty> propStack = new Stack<IProperty>();
    List<IBlockState> states = new ArrayList<IBlockState>();
    for (IProperty prop : properties) {
        propStack.push(prop);
    }
    if (!propStack.isEmpty()) {
        addStatesToList(baseState, states, propStack);
    }
    ImmutableSet<IBlockState> ret = ImmutableSet.copyOf(states);
    return ret;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ArrayList(java.util.ArrayList) Stack(java.util.Stack)

Example 68 with IProperty

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

the class ClientProxy method registerBlockSided.

@Override
public void registerBlockSided(Block block) {
    if (block instanceof IBOPBlock) {
        IBOPBlock bopBlock = (IBOPBlock) block;
        // Register non-rendering properties
        IProperty[] nonRenderingProperties = bopBlock.getNonRenderingProperties();
        if (nonRenderingProperties != null) {
            // use a custom state mapper which will ignore the properties specified in the block as being non-rendering
            IStateMapper custom_mapper = (new StateMap.Builder()).ignore(nonRenderingProperties).build();
            ModelLoader.setCustomStateMapper(block, custom_mapper);
        }
        // Register colour handlers
        if (bopBlock.getBlockColor() != null || bopBlock.getItemColor() != null) {
            blocksToColour.add(block);
        }
    }
}
Also used : IBOPBlock(biomesoplenty.common.block.IBOPBlock) IProperty(net.minecraft.block.properties.IProperty) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) IStateMapper(net.minecraft.client.renderer.block.statemap.IStateMapper)

Example 69 with IProperty

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

the class BlockIETileProvider method getActualState.

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
    state = super.getActualState(state, world, pos);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IAttachedIntegerProperies) {
        for (String s : ((IAttachedIntegerProperies) tile).getIntPropertyNames()) state = applyProperty(state, ((IAttachedIntegerProperies) tile).getIntProperty(s), ((IAttachedIntegerProperies) tile).getIntPropertyValue(s));
    }
    if (tile instanceof IDirectionalTile && (state.getPropertyKeys().contains(IEProperties.FACING_ALL) || state.getPropertyKeys().contains(IEProperties.FACING_HORIZONTAL))) {
        PropertyDirection prop = state.getPropertyKeys().contains(IEProperties.FACING_HORIZONTAL) ? IEProperties.FACING_HORIZONTAL : IEProperties.FACING_ALL;
        state = applyProperty(state, prop, ((IDirectionalTile) tile).getFacing());
    }
    if (tile instanceof IActiveState) {
        IProperty boolProp = ((IActiveState) tile).getBoolProperty(IActiveState.class);
        if (state.getPropertyKeys().contains(boolProp))
            state = applyProperty(state, boolProp, ((IActiveState) tile).getIsActive());
    }
    if (tile instanceof IDualState) {
        IProperty boolProp = ((IDualState) tile).getBoolProperty(IDualState.class);
        if (state.getPropertyKeys().contains(boolProp))
            state = applyProperty(state, boolProp, ((IDualState) tile).getIsSecondState());
    }
    if (tile instanceof TileEntityMultiblockPart)
        state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((TileEntityMultiblockPart) tile).isDummy());
    else if (tile instanceof IHasDummyBlocks)
        state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((IHasDummyBlocks) tile).isDummy());
    if (tile instanceof IMirrorAble)
        state = applyProperty(state, ((IMirrorAble) tile).getBoolProperty(IMirrorAble.class), ((IMirrorAble) tile).getIsMirrored());
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IProperty(net.minecraft.block.properties.IProperty) PropertyDirection(net.minecraft.block.properties.PropertyDirection)

Example 70 with IProperty

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

the class BlockIETileProvider method createTileEntity.

@Nullable
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
    TileEntity basic = createBasicTE(world, state.getValue(property));
    Collection<IProperty<?>> keys = state.getPropertyKeys();
    if (basic instanceof IDirectionalTile) {
        EnumFacing newFacing = null;
        if (keys.contains(IEProperties.FACING_HORIZONTAL))
            newFacing = state.getValue(IEProperties.FACING_HORIZONTAL);
        else if (keys.contains(IEProperties.FACING_ALL))
            newFacing = state.getValue(IEProperties.FACING_ALL);
        int type = ((IDirectionalTile) basic).getFacingLimitation();
        if (newFacing != null) {
            switch(type) {
                case 2:
                case 4:
                case 5:
                case 6:
                    if (newFacing.getAxis() == Axis.Y)
                        newFacing = null;
                    break;
                case 3:
                    if (newFacing.getAxis() != Axis.Y)
                        newFacing = null;
                    break;
            }
            if (newFacing != null)
                ((IDirectionalTile) basic).setFacing(newFacing);
        }
    }
    if (basic instanceof IAttachedIntegerProperies) {
        IAttachedIntegerProperies tileIntProps = (IAttachedIntegerProperies) basic;
        String[] names = ((IAttachedIntegerProperies) basic).getIntPropertyNames();
        for (String propertyName : names) {
            PropertyInteger property = tileIntProps.getIntProperty(propertyName);
            if (keys.contains(property))
                tileIntProps.setValue(propertyName, state.getValue(property));
        }
    }
    return basic;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PropertyInteger(net.minecraft.block.properties.PropertyInteger) IProperty(net.minecraft.block.properties.IProperty) EnumFacing(net.minecraft.util.EnumFacing) Nullable(javax.annotation.Nullable)

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