本文整理了Java中net.minecraft.block.Block.harvestBlock()
方法的一些代码示例,展示了Block.harvestBlock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.harvestBlock()
方法的具体详情如下:
包路径:net.minecraft.block.Block
类名称:Block
方法名:harvestBlock
暂无
代码示例来源:origin: Vazkii/Botania
public static void removeBlockWithDrops(EntityPlayer player, ItemStack stack, World world, BlockPos pos,
Predicate<IBlockState> filter,
boolean dispose, boolean particles) {
if(!world.isBlockLoaded(pos))
return;
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(!world.isRemote && filter.test(state)
&& !block.isAir(state, world, pos) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0
&& block.canHarvestBlock(player.world, pos, player)) {
int exp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
if(exp == -1)
return;
if(!player.capabilities.isCreativeMode) {
TileEntity tile = world.getTileEntity(pos);
if(block.removedByPlayer(state, world, pos, player, true)) {
block.onPlayerDestroy(world, pos, state);
if(!dispose || !ItemElementiumPick.isDisposable(block)) {
block.harvestBlock(world, player, pos, state, tile, stack);
block.dropXpOnBlockBreak(world, pos, exp);
}
}
damageItem(stack, 1, player, 80);
} else world.setBlockToAir(pos);
if(particles && ConfigHandler.blockBreakParticles && ConfigHandler.blockBreakParticlesTool)
world.playEvent(2001, pos, Block.getStateId(state));
}
}
代码示例来源:origin: SleepyTrousers/EnderIO
@Override
public void harvestBlock(@Nonnull World worldIn, @Nonnull EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nullable TileEntity te,
@Nonnull ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack);
super.removedByPlayer(state, worldIn, pos, player, true);
}
代码示例来源:origin: WayofTime/BloodMagic
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity tile, ItemStack stack) {
super.harvestBlock(world, player, pos, state, tile, stack);
world.setBlockToAir(pos);
}
代码示例来源:origin: raoulvdberge/refinedstorage
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity tile, ItemStack stack) {
super.harvestBlock(world, player, pos, state, tile, stack);
world.setBlockToAir(pos);
}
代码示例来源:origin: SleepyTrousers/EnderCore
@Override
public void harvestBlock(@Nonnull World worldIn, @Nonnull EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nullable TileEntity te,
@Nonnull ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack);
worldIn.setBlockToAir(pos);
}
代码示例来源:origin: vadis365/TheErebus
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack);
worldIn.setBlockToAir(pos);
}
代码示例来源:origin: GregTechCE/GregTech
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
tileEntities.set(te == null ? null : ((MetaTileEntityHolder) te).getMetaTileEntity());
super.harvestBlock(worldIn, player, pos, state, te, stack);
tileEntities.set(null);
}
代码示例来源:origin: TerraFirmaCraft/TerraFirmaCraft
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
if (!worldIn.isRemote && te != null && te instanceof TESidedInventory)
{
((TESidedInventory) te).onBreakBlock(worldIn, pos);
}
super.harvestBlock(worldIn, player, pos, state, te, stack);
}
代码示例来源:origin: TheCBProject/EnderStorage
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) {
super.harvestBlock(worldIn, player, pos, state, te, stack);
worldIn.setBlockToAir(pos);
}
代码示例来源:origin: TheGreyGhost/MinecraftByExample
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state,
@Nullable TileEntity te, @Nullable ItemStack stack) {
StartupCommon.methodCallLogger.enterMethod("BlockToolTest.harvestBlock",
"{world}, " + pos + ", " + String.valueOf(state) + ", " + String.valueOf(te)
+", " + String.valueOf(stack) );
super.harvestBlock(worldIn, player, pos, state, te, stack);
StartupCommon.methodCallLogger.exitMethod("BlockToolTest.harvestBlock", "");
return;
}
代码示例来源:origin: SleepyTrousers/EnderIO
@Override
public void harvestBlock(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nullable TileEntity te,
@Nonnull ItemStack stack) {
if (checkParent(world, pos)) {
getParentBlock(world, pos).harvestBlock(world, player, getParentPos(pos), getParentBlockState(world, pos), world.getTileEntity(getParentPos(pos)), stack);
}
world.setBlockToAir(pos);
}
代码示例来源:origin: Darkhax-Minecraft/Bookshelf
/**
* Attempts to harvest a block. This can be used in potentially unsafe situations, such as
* breaking a block at a position where it doesn't actually exist.
*
* @param world The world to break it in.
* @param player The player harvesting the block.
* @param pos The position to break it at.
* @param state The block state to break.
*/
public static void dropBlockSafely (World world, EntityPlayer player, BlockPos pos, IBlockState state) {
try {
state.getBlock().harvestBlock(world, player, pos, state, world.getTileEntity(pos), player.getHeldItemMainhand());
}
catch (final Exception e) {
Constants.LOG.trace("Could not harvest block!", e);
}
}
代码示例来源:origin: AlgorithmX2/Chisels-and-Bits
@Override
public void harvestBlock(
final World worldIn,
final EntityPlayer player,
final BlockPos pos,
final IBlockState state,
final TileEntity te,
final ItemStack stack )
{
try
{
spawnAsEntity( worldIn, pos, getTileEntity( te ).getItemStack( player ) );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
super.harvestBlock( worldIn, player, pos, state, (TileEntity) null, stack );
}
}
代码示例来源:origin: SleepyTrousers/EnderIO
public static boolean breakBlockWithTool(@Nonnull Block block, @Nonnull World world, @Nonnull BlockPos pos, @Nullable EnumFacing side,
@Nonnull EntityPlayer entityPlayer, @Nonnull EnumHand hand, @Nonnull String permissionNode) {
ItemStack heldItem = entityPlayer.getHeldItem(hand);
ITool tool = ToolUtil.getToolFromStack(heldItem);
if (tool != null && entityPlayer.isSneaking() && tool.canUse(hand, entityPlayer, pos)) {
IBlockState bs = world.getBlockState(pos);
if (!PermissionAPI.hasPermission(entityPlayer.getGameProfile(), permissionNode, new BlockPosContext(entityPlayer, pos, bs, side))) {
entityPlayer.sendMessage(Lang.WRENCH_DENIED.toChatServer());
return false;
}
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, bs, entityPlayer);
event.setExpToDrop(0);
if (MinecraftForge.EVENT_BUS.post(event)) {
return false;
}
if (block.removedByPlayer(bs, world, pos, entityPlayer, true)) {
block.harvestBlock(world, entityPlayer, pos, world.getBlockState(pos), world.getTileEntity(pos), heldItem);
}
tool.used(hand, entityPlayer, pos);
return true;
}
return false;
}
代码示例来源:origin: SonarSonic/Calculator
/**doesn't call onWrenched*/
public static void dropBlock(EntityPlayer player, @Nonnull EnumHand hand, World world, BlockPos pos){
TileEntity te = world.getTileEntity(pos);
world.getBlockState(pos).getBlock().harvestBlock(world, player, pos, world.getBlockState(pos), te, player.getHeldItem(hand));
world.getBlockState(pos).getBlock().removedByPlayer(world.getBlockState(pos), world, pos, player, true);
}
}
代码示例来源:origin: SleepyTrousers/EnderIO
private void doHarvest(@Nonnull final IFarmer farm, @Nonnull final World world, @Nonnull IBlockState blockState, @Nonnull final BlockPos pos, int fortune,
@Nonnull final HarvestResult result) {
FakePlayer joe = farm.startUsingItem(FarmingTool.AXE);
NNList<ItemStack> drops = new NNList<>();
blockState.getBlock().getDrops(drops, world, pos, blockState, fortune);
final float chance = ForgeEventFactory.fireBlockHarvesting(drops, world, pos, blockState, fortune, 1f, false, joe);
// flowers drop here by spawning their drops into the world (joe's world captures those)
blockState.getBlock().harvestBlock(joe.world, joe, pos, blockState, null, joe.getHeldItemMainhand());
NNList.wrap(drops).apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack drop) {
if (farm.getWorld().rand.nextFloat() <= chance) {
result.getDrops().add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy()));
}
}
});
NNList.wrap(farm.endUsingItem(FarmingTool.AXE)).apply(new Callback<ItemStack>() {
@Override
public void apply(@Nonnull ItemStack drop) {
result.getDrops().add(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, drop.copy()));
}
});
farm.registerAction(FarmingAction.HARVEST, FarmingTool.AXE, blockState, pos);
world.setBlockToAir(pos);
result.getHarvestedBlocks().add(pos);
}
代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition
@Override
public ArrayList<ItemStack> dismantleBlock(EntityPlayer player, World world, BlockPos pos, boolean returnDrops) {
ArrayList<ItemStack> items = new ArrayList<>();
IBlockState state = world.getBlockState(pos);
if (!returnDrops) {
state.getBlock().harvestBlock(world, player, pos, state, world.getTileEntity(pos), ItemStack.EMPTY);
state.getBlock().removedByPlayer(state, world, pos, player, true);
} else {
state.getBlock().removedByPlayer(state, world, pos, player, true);
state.getBlock().breakBlock(world, pos, state);
for (ItemStack itemStack : getDrops(world, pos, state, 0)) {
MOInventoryHelper.insertItemStackIntoInventory(player.inventory, itemStack, EnumFacing.DOWN);
}
}
return items;
}
代码示例来源:origin: OpenMods/OpenModsLib
boolean isRemoved = removeBlock(fakePlayer, blockPos, state, canHarvest);
if (isRemoved && canHarvest) {
state.getBlock().harvestBlock(worldObj, fakePlayer, blockPos, state, te, stackToUse);
worldObj.playEvent(fakePlayer, 2001, blockPos, Block.getStateId(state));
代码示例来源:origin: SonarSonic/Calculator
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(pos);
Block block = world.getBlockState(pos).getBlock();
if (player.isSneaking()) {
if (block instanceof IWrenchable && ((IWrenchable) block).canWrench(player, world, pos)){
world.getBlockState(pos).getBlock().harvestBlock(world, player, pos, world.getBlockState(pos), te, player.getHeldItem(hand));
world.getBlockState(pos).getBlock().removedByPlayer(world.getBlockState(pos), world, pos, player, true);
((IWrenchable) block).onWrenched(player, world, pos);
}
} else {
if (te instanceof IMachineSides) {
((IMachineSides) te).getSideConfigs().increaseSide(side);
}
}
return EnumActionResult.SUCCESS;
}
代码示例来源:origin: Vazkii/Psi
public static void removeBlockWithDrops(SpellContext context, EntityPlayer player, World world, ItemStack tool, BlockPos pos, boolean particles) {
if(!world.isBlockLoaded(pos) || (context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos())) || !world.isBlockModifiable(player, pos))
return;
if (tool.isEmpty())
tool = PsiAPI.getPlayerCAD(player);
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(!world.isRemote && !block.isAir(state, world, pos) && !(block instanceof BlockLiquid) && !(block instanceof IFluidBlock) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
if(!canHarvestBlock(block, player, world, pos, tool))
return;
BreakEvent event = createBreakEvent(state, player, world, pos, tool);
MinecraftForge.EVENT_BUS.post(event);
if(!event.isCanceled()) {
if(!player.capabilities.isCreativeMode) {
TileEntity tile = world.getTileEntity(pos);
if(block.removedByPlayer(state, world, pos, player, true)) {
block.onBlockDestroyedByPlayer(world, pos, state);
block.harvestBlock(world, player, pos, state, tile, tool);
}
} else world.setBlockToAir(pos);
}
if(particles)
world.playEvent(2001, pos, Block.getStateId(state));
}
}
内容来源于网络,如有侵权,请联系作者删除!