本文整理匯總了Java中net.minecraft.block.state.IBlockState.getBlockHardness方法的典型用法代碼示例。如果您正苦於以下問題:Java IBlockState.getBlockHardness方法的具體用法?Java IBlockState.getBlockHardness怎麽用?Java IBlockState.getBlockHardness使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.block.state.IBlockState
的用法示例。
在下文中一共展示了IBlockState.getBlockHardness方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: delayForHardBlocks
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
@Override
public void delayForHardBlocks(BlockPos pos, Consumer<BlockPos> nextJob) {
World world = entity.getEntityWorld();
if (world.isAirBlock(pos)) {
return;
}
IBlockState state = world.getBlockState(pos);
if (!allowedToHarvest(state, world, pos, GeneralTools.getHarvester())) {
return;
}
Block block = state.getBlock();
if (block instanceof BlockLiquid) {
nextJob.accept(pos);
} else {
float hardness = state.getBlockHardness(world, pos);
if (hardness < Config.delayAtHardness) {
nextJob.accept(pos);
} else {
delay((int) (hardness * Config.delayFactor), () -> nextJob.accept(pos));
}
}
}
示例2: blockStrength
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
public static float blockStrength(IBlockState state, EntityPlayer player, World world, BlockPos pos)
{
float hardness = state.getBlockHardness(world, pos);
if (hardness < 0.0F)
{
return 0.0F;
}
if (!canHarvestBlock(state.getBlock(), player, world, pos))
{
return player.getDigSpeed(state, pos) / hardness / 100F;
}
else
{
return player.getDigSpeed(state, pos) / hardness / 30F;
}
}
示例3: doBlockInteraction
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
PlayerInteractionManager manager = drone.getFakePlayer().interactionManager;
if (!manager.isDestroyingBlock || !manager.receivedFinishDiggingPacket) { //is not destroying and is not acknowledged.
IBlockState blockState = worldCache.getBlockState(pos);
Block block = blockState.getBlock();
if (!ignoreBlock(block) && isBlockValidForFilter(worldCache, drone, pos, widget)) {
if (blockState.getBlockHardness(drone.world(), pos) < 0) {
addToBlacklist(pos);
drone.addDebugEntry("gui.progWidget.dig.debug.cantDigBlock", pos);
drone.setDugBlock(null);
return false;
}
manager.onBlockClicked(pos, EnumFacing.DOWN);
manager.blockRemoving(pos);
if (!manager.isDestroyingBlock) {
addToBlacklist(pos);
drone.addDebugEntry("gui.progWidget.dig.debug.cantDigBlock", pos);
drone.setDugBlock(null);
return false;
}
drone.setDugBlock(pos);
return true;
}
drone.setDugBlock(null);
return false;
} else {
return true;
}
}
示例4: onBlockDestroyed
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
if (!(entityLiving instanceof EntityPlayer)) return super.onBlockDestroyed(stack, world, state, pos, entityLiving);
EntityPlayer player = (EntityPlayer)entityLiving;
if (!world.isRemote && state.getBlockHardness(world, pos) != 0) {
stack.damageItem(1, player);
ArrayList<BlockPos> crushGroup = new ArrayList<>();
//check and break anything nearby of equal or lower hardness
for(int z=-1; z<=1; z++) {
for(int y=-1; y<=1; y++) {
for(int x=-1; x<=1; x++) {
if (x==0 && y==0 && z==0) continue;
BlockPos crushLocation = pos.add(x, y, z);
IBlockState toCrush = world.getBlockState(crushLocation);
if (toCrush.getBlockHardness(world, crushLocation) <= state.getBlockHardness(world, pos)) {
if (!BLACKLIST.contains(toCrush.getBlock())) {
crushGroup.add(crushLocation);
stack.damageItem(1, entityLiving);
}
}
}
}
}
for(BlockPos cur : crushGroup) {
if (player instanceof EntityPlayerMP) { //Should be true any time we reach this part of the code
ToolHelper.auxHarvestBlock(world, cur, (EntityPlayerMP)player);
}
}
}
return true;
}
示例5: onBlockDestroyed
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
/**
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
*/
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
{
stack.damageItem(2, entityLiving);
}
return true;
}
示例6: onBlockDestroyed
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
/**
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
*/
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
if (!worldIn.isRemote && (double)state.getBlockHardness(worldIn, pos) != 0.0D)
{
stack.damageItem(1, entityLiving);
}
return true;
}
示例7: getPlayerRelativeBlockHardness
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
@Deprecated
/**
* Get the hardness of this Block relative to the ability of the given player
*/
public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos)
{
float f = state.getBlockHardness(worldIn, pos);
return f < 0.0F ? 0.0F : (!player.canHarvestBlock(state) ? player.getDigSpeed(state) / f / 100.0F : player.getDigSpeed(state) / f / 30.0F);
}
示例8: getHardness
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
public static float getHardness(IBlockState block, World world) {
if (block.getBlock() == Blocks.COBBLESTONE){
return 2.1f;
}
if (block.getBlockHardness(world, new BlockPos(0, 0, 0)) == 0)
return 0;
return Math.min((block.getMaterial().isToolNotRequired() ? block.getBlockHardness(world, new BlockPos(0, 0, 0))
: block.getBlockHardness(world, new BlockPos(0, 0, 0)) * 1.9f) / 1.55f + 0.65f, 50f);
}
示例9: onBlockDestroyed
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
/**
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
*/
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
{
stack.damageItem(1, entityLiving);
}
return true;
}
示例10: auxHarvestBlock
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
/**
* Destroys and tries to harvest a block with the currently active tool, except that instead of calling
* onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
*/
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!
GameType gameType = player.interactionManager.getGameType();
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
if (exp == -1) {
return false;
} else {
IBlockState iblockstate = world.getBlockState(pos);
if (iblockstate.getBlockHardness(world, pos)<0) return false;
TileEntity tileentity = world.getTileEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
return false;
} else {
ItemStack stack = player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;
world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
boolean removed = false;
if (gameType==GameType.CREATIVE) {
removed = removeBlock(world, pos, player, false);
player.connection.sendPacket(new SPacketBlockChange(world, pos));
} else {
ItemStack itemstack1 = player.getHeldItemMainhand();
ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);
if (!itemstack1.isEmpty()) {
// itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
}
}
removed = removeBlock(world, pos, player, canHarvest);
if (removed && canHarvest) {
iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
}
}
// Drop experience
if (gameType!=GameType.CREATIVE && removed && exp > 0) {
iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
}
return removed;
}
}
}
示例11: canPush
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
/**
* Checks if the piston can push the given BlockState.
*/
public static boolean canPush(IBlockState blockStateIn, World worldIn, BlockPos pos, EnumFacing facing, boolean destroyBlocks)
{
Block block = blockStateIn.getBlock();
if (block == Blocks.OBSIDIAN)
{
return false;
}
else if (!worldIn.getWorldBorder().contains(pos))
{
return false;
}
else if (pos.getY() >= 0 && (facing != EnumFacing.DOWN || pos.getY() != 0))
{
if (pos.getY() <= worldIn.getHeight() - 1 && (facing != EnumFacing.UP || pos.getY() != worldIn.getHeight() - 1))
{
if (block != Blocks.PISTON && block != Blocks.STICKY_PISTON)
{
if (blockStateIn.getBlockHardness(worldIn, pos) == -1.0F)
{
return false;
}
if (blockStateIn.getMobilityFlag() == EnumPushReaction.BLOCK)
{
return false;
}
if (blockStateIn.getMobilityFlag() == EnumPushReaction.DESTROY)
{
return destroyBlocks;
}
}
else if (((Boolean)blockStateIn.getValue(EXTENDED)).booleanValue())
{
return false;
}
return !block.hasTileEntity();
}
else
{
return false;
}
}
else
{
return false;
}
}
示例12: damageBlock
import net.minecraft.block.state.IBlockState; //導入方法依賴的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;
}
示例13: damageBlock
import net.minecraft.block.state.IBlockState; //導入方法依賴的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;
}
示例14: getHardness
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
public static float getHardness(IBlockState state, World world, BlockPos pos) {
return state.getBlockHardness(world, pos) * (!state.getMaterial().isToolNotRequired() && !(state.getBlock() instanceof BlockStone) ? 12f : 5.5f);
}
示例15: canPush
import net.minecraft.block.state.IBlockState; //導入方法依賴的package包/類
/**
* Checks if the piston can push the given BlockState.
*/
public static boolean canPush(IBlockState blockStateIn, World worldIn, BlockPos pos, EnumFacing facing, boolean destroyBlocks)
{
Block block = blockStateIn.getBlock();
if (block == Blocks.OBSIDIAN)
{
return false;
}
else if (!worldIn.getWorldBorder().contains(pos))
{
return false;
}
else if (pos.getY() >= 0 && (facing != EnumFacing.DOWN || pos.getY() != 0))
{
if (pos.getY() <= worldIn.getHeight() - 1 && (facing != EnumFacing.UP || pos.getY() != worldIn.getHeight() - 1))
{
if (block != Blocks.PISTON && block != Blocks.STICKY_PISTON)
{
if (blockStateIn.getBlockHardness(worldIn, pos) == -1.0F)
{
return false;
}
if (blockStateIn.getMobilityFlag() == EnumPushReaction.BLOCK)
{
return false;
}
if (blockStateIn.getMobilityFlag() == EnumPushReaction.DESTROY)
{
return destroyBlocks;
}
}
else if (((Boolean)blockStateIn.getValue(EXTENDED)).booleanValue())
{
return false;
}
return !block.hasTileEntity(blockStateIn);
}
else
{
return false;
}
}
else
{
return false;
}
}