use of gregtech.api.items.toolitem.ToolMetaItem in project GregTech by GregTechCE.
the class TreeChopTask method run.
@Override
public boolean run() {
ItemStack itemInMainHand = this.player.getHeldItemMainhand();
boolean isPlayerNear = player.world == world && currentPos.distanceSq(player.posX, currentPos.getY(), player.posZ) <= 1024;
boolean isPlayerConnected = player.connection.netManager.isChannelOpen() && isPlayerNear;
if (!isPlayerConnected || itemInMainHand.isEmpty() || !isItemEqual(itemInMainHand)) {
return false;
}
ToolMetaItem<?> toolMetaItem = (ToolMetaItem<?>) itemStack.getItem();
MetaToolValueItem toolValueItem = toolMetaItem.getItem(itemStack);
if (toolValueItem == null) {
return false;
}
IToolStats toolStats = toolValueItem.getToolStats();
int damagePerBlockBreak = toolStats.getToolDamagePerBlockBreak(itemStack);
if (!finishedSearchingBlocks) {
this.finishedSearchingBlocks = !attemptSearchWoodBlocks() || this.visitedBlockPos.size() >= MAX_BLOCKS_TO_SEARCH;
if (finishedSearchingBlocks) {
this.woodBlockPos.sort(new WoodBlockComparator());
}
return true;
}
if (toolMetaItem.isUsable(itemInMainHand, damagePerBlockBreak) && tryBreakAny()) {
toolMetaItem.damageItem(itemInMainHand, damagePerBlockBreak, false);
return true;
}
return false;
}
use of gregtech.api.items.toolitem.ToolMetaItem in project GregTech by GregTechCE.
the class ToolSense method onBlockPreBreak.
@Override
public boolean onBlockPreBreak(ItemStack stack, BlockPos blockPos, EntityPlayer player) {
if (player.world.isRemote || player.capabilities.isCreativeMode) {
return false;
}
ToolMetaItem<?> toolMetaItem = (ToolMetaItem<?>) stack.getItem();
int damagePerBlockBreak = getToolDamagePerBlockBreak(stack);
for (int x = -5; x <= 5; x++) {
for (int z = -5; z <= 5; z++) {
for (int y = -5; y <= 5; y++) {
BlockPos offsetPos = blockPos.add(x, y, z);
IBlockState blockState = player.world.getBlockState(offsetPos);
if (player.world.isBlockModifiable(player, offsetPos) && toolMetaItem.isUsable(stack, damagePerBlockBreak)) {
if (blockState.getBlock() instanceof BlockCrops) {
player.world.playEvent(2001, offsetPos, Block.getStateId(blockState));
ToolUtility.applyHarvestBehavior(offsetPos, player);
toolMetaItem.damageItem(stack, damagePerBlockBreak, false);
} else if (blockState.getMaterial() == Material.PLANTS || blockState.getMaterial() == Material.LEAVES || blockState.getMaterial() == Material.VINE) {
player.world.playEvent(2001, offsetPos, Block.getStateId(blockState));
player.world.setBlockToAir(offsetPos);
toolMetaItem.damageItem(stack, damagePerBlockBreak, false);
}
}
}
}
}
return true;
}
use of gregtech.api.items.toolitem.ToolMetaItem in project GregTech by GregTechCE.
the class ToolJackHammer method onBlockDestroyed.
@Override
public void onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entity) {
if (entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) {
EntityPlayer entityPlayer = (EntityPlayer) entity;
EnumFacing sideHit = ToolUtility.getSideHit(world, pos, entityPlayer);
int damagePerBlockBreak = getToolDamagePerBlockBreak(stack);
JackHammerMode jackHammerMode = MODE_SWITCH_BEHAVIOR.getModeFromItemStack(stack);
EnumFacing horizontalFacing = entity.getHorizontalFacing();
int xSizeExtend = (jackHammerMode.getHorizontalSize() - 1) / 2;
int ySizeExtend = (jackHammerMode.getVerticalSize() - 1) / 2;
for (int x = -xSizeExtend; x <= xSizeExtend; x++) {
for (int y = -ySizeExtend; y <= ySizeExtend; y++) {
// do not check center block - it's handled now
if (x == 0 && y == 0)
continue;
BlockPos offsetPos = rotate(pos, x, y, sideHit, horizontalFacing);
IBlockState blockState = world.getBlockState(offsetPos);
if (world.isBlockModifiable(entityPlayer, offsetPos) && blockState.getBlock().canHarvestBlock(world, offsetPos, entityPlayer) && blockState.getPlayerRelativeBlockHardness(entityPlayer, world, offsetPos) > 0.0f && stack.canHarvestBlock(blockState)) {
GTUtility.harvestBlock(world, offsetPos, entityPlayer);
((ToolMetaItem) stack.getItem()).damageItem(stack, damagePerBlockBreak, false);
}
}
}
}
}
Aggregations