本文整理匯總了Java中net.minecraft.block.Block.removedByPlayer方法的典型用法代碼示例。如果您正苦於以下問題:Java Block.removedByPlayer方法的具體用法?Java Block.removedByPlayer怎麽用?Java Block.removedByPlayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.removedByPlayer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: damageBlock
import net.minecraft.block.Block; //導入方法依賴的package包/類
public static float damageBlock(BlockPos pos, EntityLivingBase living, World world, float damage) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || state.getMaterial() == Material.WATER || state.getMaterial() == Material.LAVA || state.getBlockHardness(world, pos) < 0)
return damage;
DestroyBlockEntry finalEntry = null;
int entryId = 0;
int emptyId = -1;
for (int i = 0; i < BlockEventBus.destroyProgress.size(); i++) {
DestroyBlockEntry entry = BlockEventBus.destroyProgress.get(i);
if (emptyId == -1 && entry == null)
emptyId = i;
if (entry != null && entry.world == world && entry.pos.equals(pos)) {
finalEntry = entry;
entryId = i;
break;
}
}
if (finalEntry == null) {
finalEntry = new DestroyBlockEntry(pos, world);
if (emptyId != -1) {
BlockEventBus.destroyProgress.set(emptyId, finalEntry);
entryId = emptyId;
} else {
BlockEventBus.destroyProgress.add(finalEntry);
entryId = BlockEventBus.destroyProgress.size() - 1;
}
}
/*if (block instanceof BlockChest) {
((TileEntityChest) world.getTileEntity(pos)).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, living.getRNG().nextLong());
}*/
float hardness = BlockLauncher.getHardness(state, world);
finalEntry.curDamage += damage;
if (living != null)
world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, (int) ((finalEntry.curDamage / hardness) * 10));
if (finalEntry.curDamage >= hardness) {
if (living != null && living instanceof EntityPlayer)
block.harvestBlock(world, (EntityPlayer) living, pos, state, null, ItemStack.EMPTY);
else {
block.dropBlockAsItem(world, pos, state, 0);
}
BlockEventBus.destroyProgress.remove(finalEntry);
boolean flag = (living == null || !(living instanceof EntityPlayer) && world.isAirBlock(pos)) || block.removedByPlayer(state, world, pos, (EntityPlayer) living, true);
if (flag) {
if (living != null) {
world.playEvent(2001, pos, Block.getStateId(state));
world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, -1);
}
block.onBlockDestroyedByPlayer(world, pos, state);
}
return finalEntry.curDamage - hardness;
}
return 0;
}
示例2: damageBlock
import net.minecraft.block.Block; //導入方法依賴的package包/類
public static float damageBlock(BlockPos pos, EntityLivingBase living, World world, ItemStack stack, int critical, float damage, Vec3d forwardVec, Explosion explosion) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || TF2ConfigVars.destTerrain == 0 || state.getBlockHardness(world, pos) < 0 ||
(!(living instanceof EntityPlayer) && !world.getGameRules().getBoolean("mobGriefing")) || (living instanceof EntityPlayer && !world.isBlockModifiable((EntityPlayer) living, pos)))
return 0;
DestroyBlockEntry finalEntry = null;
int entryId = 0;
int emptyId = -1;
for (int i = 0; i < TF2EventsCommon.destroyProgress.size(); i++) {
DestroyBlockEntry entry = TF2EventsCommon.destroyProgress.get(i);
if (emptyId == -1 && entry == null)
emptyId = i;
if (entry != null && entry.world == world && entry.pos.equals(pos)) {
finalEntry = entry;
entryId = i;
break;
}
}
if (finalEntry == null) {
finalEntry = new DestroyBlockEntry(pos, world);
if (emptyId != -1) {
TF2EventsCommon.destroyProgress.set(emptyId, finalEntry);
entryId = emptyId;
} else {
TF2EventsCommon.destroyProgress.add(finalEntry);
entryId = TF2EventsCommon.destroyProgress.size() - 1;
}
}
/*if (block instanceof BlockChest) {
((TileEntityChest) world.getTileEntity(pos)).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, living.getRNG().nextLong());
}*/
float hardness = TF2Util.getHardness(state, world, pos);
if (!stack.isEmpty() && stack.getItem() instanceof ItemSniperRifle && hardness > 100)
damage *= 3;
finalEntry.curDamage += damage;
if (living != null)
world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, (int) ((finalEntry.curDamage / hardness) * 10));
if (finalEntry.curDamage >= hardness) {
if (living != null && living instanceof EntityPlayer)
block.harvestBlock(world, (EntityPlayer) living, pos, state, null, stack);
else {
block.dropBlockAsItem(world, pos, state, 0);
block.onBlockExploded(world, pos, explosion);
}
TF2EventsCommon.destroyProgress.remove(finalEntry);
boolean flag = (living == null || !(living instanceof EntityPlayer) && world.isAirBlock(pos)) || block.removedByPlayer(state, world, pos, (EntityPlayer) living, true);
if (flag) {
if (living != null) {
world.playEvent(2001, pos, Block.getStateId(state));
world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, -1);
}
block.onBlockDestroyedByPlayer(world, pos, state);
if (forwardVec != null) {
RayTraceResult trace = world.rayTraceBlocks(living.getPositionVector().addVector(0, living.getEyeHeight(), 0), forwardVec, false, true, false);
if (trace != null)
damageBlock(trace.getBlockPos(), living, world, stack, critical, finalEntry.curDamage - hardness, forwardVec, explosion);
}
}
return finalEntry.curDamage - hardness;
}
return 0;
}
示例3: onPlayerDestroyBlock
import net.minecraft.block.Block; //導入方法依賴的package包/類
public boolean onPlayerDestroyBlock(BlockPos pos)
{
if (this.currentGameType.isAdventure())
{
if (this.currentGameType == GameType.SPECTATOR)
{
return false;
}
if (!this.mc.thePlayer.isAllowEdit())
{
ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack == null)
{
return false;
}
if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
{
return false;
}
}
}
ItemStack stack = mc.thePlayer.getHeldItemMainhand();
if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
{
return false;
}
if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
{
return false;
}
else
{
World world = this.mc.theWorld;
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.canUseCommandBlock())
{
return false;
}
else if (iblockstate.getMaterial() == Material.AIR)
{
return false;
}
else
{
world.playEvent(2001, pos, Block.getStateId(iblockstate));
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
if (!this.currentGameType.isCreative())
{
ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);
if (itemstack1.stackSize <= 0)
{
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
}
}
}
boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);
if (flag)
{
block.onBlockDestroyedByPlayer(world, pos, iblockstate);
}
return flag;
}
}
}