本文整理了Java中net.minecraft.block.Block.canSilkHarvest()
方法的一些代码示例,展示了Block.canSilkHarvest()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.canSilkHarvest()
方法的具体详情如下:
包路径:net.minecraft.block.Block
类名称:Block
方法名:canSilkHarvest
暂无
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
protected List<ItemStack> obtainBlockDrops( final WorldServer w, final BlockPos pos )
{
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft( w );
final IBlockState state = w.getBlockState( pos );
if( state.getBlock().canSilkHarvest( w, pos, state, fakePlayer ) )
{
final List<ItemStack> out = new ArrayList<>( 1 );
final Item item = Item.getItemFromBlock( state.getBlock() );
if( item != Items.AIR )
{
int meta = 0;
if( item.getHasSubtypes() )
{
meta = state.getBlock().getMetaFromState( state );
}
final ItemStack itemstack = new ItemStack( item, 1, meta );
out.add( itemstack );
}
return out;
}
else
{
return super.obtainBlockDrops( w, pos );
}
}
代码示例来源:origin: Vazkii/Botania
@SubscribeEvent
public void onBlockDrops(HarvestDropsEvent event) {
if(event.getHarvester() != null && event.getState() != null && event.getDrops() != null && event.getDrops().isEmpty() && !event.getHarvester().getHeldItemMainhand().isEmpty() && event.getHarvester().getHeldItemMainhand().getItem() == this && event.getState().getMaterial() == Material.GLASS && event.getState().getBlock().canSilkHarvest(event.getWorld(), event.getPos(), event.getState(), event.getHarvester()))
event.getDrops().add(new ItemStack(event.getState().getBlock(), 1, event.getState().getBlock().getMetaFromState(event.getState())));
}
代码示例来源:origin: Vazkii/Botania
@Override
public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) {
if(!entity.world.isRemote && !burst.isFake() && pos.getBlockPos() != null) {
int harvestLevel = ConfigHandler.harvestLevelWeight;
BlockPos bPos = pos.getBlockPos();
Block block = entity.world.getBlockState(bPos).getBlock();
IBlockState state = entity.world.getBlockState(bPos);
int neededHarvestLevel = block.getHarvestLevel(state);
if(entity.world.isAirBlock(bPos.down()) && state.getBlockHardness(entity.world, bPos) != -1 && neededHarvestLevel <= harvestLevel && entity.world.getTileEntity(bPos) == null && block.canSilkHarvest(entity.world, bPos, state, null)) {
state = TECHNICAL_BLOCK_REMAP.getOrDefault(state, state);
EntityFallingBlock falling = new EntityFallingBlock(entity.world, bPos.getX() + 0.5, bPos.getY(), bPos.getZ() + 0.5, state);
falling.fallTime = 1;
entity.world.setBlockToAir(bPos);
((WorldServer) entity.world).spawnParticle(EnumParticleTypes.FALLING_DUST, bPos.getX() + 0.5, bPos.getY() + 0.5, bPos.getZ() + 0.5, 10, 0.45, 0.45, 0.45, 5, new int[] {Block.getStateId(state)});
entity.world.spawnEntity(falling);
}
}
return dead;
}
代码示例来源:origin: PenguinSquad/Harvest-Festival
public static void collectDrops(World world, BlockPos pos, IBlockState state, EntityPlayer player, List<ItemStack> drops) {
Block block = state.getBlock();
List<ItemStack> blockDrops = new ArrayList<>();
if (block.canSilkHarvest(world, pos, state, player)) {
try {
Method method = ReflectionHelper.findMethod(Block.class, null, new String[] { "getSilkTouchDrop", "func_180643_i" } , IBlockState.class);
ItemStack stack = (ItemStack) method.invoke(block, state);
if (stack != null) {
blockDrops.add(stack);
ForgeEventFactory.fireBlockHarvesting(blockDrops, world, pos, state, 0, 1F, true, player);
drops.addAll(blockDrops); //Add all the drops to our list
}
} catch (IllegalAccessException | InvocationTargetException e) {/**/}
} else {
blockDrops = block.getDrops(world, pos, state, 0);
ForgeEventFactory.fireBlockHarvesting(blockDrops, world, pos, state, 0, 1F, false, player);
drops.addAll(blockDrops); //Add all the drops to our list
}
}
代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation
@Override
public void onPlayerHarvestDropsWithTool(BlockEvent.HarvestDropsEvent event, @Nonnull ItemStack toolStack, @Nonnull ItemStack thisUpgradeStack) {
EntityPlayer player = event.getHarvester();
BlockPos pos = event.getPos();
World world = event.getWorld();
IBlockState state = event.getState();
Block block = state.getBlock();
if (ForgeHooks.canHarvestBlock(block, player, world, pos) && block.canSilkHarvest(world, pos, state, player)) {
try {
ItemStack toAdd = (ItemStack) ReflectionHelper.createStackedBlockMethod.invoke(block, state);
if (toAdd != null) {
event.getDrops().clear();
event.getDrops().add(toAdd);
}
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: sinkillerj/ProjectE
public static List<ItemStack> getBlockDrops(World world, EntityPlayer player, IBlockState state, ItemStack stack, BlockPos pos)
{
if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0 && state.getBlock().canSilkHarvest(world, pos, state, player))
{
return Lists.newArrayList(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)));
}
return state.getBlock().getDrops(world, pos, state, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack));
}
代码示例来源:origin: Vazkii/Psi
public static BreakEvent createBreakEvent(IBlockState state, EntityPlayer player, World world, BlockPos pos, ItemStack tool) {
BreakEvent event = new BreakEvent(world, pos, state, player);
if (state == null || !canHarvestBlock(state.getBlock(), player, world, pos, tool) ||
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0))
event.setExpToDrop(0);
else
event.setExpToDrop(state.getBlock().getExpDrop(state, world, pos,
EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, tool)));
return event;
}
代码示例来源:origin: WayofTime/BloodMagic
protected void sharedHarvest(ItemStack stack, World world, EntityPlayer player, BlockPos blockPos, IBlockState blockState, boolean silkTouch, int fortuneLvl) {
if (blockState.getBlockHardness(world, blockPos) != -1.0F) {
float strengthVsBlock = getDestroySpeed(stack, blockState);
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
if (!player.isCreative())
if (silkTouch && blockState.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Item.getItemFromBlock(blockState.getBlock())));
else {
NonNullList<ItemStack> itemDrops = NonNullList.create();
blockState.getBlock().getDrops(itemDrops, world, blockPos, world.getBlockState(blockPos), fortuneLvl);
for (ItemStack stacks : itemDrops)
ItemHandlerHelper.giveItemToPlayer(player, stacks);
}
blockState.getBlock().removedByPlayer(world.getBlockState(blockPos), world, blockPos, player, false);
}
}
}
}
代码示例来源:origin: CoFH/CoFHCore
public static List<ItemStack> breakBlock(World worldObj, EntityPlayer player, BlockPos pos, IBlockState state, int fortune, boolean doBreak, boolean silkTouch) {
if (state.getBlockHardness(worldObj, pos) == -1) {
return new LinkedList<>();
}
NonNullList<ItemStack> ret = NonNullList.create();
if (silkTouch && state.getBlock().canSilkHarvest(worldObj, pos, state, player)) {
ret.add(createStackedBlock(state));
} else {
state.getBlock().getDrops(ret, worldObj, pos, state, fortune);
}
if (!doBreak) {
return ret;
}
worldObj.playEvent(2001, pos, Block.getStateId(state));
worldObj.setBlockToAir(pos);
List<EntityItem> result = worldObj.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos.getX() - 2, pos.getY() - 2, pos.getZ() - 2, pos.getX() + 3, pos.getY() + 3, pos.getZ() + 3));
for (EntityItem entity : result) {
if (entity.isDead || entity.getItem().getCount() <= 0) {
continue;
}
ret.add(entity.getItem());
entity.world.removeEntity(entity);
}
return ret;
}
代码示例来源:origin: Direwolf20-MC/BuildingGadgets
if (setBlock.getBlock().canSilkHarvest(world, pos, setBlock, player)) {
itemStack = InventoryManipulation.getSilkTouchDrop(setBlock);
} else {
代码示例来源:origin: Direwolf20-MC/BuildingGadgets
boolean useConstructionPaste = false;
if (setBlock.getBlock().canSilkHarvest(world, pos, setBlock, player)) {
itemStack = InventoryManipulation.getSilkTouchDrop(setBlock);
} else {
代码示例来源:origin: WayofTime/BloodMagic
if (!isBlockClaimed && isSilkTouch && block.canSilkHarvest(world, newPos, state, getFakePlayer((WorldServer) world))) {
ItemStack checkStack = block.getItem(world, newPos, state);
if (checkStack.isEmpty()) {
代码示例来源:origin: Vazkii/Psi
world.getTileEntity(pos) == null && block.canSilkHarvest(world, pos, state, context.caster)) {
代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition
int matter = 0;
if (blockState.getBlock().canSilkHarvest(world, pos, blockState, null)) {
matter += MatterHelper.getMatterAmountFromItem(blockState.getBlock().getPickBlock(blockState, null, world, pos, null));
} else {
代码示例来源:origin: Direwolf20-MC/BuildingGadgets
if (renderBlockState.getBlock().canSilkHarvest(world, new BlockPos(0, 0, 0), renderBlockState, player)) {
itemStack = InventoryManipulation.getSilkTouchDrop(renderBlockState);
} else {
代码示例来源:origin: Vazkii/Psi
Block block = state.getBlock();
if(world.getTileEntity(pos) != null || state.getMobilityFlag() != EnumPushReaction.NORMAL ||
!block.canSilkHarvest(world, pos, state, context.caster) ||
state.getPlayerRelativeBlockHardness(context.caster, world, pos) <= 0 ||
!PieceTrickBreakBlock.canHarvestBlock(block, context.caster, world, pos, tool))
代码示例来源:origin: Direwolf20-MC/BuildingGadgets
if (renderBlockState.getBlock().canSilkHarvest(world, new BlockPos(0, 0, 0), renderBlockState, player)) {
itemStack = InventoryManipulation.getSilkTouchDrop(renderBlockState);
} else {
代码示例来源:origin: raoulvdberge/refinedstorage
((TileEntityShulkerBox) shulkerBoxTile).clear();
} else if (upgrades.hasUpgrade(ItemUpgrade.TYPE_SILK_TOUCH) && frontBlock.canSilkHarvest(world, front, frontBlockState, null)) {
drops.add(frontStack);
} else {
内容来源于网络,如有侵权,请联系作者删除!