本文整理汇总了Java中net.minecraftforge.common.ForgeHooks.canHarvestBlock方法的典型用法代码示例。如果您正苦于以下问题:Java ForgeHooks.canHarvestBlock方法的具体用法?Java ForgeHooks.canHarvestBlock怎么用?Java ForgeHooks.canHarvestBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.common.ForgeHooks
的用法示例。
在下文中一共展示了ForgeHooks.canHarvestBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BreakEvent
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public BreakEvent(World world, BlockPos pos, IBlockState state, EntityPlayer player)
{
super(world, pos, state);
this.player = player;
if (state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
{
this.exp = 0;
}
else
{
int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
this.exp = state.getBlock().getExpDrop(state, world, pos, bonusLevel);
}
}
示例2: BreakEvent
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public BreakEvent(int x, int y, int z, World world, Block block, int blockMetadata, EntityPlayer player)
{
super(x, y, z, world, block, blockMetadata);
this.player = player;
if (block == null || !ForgeHooks.canHarvestBlock(block, player, blockMetadata) || // Handle empty block or player unable to break block scenario
block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.func_77502_d(player)) // If the block is being silk harvested, the exp dropped is 0
{
this.exp = 0;
}
else
{
int meta = block.func_149643_k(world, x, y, z);
int bonusLevel = EnchantmentHelper.func_77517_e(player);
this.exp = block.getExpDrop(world, meta, bonusLevel);
}
}
示例3: BreakEvent
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public BreakEvent(int x, int y, int z, World world, Block block, int blockMetadata, EntityPlayer player)
{
super(x, y, z, world, block, blockMetadata);
this.player = player;
if (block == null || !ForgeHooks.canHarvestBlock(block, player, blockMetadata) || // Handle empty block or player unable to break block scenario
block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.getSilkTouchModifier(player)) // If the block is being silk harvested, the exp dropped is 0
{
this.exp = 0;
}
else
{
int meta = block.getDamageValue(world, x, y, z);
int bonusLevel = EnchantmentHelper.getFortuneModifier(player);
this.exp = block.getExpDrop(world, meta, bonusLevel);
}
}
示例4: checkBlockBreak
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public void checkBlockBreak(World world, EntityPlayer player, BlockPos pos, ItemStack stack, float strength, Block originalBlock,
EnumFacing side)
{
IBlockState state = world.getBlockState(pos);
Block breakBlock = state.getBlock();
Material material = originalBlock.getMaterial(state);
if (breakBlock.getMaterial(state) == material && ForgeHooks.canHarvestBlock(breakBlock, player, world, pos)
&& stack.canHarvestBlock(state))
{
float newStrength = ForgeHooks.blockStrength(state, player, world, pos);
if (newStrength > 0f && strength / newStrength <= 10f)
{
if ((double) breakBlock.getBlockHardness(state, world, pos) != 0.0D)
{
if (DamageHandler.handleDamage(false, state, stack, player))
{
BlockUtils.tryHarvestBlock(world, state, pos, side, player);
}
}
else
{
BlockUtils.tryHarvestBlock(world, state, pos, side, player);
}
}
}
}
示例5: onBreakSpeed
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
@SubscribeEvent
public void onBreakSpeed(BreakSpeed event)
{
if (event.block instanceof IBlockCustom)
{
BlockType type = ((IBlockCustom) event.block).getType(event.metadata);
if (type.toolType.isEmpty())
{
return;
}
ItemStack held = event.entityPlayer.getHeldItem();
if (held != null && !held.getItem().getToolClasses(held).contains(type.toolType))
{
event.newSpeed = ForgeHooks.canHarvestBlock(event.block, event.entityPlayer, event.metadata) ? 0.3f : 1;
}
}
}
示例6: determineBreakSpeed
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
private void determineBreakSpeed(PlayerEvent.BreakSpeed event) {
final int y = event.pos.getY();
if (y == -1) return; // Event specifies that 'y' might be -1 for unknown usage?
final IBlockState bs = event.state;
final Block block = bs.getBlock();
final int x = event.pos.getX();
final int z = event.pos.getZ();
final EntityPlayer player = event.entityPlayer;
if (stillBusy(player)) return;
if (!canUndo(event, event.pos, block, bs)) return;
// Duplicate logic to figure out what the *actual* break speed will be, so that we don't make this actual break speed too fast
float hardness = block.getBlockHardness(player.worldObj, event.pos);
if (hardness < 0.0F) {
// Block is invulnerable
return;
}
String heldName = DataUtil.getName(player.getHeldItem());
if (heldName == null) heldName = "";
if (heldName.toLowerCase(Locale.ROOT).startsWith("tconstruct:")) {
return; // avoid warp-speed issues
}
final float harvestingSpeed = ForgeHooks.canHarvestBlock(block, player, player.worldObj, event.pos) ? 30F : 100F;
final float max_true_speed = block.hasTileEntity(bs) ? MAX_TRUE_SPEED_TILEENTITY : MAX_TRUE_SPEED_STANDARD;
float true_speed = event.newSpeed / hardness / harvestingSpeed;
if (true_speed > max_true_speed) return;
float boost = max_true_speed * hardness * harvestingSpeed;
event.newSpeed = Math.max(event.newSpeed * boost, event.newSpeed);
event.newSpeed = Math.min(ANTI_WARP_SPEED, event.newSpeed);
// ... this code is wrong. It's suuuper fast for enderchests. Everything too complicated?
// Maybe just a single blind speed, and be done with it?
}
示例7: getPlayerRelativeBlockHardness
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
@Override
public float getPlayerRelativeBlockHardness(EntityPlayer player, World world, int x, int y, int z) {
int metadata = getMetadata(world, x, y, z);
float hardness = getBlockHardness(world, x, y, z);
if(hardness < 0.0F) {
return 0.0F;
}
if(!ForgeHooks.canHarvestBlock(this, player, metadata)) {
return player.getBreakSpeed(this, true, metadata, x, y, z) / hardness / 100F;
} else {
return player.getBreakSpeed(this, false, metadata, x, y, z) / hardness / 30F;
}
}
示例8: canHarvestBlock
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public boolean canHarvestBlock(EntityPlayer player, int meta)
{
BlockType type = getType(meta);
ItemStack held = player.getHeldItem();
int harvestLevel = getHarvestLevel(meta);
if (type.toolType.isEmpty() || held == null)
{
return ForgeHooks.canHarvestBlock(block, player, meta);
}
return held.getItem().getHarvestLevel(held, getHarvestTool(meta)) >= harvestLevel
&& held.getItem().getToolClasses(held).contains(type.toolType);
}
示例9: canHarvestBlock
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public boolean canHarvestBlock(final EntityPlayer player, final int meta) {
return ForgeHooks.canHarvestBlock(getBlock(meta), player, meta);
}
示例10: breakExtraBlock
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public static void breakExtraBlock(ItemStack stack, World world, EntityPlayer player, BlockPos pos, BlockPos refPos) {
if(world.isAirBlock(pos)) {
return;
}
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(!ToolUtil.isToolEffective(stack, state)) {
return;
}
IBlockState refState = world.getBlockState(refPos);
float refStrength = ForgeHooks.blockStrength(refState, player, world, refPos);
float strength = ForgeHooks.blockStrength(state, player, world, pos);
if(!ForgeHooks.canHarvestBlock(block, player, world, pos) || refStrength / strength > 10f) {
return;
}
if(player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, pos, state, player);
if(block.removedByPlayer(state, world, pos, player, false)) {
block.onBlockDestroyedByPlayer(world, pos, state);
}
if(!world.isRemote) {
CrystalModNetwork.sendMCPacket(player, new SPacketBlockChange(world, pos));
}
return;
}
stack.onBlockDestroyed(world, state, pos, player);
if(!world.isRemote) {
int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos);
if(xp == -1) {
return;
}
TileEntity tileEntity = world.getTileEntity(pos);
if(block.removedByPlayer(state, world, pos, player, true))
{
block.onBlockDestroyedByPlayer(world, pos, state);
block.harvestBlock(world, player, pos, state, tileEntity, stack);
block.dropXpOnBlockBreak(world, pos, xp);
}
CrystalModNetwork.sendMCPacket(player, new SPacketBlockChange(world, pos));
}
else {
Minecraft.getMinecraft();
world.playBroadcastSound(2001, pos, Block.getStateId(state));
if(block.removedByPlayer(state, world, pos, player, true)) {
block.onBlockDestroyedByPlayer(world, pos, state);
}
stack.onBlockDestroyed(world, state, pos, player);
if(ItemStackTools.getStackSize(stack) == 0 && stack == player.getHeldItemMainhand()) {
ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, ItemStackTools.getEmptyStack());
}
Minecraft.getMinecraft().getConnection().sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, Minecraft
.getMinecraft().objectMouseOver.sideHit));
}
}
示例11: onBlockStartBreak
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
/**
* <<<< made with some help from Tinkers Construct and Spark's Hammers
* https://github.com/thebrightspark/SparksHammers/blob/b84bd178fe2bbe47b13a89ef9435b20f09e429a4/src/main/java/com/brightspark/sparkshammers/util/CommonUtils.java and
* https://github.com/SlimeKnights/TinkersConstruct
*/
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos posHit, EntityPlayer player) {
RayTraceResult ray = rayTrace(player.getEntityWorld(), player, false);
if (ray == null) {
return super.onBlockStartBreak(stack, posHit, player);
}
EnumFacing sideHit = ray.sideHit;
World world = player.getEntityWorld();
//use the shape builder to get region
List<BlockPos> shape;
if (sideHit == EnumFacing.UP || sideHit == EnumFacing.DOWN) {
shape = UtilShape.squareHorizontalHollow(posHit, RADIUS);
}
else if (sideHit == EnumFacing.EAST || sideHit == EnumFacing.WEST) {
shape = UtilShape.squareVerticalZ(posHit, RADIUS);
}
else {//has to be NORTHSOUTH
shape = UtilShape.squareVerticalX(posHit, RADIUS);
}
for (BlockPos posCurrent : shape) {
//first we validate
if (posHit.equals(posCurrent)) {
continue;
}
if (super.onBlockStartBreak(stack, new BlockPos(posCurrent), player)) {
continue;
}
IBlockState bsCurrent = world.getBlockState(posCurrent);
if (world.isAirBlock(posCurrent)) {
continue;
}
if (!mats.contains(bsCurrent.getMaterial())) {
continue;
}
Block blockCurrent = bsCurrent.getBlock();
if (!ForgeHooks.canHarvestBlock(blockCurrent, player, world, posCurrent)
|| bsCurrent.getBlock().canEntityDestroy(bsCurrent, world, posCurrent, player) == false
|| bsCurrent.getBlock().getBlockHardness(bsCurrent, world, posCurrent) < 0) {
continue;
}
//then we destroy
stack.onBlockDestroyed(world, bsCurrent, posCurrent, player);
if (world.isRemote) {//C
world.playEvent(2001, posCurrent, Block.getStateId(bsCurrent));
if (blockCurrent.removedByPlayer(bsCurrent, world, posCurrent, player, true)) {
blockCurrent.onBlockDestroyedByPlayer(world, posCurrent, bsCurrent);
}
stack.onBlockDestroyed(world, bsCurrent, posCurrent, player);//update tool damage
if (stack.getCount() == 0 && stack == player.getHeldItemMainhand()) {
ForgeEventFactory.onPlayerDestroyItem(player, stack, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
}
Minecraft.getMinecraft().getConnection().sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posCurrent, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
else if (player instanceof EntityPlayerMP) {//Server side, so this works
EntityPlayerMP mp = (EntityPlayerMP) player;
int xpGivenOnDrop = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, posCurrent);
if (xpGivenOnDrop >= 0) {
if (blockCurrent.removedByPlayer(bsCurrent, world, posCurrent, player, true)) {
TileEntity tile = world.getTileEntity(posCurrent);
blockCurrent.onBlockDestroyedByPlayer(world, posCurrent, bsCurrent);
blockCurrent.harvestBlock(world, player, posCurrent, bsCurrent, tile, stack);
blockCurrent.dropXpOnBlockBreak(world, posCurrent, xpGivenOnDrop);
}
mp.connection.sendPacket(new SPacketBlockChange(world, posCurrent));
}
}
}
return super.onBlockStartBreak(stack, posHit, player);
}
示例12: aoeBlockBreak
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
private void aoeBlockBreak(ItemStack stack, World world, BlockPos pos, EntityPlayer player)
{
if(world.isAirBlock(pos))
return;
if(!(player instanceof EntityPlayerMP))
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
IBlockState state = world.getBlockState(pos);
if(!isEffective(state) || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos))
return;
int event = ForgeHooks.onBlockBreakEvent(world, playerMP.interactionManager.getGameType(), playerMP, pos);
if(event == -1)
return;
stack.onBlockDestroyed(world, state, pos, player);
if(!world.isRemote)
{
state.getBlock().onBlockHarvested(world, pos, state, player);
if(state.getBlock().removedByPlayer(state, world, pos, player, true))
{
state.getBlock().onBlockDestroyedByPlayer(world, pos, state);
state.getBlock().harvestBlock(world, player, pos, state, world.getTileEntity(pos), stack);
state.getBlock().dropXpOnBlockBreak(world, pos, event);
}
playerMP.connection.sendPacket(new SPacketBlockChange(world, pos));
}
else //CLIENT
{
if(state.getBlock().removedByPlayer(state, world, pos, player, true))
state.getBlock().onBlockDestroyedByPlayer(world, pos, state);
ItemStack itemstack = player.getActiveItemStack();
if(itemstack != null)
{
itemstack.onBlockDestroyed(world, state, pos, player);
}
ClockworkPhase2.proxy.sendBlockDestroyPacket(pos);
}
}
示例13: aoeBlockBreak
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
private void aoeBlockBreak(ItemStack stack, World world, BlockPos pos, EntityPlayer player)
{
if(world.isAirBlock(pos))
return;
if(!(player instanceof EntityPlayerMP))
return;
EntityPlayerMP playerMP = (EntityPlayerMP) player;
IBlockState state = world.getBlockState(pos);
if(!isEffective(stack, state) || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos))
return;
int event = ForgeHooks.onBlockBreakEvent(world, playerMP.interactionManager.getGameType(), playerMP, pos);
if(event == -1)
return;
stack.onBlockDestroyed(world, state, pos, player);
if(!world.isRemote)
{
state.getBlock().onBlockHarvested(world, pos, state, player);
if(state.getBlock().removedByPlayer(state, world, pos, player, true))
{
state.getBlock().onBlockDestroyedByPlayer(world, pos, state);
state.getBlock().harvestBlock(world, player, pos, state, world.getTileEntity(pos), stack);
state.getBlock().dropXpOnBlockBreak(world, pos, event);
}
playerMP.connection.sendPacket(new SPacketBlockChange(world, pos));
}
else //CLIENT
{
if(state.getBlock().removedByPlayer(state, world, pos, player, true))
state.getBlock().onBlockDestroyedByPlayer(world, pos, state);
ItemStack itemstack = player.getActiveItemStack();
if(!itemstack.isEmpty())
{
itemstack.onBlockDestroyed(world, state, pos, player);
}
ClockworkPhase2.proxy.sendBlockDestroyPacket(pos);
}
}
示例14: harvestBlock
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
protected boolean harvestBlock(World world, int x, int y, int z, EntityPlayer player) {
if (world.isAirBlock(x, y, z)) {
return false;
}
EntityPlayerMP playerMP = null;
if (player instanceof EntityPlayerMP) {
playerMP = (EntityPlayerMP) player;
}
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (!(toolClasses.contains(block.getHarvestTool(meta)) || canHarvestBlock(block, player.getCurrentEquippedItem()))) {
return false;
}
if (!ForgeHooks.canHarvestBlock(block, player, meta)) {
return false;
}
BreakEvent event = null;
if (playerMP != null) {
event = ForgeHooks.onBlockBreakEvent(world, playerMP.theItemInWorldManager.getGameType(), playerMP, x, y, z);
if (event.isCanceled()) {
return false;
}
}
if (player.capabilities.isCreativeMode) {
if (!world.isRemote) {
block.onBlockHarvested(world, x, y, z, meta, player);
} else {
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) | (meta << 12));
}
if (block.removedByPlayer(world, player, x, y, z, false)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
}
if (!world.isRemote) {
playerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
Minecraft.getMinecraft().getNetHandler()
.addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
return true;
}
world.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) | (meta << 12));
if (!world.isRemote) {
block.onBlockHarvested(world, x, y, z, meta, player);
if (block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
block.harvestBlock(world, player, x, y, z, meta);
if (event != null) {
block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
}
}
playerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
if (block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
}
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
return true;
}
示例15: shouldDropItems
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public boolean shouldDropItems(World world, int x, int y, int z, int meta, EntityPlayer player, ItemStack stack) {
return ForgeHooks.canHarvestBlock(this, player, meta);
}