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


Java Block.getDrops方法代碼示例

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


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

示例1: isValidPosition

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Override
protected boolean isValidPosition(BlockPos pos) {
    IBlockState blockState = worldCache.getBlockState(pos);
    Block block = blockState.getBlock();
    if (!worldCache.isAirBlock(pos) && !ignoreBlock(block)) {
        NonNullList<ItemStack> droppedStacks = NonNullList.create();
        if (block.canSilkHarvest(drone.world(), pos, blockState, drone.getFakePlayer())) {
            droppedStacks.add(getSilkTouchBlock(block, blockState));
        } else {
            block.getDrops(droppedStacks, drone.world(), pos, blockState, 0);
        }
        for (ItemStack droppedStack : droppedStacks) {
            if (widget.isItemValidForFilters(droppedStack, blockState)) {
                swapBestItemToFirstSlot(pos);
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:21,代碼來源:DroneAIDig.java

示例2: isBlockValidForFilter

import net.minecraft.block.Block; //導入方法依賴的package包/類
public static boolean isBlockValidForFilter(IBlockAccess worldCache, IDroneBase drone, BlockPos pos, ProgWidgetAreaItemBase widget) {
    IBlockState blockState = worldCache.getBlockState(pos);
    Block block = blockState.getBlock();

    if (!block.isAir(blockState, worldCache, pos)) {
        NonNullList<ItemStack> droppedStacks = NonNullList.create();
        if (block.canSilkHarvest(drone.world(), pos, blockState, drone.getFakePlayer())) {
            droppedStacks.add(getSilkTouchBlock(block, blockState));
        } else {
            block.getDrops(droppedStacks, drone.world(), pos, blockState, 0);
        }
        for (ItemStack droppedStack : droppedStacks) {
            if (widget.isItemValidForFilters(droppedStack, blockState)) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:20,代碼來源:DroneAIDig.java

示例3: harvestAndPickup

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Override
public boolean harvestAndPickup(BlockPos pos) {
    World world = entity.getEntityWorld();
    if (world.isAirBlock(pos)) {
        return true;
    }
    IBlockState state = world.getBlockState(pos);
    if (!allowedToHarvest(state, world, pos, GeneralTools.getHarvester())) {
        return false;
    }
    Block block = state.getBlock();
    List<ItemStack> drops = block.getDrops(world, pos, state, 0);
    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1.0f, false, GeneralTools.getHarvester());
    SoundTools.playSound(world, block.getSoundType().getBreakSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
    block.onBlockHarvested(world, pos, state, GeneralTools.getHarvester());
    entity.getEntityWorld().setBlockToAir(pos);
    giveDropsToMeeCreeps(drops);
    return true;
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:20,代碼來源:WorkerHelper.java

示例4: harvestAndDrop

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Override
public boolean harvestAndDrop(BlockPos pos) {
    World world = entity.getEntityWorld();
    if (world.isAirBlock(pos)) {
        return true;
    }
    IBlockState state = world.getBlockState(pos);
    if (!allowedToHarvest(state, world, pos, GeneralTools.getHarvester())) {
        return false;
    }

    Block block = state.getBlock();

    List<ItemStack> drops = block.getDrops(world, pos, state, 0);
    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1.0f, false, GeneralTools.getHarvester());
    SoundTools.playSound(world, block.getSoundType().getBreakSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
    block.onBlockHarvested(world, pos, state, GeneralTools.getHarvester());
    entity.getEntityWorld().setBlockToAir(pos);
    for (ItemStack stack : drops) {
        entity.entityDropItem(stack, 0.0f);
    }
    return true;
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:24,代碼來源:WorkerHelper.java

示例5: test_getDrops

import net.minecraft.block.Block; //導入方法依賴的package包/類
@Test
public void test_getDrops()
{
    ContentBlockSnow content = new ContentBlockSnow();
    content.id = "test_getDrops";
    content.snowball = new WrappedItemStackConstant(new ItemStack(Items.APPLE, 3));
    content.drop = Attribute.constant(new BlockDrop[] {new BlockDrop(new WrappedItemStackConstant(new ItemStack(Items.STICK)), IntRange.create(2, 2))});

    Block block = content.createBlock();

    NonNullList<ItemStack> drops = NonNullList.create();
    block.getDrops(drops, null, null, block.getDefaultState().withProperty(BlockSnow.LAYERS, 5), 0);
    ItemStack drop1 = drops.get(0);
    ItemStack drop2 = drops.get(1);

    assertEquals(2, drops.size());

    assertSame(Items.APPLE, drop1.getItem());
    assertEquals(18, drop1.getCount());

    assertSame(Items.STICK, drop2.getItem());
    assertEquals(2, drop2.getCount());
}
 
開發者ID:cubex2,項目名稱:customstuff4,代碼行數:24,代碼來源:BlockSnowTest.java

示例6: harvest

import net.minecraft.block.Block; //導入方法依賴的package包/類
protected void harvest(BlockPos pos) {
    IMeeCreep entity = helper.getMeeCreep();
    World world = entity.getWorld();
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    List<ItemStack> drops = block.getDrops(world, pos, state, 0);
    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1.0f, false, GeneralTools.getHarvester());
    SoundTools.playSound(world, block.getSoundType().getBreakSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
    entity.getWorld().setBlockToAir(pos);
    helper.giveDropsToMeeCreeps(drops);
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:12,代碼來源:HarvestActionWorker.java

示例7: harvest

import net.minecraft.block.Block; //導入方法依賴的package包/類
protected void harvest(BlockPos pos) {
    IMeeCreep entity = helper.getMeeCreep();
    World world = entity.getWorld();
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    List<ItemStack> drops = block.getDrops(world, pos, state, 0);
    net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1.0f, false, GeneralTools.getHarvester());
    SoundTools.playSound(world, block.getSoundType().getBreakSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
    world.setBlockToAir(pos);
    helper.giveDropsToMeeCreeps(drops);
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:12,代碼來源:MineOresActionWorker.java

示例8: breakBlock

import net.minecraft.block.Block; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public void breakBlock(EnumFacing facing) {
	BlockPos newPos = pos.offset(facing, 1);
	IBlockState state = this.world.getBlockState(newPos);
	Block block = state.getBlock();
	if (!block.isAir(state, this.world, newPos) && block.getBlockHardness(state, this.world, newPos) >= 0
			&& !(block instanceof BlockDynamicLiquid) && !(block instanceof BlockStaticLiquid)) {
		// Creates a fake player which will berak the block
		EntityPlayer player = new EntityPlayer(world, new GameProfile(null, "BlockBreaker")) {

			@Override
			public boolean isSpectator() {
				return true;
			}

			@Override
			public boolean isCreative() {
				return false;
			}
		};
		List<ItemStack> drops = new ArrayList<ItemStack>();
		boolean customDrops = false;
		if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) {
			ItemStack enchantedBook = this.handler.getStackInSlot(9);
			Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedBook);
			if (enchantments.containsKey(Enchantments.FORTUNE)) {
				int fortune = enchantments.get(Enchantments.FORTUNE);
				drops.add(new ItemStack(block.getItemDropped(state, this.random, fortune),
						block.quantityDroppedWithBonus(fortune, this.random), block.damageDropped(state)));
				customDrops = true;
			}
			if (enchantments.containsKey(Enchantments.SILK_TOUCH)
					&& block.canSilkHarvest(world, newPos, state, player)) {
				// HARD FIX FOR LAPIS
				if (block == Blocks.LAPIS_ORE)
					drops.add(new ItemStack(block, 1));
				else
					drops.add(new ItemStack(block, 1, block.damageDropped(state)));
				customDrops = true;
			}
		}
		if (!customDrops)
			drops = block.getDrops(world, newPos, state, 0);
		for (ItemStack stack : drops) {
			Utils.addStackToInventory(this.handler, 9, stack, false);
		}
		if (!Utils.isInventoryFull(this.handler, 9)) {
			this.world.playEvent(2001, pos, Block.getStateId(state));
			this.world.playSound(null, pos, block.getSoundType(state, world, newPos, player).getBreakSound(),
					SoundCategory.BLOCKS, 1, 1);
			this.world.setBlockToAir(newPos);
			if (block == Blocks.ICE)
				this.world.setBlockState(newPos, Blocks.FLOWING_WATER.getDefaultState());
		}
	}
}
 
開發者ID:IvanSteklow,項目名稱:VanillaExtras,代碼行數:57,代碼來源:TileEntityBlockBreaker.java


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