當前位置: 首頁>>代碼示例>>Java>>正文


Java Block.harvestBlock方法代碼示例

本文整理匯總了Java中net.minecraft.block.Block.harvestBlock方法的典型用法代碼示例。如果您正苦於以下問題:Java Block.harvestBlock方法的具體用法?Java Block.harvestBlock怎麽用?Java Block.harvestBlock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.block.Block的用法示例。


在下文中一共展示了Block.harvestBlock方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:64,代碼來源:BlockLauncher.java

示例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;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:73,代碼來源:TF2Util.java


注:本文中的net.minecraft.block.Block.harvestBlock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。