當前位置: 首頁>>代碼示例>>Java>>正文


Java Block.getStateForPlacement方法代碼示例

本文整理匯總了Java中net.minecraft.block.Block.getStateForPlacement方法的典型用法代碼示例。如果您正苦於以下問題:Java Block.getStateForPlacement方法的具體用法?Java Block.getStateForPlacement怎麽用?Java Block.getStateForPlacement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.block.Block的用法示例。


在下文中一共展示了Block.getStateForPlacement方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildSupport

import net.minecraft.block.Block; //導入方法依賴的package包/類
private void buildSupport(BlockPos pos, EntityItem entityItem) {
    ItemStack blockStack = entityItem.getItem();
    ItemStack actual = blockStack.splitStack(1);
    if (blockStack.isEmpty()) {
        entityItem.setDead();
    }
    if (actual.isEmpty()) {
        return;
    }
    Item item = actual.getItem();
    if (!(item instanceof ItemBlock)) {
        // Safety
        return;
    }

    IMeeCreep entity = helper.getMeeCreep();
    World world = entity.getWorld();
    Block block = ((ItemBlock) item).getBlock();
    IBlockState stateForPlacement = block.getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, item.getMetadata(actual), GeneralTools.getHarvester(), EnumHand.MAIN_HAND);
    world.setBlockState(pos, stateForPlacement, 3);
    SoundTools.playSound(world, block.getSoundType().getPlaceSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:23,代碼來源:DigTunnelActionWorker.java

示例2: onBlockActivated

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack stack = player.getHeldItem(hand);
	boolean isBlock = stack.getItem() instanceof ItemBlock && stack.getItem() != ModItems.ANGSTROM;
	if(!world.isRemote && isBlock) {
		//Replace
		ItemBlock item = (ItemBlock) stack.getItem();
		Block block = Block.getBlockFromItem(item);
		int meta = item.getMetadata(stack);
		IBlockState inState = block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, player, hand);
		world.setBlockState(pos, inState);
		block.onBlockPlacedBy(world, pos, inState, player, stack);
		SoundType sound = block.getSoundType(inState, world, pos, player);
		world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), sound.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F);
		//Exchange
		ItemStack drop = new ItemStack(Item.getItemFromBlock(this));
		ItemHandlerHelper.giveItemToPlayer(player, drop);
		if(!player.capabilities.isCreativeMode) {
			stack.shrink(1);
		}
	}
	return isBlock;
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:24,代碼來源:BlockAngstrom.java

示例3: doBlockInteraction

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
    if (drone.getPathNavigator().hasNoPath()) {
        EnumFacing side = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
        for (int i = 0; i < drone.getInv().getSlots(); i++) {
            ItemStack droneStack = drone.getInv().getStackInSlot(i);
            if (droneStack.getItem() instanceof ItemBlock && ((ItemBlock) droneStack.getItem()).getBlock().canPlaceBlockOnSide(drone.world(), pos, ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides()))) {
                if (widget.isItemValidForFilters(droneStack)) {
                    ItemBlock itemBlock = (ItemBlock) droneStack.getItem();
                    Block block = itemBlock.getBlock();
                    if (drone.world().mayPlace(block, pos, false, side, drone instanceof EntityDrone ? (EntityDrone) drone : null)) {
                        int newMeta = itemBlock.getMetadata(droneStack.getMetadata());
                        setFakePlayerAccordingToDir();
                        IBlockState iblockstate1 = block.getStateForPlacement(drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), newMeta, drone.getFakePlayer(), EnumHand.MAIN_HAND);
                        if (itemBlock.placeBlockAt(droneStack, drone.getFakePlayer(), drone.world(), pos, side, side.getFrontOffsetX(), side.getFrontOffsetY(), side.getFrontOffsetZ(), iblockstate1)) {
                            drone.addAir(null, -PneumaticValues.DRONE_USAGE_PLACE);
                            SoundType soundType = block.getSoundType(iblockstate1, drone.world(), pos, drone.getFakePlayer());
                            drone.world().playSound(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F, false);
                            droneStack.shrink(1);
                            if (droneStack.getCount() <= 0) {
                                drone.getInv().setStackInSlot(i, ItemStack.EMPTY);
                            }
                        }
                        return false;
                    }
                }
            }
        }
        return false;
    } else {
        return true;
    }
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:34,代碼來源:DroneAIPlace.java

