Search in sources :

Example 41 with IProperty

use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.

the class ItemBlockReinforcedSlabs method canPlaceBlockOnSide.

@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
    BlockPos blockpos1 = pos;
    IProperty iproperty = singleSlab.getVariantProperty();
    Object object = singleSlab.getVariant(stack);
    IBlockState iblockstate = worldIn.getBlockState(pos);
    if (iblockstate.getBlock() == singleSlab) {
        boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
        if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty))
            return true;
    }
    pos = pos.offset(side);
    IBlockState iblockstate1 = worldIn.getBlockState(pos);
    return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) BlockPos(net.minecraft.util.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 42 with IProperty

use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.

the class ItemBlockReinforcedWoodSlabs method canPlaceBlockOnSide.

@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
    BlockPos blockpos1 = pos;
    IProperty iproperty = singleSlab.getVariantProperty();
    Object object = singleSlab.getVariant(stack);
    IBlockState iblockstate = worldIn.getBlockState(pos);
    if (iblockstate.getBlock() == singleSlab) {
        boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
        if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty))
            return true;
    }
    pos = pos.offset(side);
    IBlockState iblockstate1 = worldIn.getBlockState(pos);
    return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) BlockPos(net.minecraft.util.BlockPos) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 43 with IProperty

use of net.minecraft.block.properties.IProperty in project SpongeCommon by SpongePowered.

the class MixinStateImplementation method generateId.

@Override
public void generateId(Block block) {
    StringBuilder builder = new StringBuilder();
    builder.append(((BlockType) block).getId());
    if (!this.properties.isEmpty()) {
        builder.append('[');
        Joiner joiner = Joiner.on(',');
        List<String> propertyValues = new ArrayList<>();
        for (Map.Entry<IProperty<?>, Comparable<?>> entry : this.properties.entrySet()) {
            propertyValues.add(entry.getKey().getName() + "=" + entry.getValue());
        }
        builder.append(joiner.join(propertyValues));
        builder.append(']');
    }
    this.id = builder.toString();
}
Also used : Joiner(com.google.common.base.Joiner) IProperty(net.minecraft.block.properties.IProperty) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 44 with IProperty

use of net.minecraft.block.properties.IProperty in project SpongeCommon by SpongePowered.

the class BlockPropertyIdProvider method getIdAndTryRegistration.

public static String getIdAndTryRegistration(IProperty<?> property, Block block, String blockId) {
    BlockPropertyIdProvider instance = getInstance();
    checkNotNull(property, "Property is null! Cannot retrieve a registration for a null property!");
    checkNotNull(block, "Block cannot be null!");
    checkNotNull(blockId, "Block id cannot be null!");
    checkArgument(!blockId.isEmpty(), "Block id cannot be empty!");
    if (instance.isRegistered(property)) {
        return instance.propertyIdMap.get(property);
    }
    final String lowerCasedBlockId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, blockId);
    final String modId = lowerCasedBlockId.split(":")[0];
    final String propertyName = property.getName();
    final String lastAttemptId = lowerCasedBlockId + "_" + property.getName();
    try {
        // Seriously, don't look past this try state. just continue on with your day...
        // I warned you...
        final String originalClass = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, block.getClass().getSimpleName());
        Class<?> blockClass = block.getClass();
        while (true) {
            if (blockClass == Object.class) {
                final String propertyId = modId + ":" + originalClass + "_" + property.getName();
                LogManager.getLogger("Sponge").warn("Could not find {} owning class, assigning fallback id: {}", property.getName(), propertyId);
                instance.register(property, propertyId);
                return propertyId;
            }
            // Had enough?
            for (Field field : blockClass.getDeclaredFields()) {
                field.setAccessible(true);
                final boolean isStatic = Modifier.isStatic(field.getModifiers());
                final Object o = isStatic ? field.get(null) : field.get(block);
                if (property != o) {
                    continue;
                }
                final String className = field.getDeclaringClass().getSimpleName().replace("Block", "").replace("block", "");
                final String classNameId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, className);
                final String propertyClassName = isStatic ? classNameId : originalClass;
                final String combinedId = modId + ":" + propertyClassName + "_" + propertyName.toLowerCase(Locale.ENGLISH);
                if (instance.idPropertyMap.containsKey(combinedId)) {
                    // in this case, we really do have to fall back on the full block id...
                    if (instance.idPropertyMap.containsKey(lastAttemptId)) {
                        // we really are screwed...
                        throw new IllegalArgumentException("Sorry! Someone is trying to re-register a block with the same property instances of" + "block: " + blockId + " , with property: " + propertyName);
                    }
                    instance.register((IProperty<?>) o, lastAttemptId);
                    return lastAttemptId;
                }
                instance.register(((IProperty<?>) o), combinedId);
                return combinedId;
            }
            blockClass = blockClass.getSuperclass();
        }
    } catch (Exception e) {
        LogManager.getLogger("Sponge").warn("An exception was thrown while trying to resolve the property " + property.getName() + "'s owning class, assigning " + "fallback id: " + lastAttemptId, e);
        instance.register(property, lastAttemptId);
        return lastAttemptId;
    }
}
Also used : Field(java.lang.reflect.Field) IProperty(net.minecraft.block.properties.IProperty)

Example 45 with IProperty

use of net.minecraft.block.properties.IProperty in project MorePlanets by SteveKunG.

the class ItemBlockSlabMP method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    if (this.block instanceof ISlabBlock) {
        ISlabBlock singleSlab = (ISlabBlock) this.block;
        if (itemStack.getCount() != 0 && player.canPlayerEdit(pos.offset(facing), facing, itemStack)) {
            Object object = singleSlab.getHalf().getTypeForItem(itemStack);
            IBlockState state = world.getBlockState(pos);
            if (state.getBlock() == singleSlab.getHalf()) {
                IProperty iproperty = singleSlab.getHalf().getVariantProperty();
                Comparable comparable = state.getValue(iproperty);
                EnumBlockHalf enumblockhalf = state.getValue(BlockSlab.HALF);
                if ((facing == EnumFacing.UP && enumblockhalf == EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && enumblockhalf == BlockSlab.EnumBlockHalf.TOP) && comparable == object) {
                    IBlockState state1 = singleSlab.getDouble().getDefaultState().withProperty(iproperty, comparable);
                    AxisAlignedBB axisalignedbb = state1.getCollisionBoundingBox(world, pos);
                    if (axisalignedbb != Block.NULL_AABB && world.checkNoEntityCollision(axisalignedbb.offset(pos)) && world.setBlockState(pos, state1, 11)) {
                        SoundType sound = singleSlab.getDouble().getSoundType(state1, world, pos, player);
                        world.playSound(player, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
                        itemStack.shrink(1);
                    }
                    return EnumActionResult.SUCCESS;
                }
            }
            return this.tryPlace(player, itemStack, world, pos.offset(facing), object, singleSlab.getHalf(), singleSlab.getDouble()) ? EnumActionResult.SUCCESS : super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
        }
    } else {
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.FAIL;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SoundType(net.minecraft.block.SoundType) EnumBlockHalf(net.minecraft.block.BlockSlab.EnumBlockHalf) IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ISlabBlock(stevekung.mods.moreplanets.util.blocks.ISlabBlock) ItemStack(net.minecraft.item.ItemStack)

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