本文整理汇总了Java中net.minecraftforge.common.ForgeHooks.onBlockBreakEvent方法的典型用法代码示例。如果您正苦于以下问题:Java ForgeHooks.onBlockBreakEvent方法的具体用法?Java ForgeHooks.onBlockBreakEvent怎么用?Java ForgeHooks.onBlockBreakEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.common.ForgeHooks
的用法示例。
在下文中一共展示了ForgeHooks.onBlockBreakEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blockDestroy
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
/**
* ブロックを破壊します
*
* @param world world
* @param x x座標
* @param y y座標
* @param z z座標
* @param player プレイヤー
* @param centerBlock 中心のブロック
* @param cX 中心のブロックのx座標
* @param cY 中心のブロックのy座標
* @param cZ 中心のブロックのz座標
* @param toolStack 破壊に使用したツールのItemStack
*/
private void blockDestroy(World world, int x, int y, int z, EntityPlayerMP player, Block centerBlock, int cX, int cY, int cZ, ItemStack toolStack) {
if (!world.isAirBlock(x, y, z)) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (canDestroyBlock(toolStack, block, meta) && (centerBlock.getBlockHardness(world, cX, cY, cZ) - block.getBlockHardness(world, x, y, z)) <= 3F) {
BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z);
if (!event.isCanceled()) {
block.onBlockHarvested(world, x, y, z, meta, player);
if (block.removedByPlayer(world, player, x, y, z, false)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
block.harvestBlock(world, player, x, y, z, meta);
}
if (!world.isRemote) {
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
}
}
}
}
}
示例2: breakBlockAsPlayer
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
/**
* Breaks the block as a player, and thus drops the item(s) from it
*/
public static void breakBlockAsPlayer(World world, BlockPos pos, EntityPlayerMP playerMP, ItemStack toolStack)
{
PlayerInteractionManager manager = playerMP.interactionManager;
int exp = ForgeHooks.onBlockBreakEvent(world, manager.getGameType(), playerMP, pos);
if (exp != -1)
{
IBlockState stateExisting = world.getBlockState(pos);
Block blockExisting = stateExisting.getBlock();
blockExisting.onBlockHarvested(world, pos, stateExisting, playerMP);
boolean harvest = blockExisting.removedByPlayer(stateExisting, world, pos, playerMP, true);
if (harvest)
{
blockExisting.onBlockDestroyedByPlayer(world, pos, stateExisting);
blockExisting.harvestBlock(world, playerMP, pos, stateExisting, world.getTileEntity(pos), toolStack);
}
}
}
示例3: harvest
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
private boolean harvest(EntityPlayerMP player, int x, int y, int z) {
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(worldObj, player.theItemInWorldManager.getGameType(), player, x, y, z);
if (event.isCanceled()) {
return false;
} else {
Block block = worldObj.getBlock(x, y, z);
int meta = worldObj.getBlockMetadata(x, y, z);
if (block.getBlockHardness(worldObj, x, y, z) < 0) return false;
worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (worldObj.getBlockMetadata(x, y, z) << 12));
block.onBlockHarvested(worldObj, x, y, z, meta, player);
boolean success = block.removedByPlayer(worldObj, player, x, y, z, true);
if (success) {
block.onBlockDestroyedByPlayer(worldObj, x, y, z, meta);
block.harvestBlock(worldObj,player, x, y, z, meta);
block.dropXpOnBlockBreak(worldObj, x, y, z, event.getExpToDrop() != 0 ? event.getExpToDrop() : block.getExpDrop(worldObj, meta, 0));
}
return success;
}
}
示例4: doMining
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
void doMining(World world, EntityPlayerMP player, int x, int y, int z) // Calling this 27 times, to blast mine a 3x3x3 area
{
Block toBeBroken = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (toBeBroken.getBlockHardness(world, x, y, z) == -1) { return; } // Unbreakable
if (toBeBroken.getHarvestLevel(meta) > 1) { return; }
if (toBeBroken.getMaterial() == Material.water) { return; }
if (toBeBroken.getMaterial() == Material.lava) { return; }
if (toBeBroken.getMaterial() == Material.air) { return; }
if (toBeBroken.getMaterial() == Material.portal) { return; }
// Need to do checks here against invalid blocks
if (toBeBroken == Blocks.water) { return; }
if (toBeBroken == Blocks.flowing_water) { return; }
if (toBeBroken == Blocks.lava) { return; }
if (toBeBroken == Blocks.flowing_lava) { return; }
if (toBeBroken == Blocks.obsidian) { return; }
if (toBeBroken == Blocks.mob_spawner) { return; }
// Crashing blocks: Redstone Lamp, Extended Piston
// They're likely trying to drop things that cannot be dropped (active states of themselves)
//WorldSettings.GameType gametype = WorldSettings.GameType.getByName("survival");
WorldSettings.GameType gametype = world.getWorldInfo().getGameType();
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, gametype, player, x, y, z);
if (event.isCanceled()) { return; } // Not allowed to do this
//toBeBroken.dropBlockAsItem(world, x, x, z, meta, 0); // The last one is Fortune
boolean removalSuccess = world.setBlockToAir(x, y, z);
if (removalSuccess) { toBeBroken.onBlockDestroyedByPlayer(world, x, y, z, meta); }
Item preBlockItem = toBeBroken.getItemDropped(meta, player.getRNG(), 0);
if (preBlockItem == null) { return; } // Item doesn't exist
ItemStack blockItem = new ItemStack(preBlockItem);
blockItem.setItemDamage(meta);
EntityItem entityItem = new EntityItem(world, x, y + 0.5d, z, blockItem);
entityItem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityItem);
}
示例5: breakBlockForMaterial
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
private void breakBlockForMaterial(Material material, World world, int x, int y, int z, EntityPlayer player) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (material == block.getMaterial() && block.getBlockHardness(world, x, y, z) >= 0) {
if (player instanceof EntityPlayerMP) {
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).theItemInWorldManager.getGameType(), (EntityPlayerMP) player, x, y, z);
if (event.isCanceled())
return;
if (!world.isRemote) {
ArrayList<ItemStack> drops = block.getDrops(world, x, y, z, meta, 0);
world.setBlockToAir(x, y, z);
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
Random rand = new Random();
for (ItemStack i : drops) {
float f = 0.7F;
double d = (double) (rand.nextFloat()*f)+(double) (1.0F-f)*0.5D;
double d1 = (double) (rand.nextFloat()*f)+(double) (1.0F-f)*0.5D;
double d2 = (double) (rand.nextFloat()*f)+(double) (1.0F-f)*0.5D;
EntityItem entityitem = new EntityItem(world, (double) x+d, (double) y+d1, (double) z+d2, i);
entityitem.delayBeforeCanPickup = 5;
world.spawnEntityInWorld(entityitem);
}
} else { //FIXME
block.addDestroyEffects(world, x, y, z, meta, Minecraft.getMinecraft().effectRenderer);
world.playSoundEffect((double) x+0.5D, (double) y+0.5D, (double) z+0.5D, block.stepSound.getBreakSound(), 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
block.onBlockDestroyedByPlayer(world, x,y,z, meta);
}
}
}
}
示例6: harvestBlock
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public static void harvestBlock(World world, int x, int y, int z, EntityPlayer entityPlayer){
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (!(entityPlayer instanceof EntityPlayerMP))
return;
EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
if(!ForgeEventFactory.doPlayerHarvestCheck(player, block, isToolEffective(player.getCurrentEquippedItem(), world, x, y, z)))
if(!player.capabilities.isCreativeMode)
return;
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z);
if(event.isCanceled())
return;
if(!world.isRemote){ //Server-side: Simulating ItemInWorldManager
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
if(!player.capabilities.isCreativeMode && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
block.harvestBlock(world, player, x, y, z, meta);
block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
}
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + meta << 12);
}
}else { //Client-side: Simulating PlayerControllerMP
if(block.removedByPlayer(world, player, x, y ,z, true))
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
}
}
示例7: onBlockStartBreak
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
World world = player.getEntityWorld();
if (!world.isRemote && player instanceof EntityPlayerMP) {
RayTraceResult rt = this.rayTrace(world, player, false);
if (rt.typeOfHit == RayTraceResult.Type.BLOCK) {
EnumFacing side = rt.sideHit;
List<BlockPos> extraBlocks = getExtraBlocks(world, rt, player);
for (BlockPos pos2 : extraBlocks) {
IBlockState state = world.getBlockState(pos2);
if (!world.isBlockLoaded(pos2) || !player.canPlayerEdit(pos2, side, itemstack) || !(state.getBlock().canHarvestBlock(world, pos2, player))) {
continue;
}
if (player.capabilities.isCreativeMode) {
state.getBlock().onBlockHarvested(world, pos2, state, player);
if (state.getBlock().removedByPlayer(state, world, pos2, player, false)) {
state.getBlock().onBlockDestroyedByPlayer(world, pos2, state);
}
} else {
int xp = ForgeHooks.onBlockBreakEvent(world, ((EntityPlayerMP) player).interactionManager.getGameType(), (EntityPlayerMP) player, pos2);
state.getBlock().onBlockHarvested(world, pos2, state, player);
this.onBlockDestroyed(itemstack, world, state, pos2, player);
if (state.getBlock().removedByPlayer(state, world, pos2, player, true)) {
state.getBlock().onBlockDestroyedByPlayer(world, pos2, state);
state.getBlock().harvestBlock(world, player, pos2, state, world.getTileEntity(pos2), itemstack);
state.getBlock().dropXpOnBlockBreak(world, pos2, xp);
}
}
world.playEvent(2001, pos, Block.getStateId(state));
((EntityPlayerMP) player).connection.sendPacket(new SPacketBlockChange(world, pos));
}
}
}
return false;
}
示例8: onImpact
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
@Override
public void onImpact(MovingObjectPosition target)
{
if (target.entityHit != null) // We hit a living thing!
{
// Damage
target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), (float)this.damage);
}
else // Hit the terrain
{
Block block = this.worldObj.getBlock(target.blockX, target.blockY, target.blockZ);
int meta = this.worldObj.getBlockMetadata(target.blockX, target.blockY, target.blockZ);
boolean breakThis = true;
// Checking here against invalid blocks
if (block == Blocks.bedrock) { breakThis = false; }
else if (block == Blocks.water) { breakThis = false; }
else if (block == Blocks.flowing_water) { breakThis = false; }
else if (block == Blocks.lava) { breakThis = false; }
else if (block == Blocks.flowing_lava) { breakThis = false; }
else if (block == Blocks.obsidian) { breakThis = false; }
else if (block == Blocks.mob_spawner) { breakThis = false; }
else if (block.getMaterial() == Material.water) { breakThis = false; }
else if (block.getMaterial() == Material.lava) { breakThis = false; }
else if (block.getMaterial() == Material.air) { breakThis = false; }
else if (block.getMaterial() == Material.portal) { breakThis = false; }
else if (block.getHarvestLevel(meta) > 0) { breakThis = false; }
else if (block.getBlockHardness(this.worldObj, target.blockX, target.blockY, target.blockZ) > 3) { breakThis = false; }
if (this.shootingEntity instanceof EntityPlayerMP)
{
WorldSettings.GameType gametype = this.worldObj.getWorldInfo().getGameType();
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(this.worldObj, gametype, (EntityPlayerMP) this.shootingEntity, target.blockX, target.blockY, target.blockZ);
if (event.isCanceled()) { breakThis = false; } // Not allowed to do this
}
if (breakThis) // Nothing preventing us from breaking this block!
{
this.worldObj.setBlockToAir(target.blockX, target.blockY, target.blockZ);
block.dropBlockAsItem(this.worldObj, target.blockX, target.blockY, target.blockZ, meta, 0);
}
}
// SFX
for (int i = 0; i < 4; ++i) { this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); }
this.worldObj.playSoundAtEntity(this, Block.soundTypeGravel.getBreakSound(), 1.0F, 1.0F);
this.setDead(); // Hit something, so begone.
}
示例9: 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));
}
}
示例10: hasBreakPermission
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public static boolean hasBreakPermission(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityPlayerMP player) {
return hasEditPermission(pos, player) && !(ForgeHooks.onBlockBreakEvent(world, player.interactionManager.getGameType(), player, pos) == -1);
}
示例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: tryHarvestBlock
import net.minecraftforge.common.ForgeHooks; //导入方法依赖的package包/类
public boolean tryHarvestBlock(int p_73084_1_, int p_73084_2_, int p_73084_3_)
{
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, p_73084_1_, p_73084_2_, p_73084_3_);
if (event.isCanceled())
{
return false;
}
else
{
ItemStack stack = thisPlayerMP.getCurrentEquippedItem();
if (stack != null && stack.getItem().onBlockStartBreak(stack, p_73084_1_, p_73084_2_, p_73084_3_, thisPlayerMP))
{
return false;
}
Block block = this.theWorld.getBlock(p_73084_1_, p_73084_2_, p_73084_3_);
if (block == Blocks.air)
{
return false; // CraftBukkit - A plugin set block to air without cancelling
}
int l = this.theWorld.getBlockMetadata(p_73084_1_, p_73084_2_, p_73084_3_);
this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, p_73084_1_, p_73084_2_, p_73084_3_, Block.getIdFromBlock(block) + (this.theWorld.getBlockMetadata(p_73084_1_, p_73084_2_, p_73084_3_) << 12));
boolean flag = false;
if (this.isCreative())
{
flag = this.removeBlock(p_73084_1_, p_73084_2_, p_73084_3_);
this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(p_73084_1_, p_73084_2_, p_73084_3_, this.theWorld));
}
else
{
ItemStack itemstack = this.thisPlayerMP.getCurrentEquippedItem();
boolean flag1 = block.canHarvestBlock(thisPlayerMP, l);
if (itemstack != null)
{
itemstack.func_150999_a(this.theWorld, block, p_73084_1_, p_73084_2_, p_73084_3_, this.thisPlayerMP);
if (itemstack.stackSize == 0)
{
this.thisPlayerMP.destroyCurrentEquippedItem();
}
}
flag = this.removeBlock(p_73084_1_, p_73084_2_, p_73084_3_, flag1);
if (flag && flag1)
{
block.harvestBlock(this.theWorld, this.thisPlayerMP, p_73084_1_, p_73084_2_, p_73084_3_, l);
}
}
// Drop experience
if (!this.isCreative() && flag && event != null)
{
block.dropXpOnBlockBreak(this.theWorld, p_73084_1_, p_73084_2_, p_73084_3_, event.getExpToDrop());
}
return flag;
}
}