示例4: buildSupportBlock

import net.minecraft.block.Block; //導入方法依賴的package包/類
private void buildSupportBlock(EntityItem entityItem) {
    ItemStack blockStack = entityItem.getItem();
    ItemStack actual = blockStack.splitStack(1);
    if (blockStack.isEmpty()) {
        entityItem.setDead();
    }
    IMeeCreep entity = helper.getMeeCreep();
    World world = entity.getWorld();

    Block block = ((ItemBlock) actual.getItem()).getBlock();
    IBlockState stateForPlacement = block.getStateForPlacement(world, supportPosTodo.south(), EnumFacing.DOWN, 0, 0, 0, actual.getItem().getMetadata(actual), GeneralTools.getHarvester(), EnumHand.MAIN_HAND);
    world.setBlockState(supportPosTodo.south(), stateForPlacement, 3);
    placeLadder(supportPosTodo);
    supportPosTodo = null;
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:16,代碼來源:DigdownActionWorker.java

示例5: getStateFromMeta

import net.minecraft.block.Block; //導入方法依賴的package包/類
public static IBlockState getStateFromMeta(Block block, int meta)
{
    try
    {
        return block.getStateForPlacement(null, null, EnumFacing.UP, 0F, 0F, 0F, meta, null, null);
    }
    catch (NullPointerException e)
    {
        return null;
    }
}
 
開發者ID:oitsjustjose,項目名稱:Geolosys,代碼行數:12,代碼來源:HelperFunctions.java

示例6: parseStones

import net.minecraft.block.Block; //導入方法依賴的package包/類
public void parseStones()
{
    for (String s : Config.getInstance().userStoneEntriesRaw)
    {
        String[] parts = s.trim().replaceAll(" ", "").split("[\\W]");
        if (parts.length != 6)
        {
            printFormattingError(s);
            continue;
        }
        try
        {
            Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(parts[0], parts[1]));
            if (block == null || block == Blocks.AIR)
            {
                printFormattingError(s);
                continue;
            }
            IBlockState tempState = block.getStateForPlacement(null, null, null, 0.0F, 0.0F, 0.0F, toInt(parts[2]), null, null);
            userStoneEntriesClean.add(new Entry(tempState, 0, toInt(parts[3]), toInt(parts[4]), toInt(parts[5])));

        }
        catch (NumberFormatException e)
        {
            printFormattingError(s);
            continue;
        }
    }
}
 
開發者ID:oitsjustjose,項目名稱:Geolosys,代碼行數:30,代碼來源:ConfigParser.java

示例7: onItemUse

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();
    Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));

    if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
        facing = EnumFacing.UP;
    else if (!block.isReplaceable(worldIn, pos))
        pos = pos.offset(facing);

    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
        IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);

        if (!worldIn.setBlockState(pos, blockState, 11))
            return EnumActionResult.FAIL;
        else {
            blockState = worldIn.getBlockState(pos);

            if (blockState.getBlock() == cake) {
                ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
                blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
            }

            SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
    }
    else
        return EnumActionResult.FAIL;
}
 
開發者ID:LasmGratel,項目名稱:FoodCraft-Reloaded,代碼行數:36,代碼來源:ItemFruitCake.java

示例8: onItemUse

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();
    Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(vegetableType.toString(), "cake")));

    if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
        facing = EnumFacing.UP;
    else if (!block.isReplaceable(worldIn, pos))
        pos = pos.offset(facing);

    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
        IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);

        if (!worldIn.setBlockState(pos, blockState, 11))
            return EnumActionResult.FAIL;
        else {
            blockState = worldIn.getBlockState(pos);

            if (blockState.getBlock() == cake) {
                ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
                blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
            }

            SoundType soundtype = blockState.getBlock().getSoundType(blockState, worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
    }
    else
        return EnumActionResult.FAIL;
}
 
開發者ID:LasmGratel,項目名稱:FoodCraft-Reloaded,代碼行數:36,代碼來源:ItemVegetableCake.java


注:本文中的net.minecraft.block.Block.getStateForPlacement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。