Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

Commit

Permalink
Avoid causing exception when getDestroySpeed needs real block pos
Browse files Browse the repository at this point in the history
  • Loading branch information
ISNing committed Jul 21, 2023
1 parent 66df05c commit 1bcae16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/main/java/weather2/util/WeatherUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,21 @@ public static boolean isOceanBlock(Block blockID)
return false;
}

public static boolean isSolidBlock(Block id)
{
public static boolean isSolidBlock(Block id) {
return (id == Blocks.STONE ||
id == Blocks.COBBLESTONE ||
id == Blocks.SANDSTONE);
}

public static boolean shouldGrabBlock(Level parWorld, BlockState state)
{
try
{
public static boolean shouldGrabBlock(Level parWorld, BlockState state, BlockPos pos) {
try {
ItemStack itemStr = new ItemStack(Items.DIAMOND_AXE);

Block block = state.getBlock();

boolean result = true;

if (ConfigTornado.Storm_Tornado_GrabCond_List)
{
if (ConfigTornado.Storm_Tornado_GrabCond_List) {
try {
result = canGrabViaLists(state);
} catch (Exception e) {
Expand All @@ -198,7 +194,7 @@ public static boolean shouldGrabBlock(Level parWorld, BlockState state)
} else {

//float strVsBlock = block.getBlockHardness(block.defaultBlockState(), parWorld, new BlockPos(0, 0, 0)) - (((itemStr.getStrVsBlock(block.defaultBlockState()) - 1) / 4F));
float strVsBlock = state.getDestroySpeed(parWorld, new BlockPos(0, 0, 0)) - (((itemStr.getDestroySpeed(block.defaultBlockState()) - 1) / 4F));
float strVsBlock = state.getDestroySpeed(parWorld, pos) - (((itemStr.getDestroySpeed(block.defaultBlockState()) - 1) / 4F));

//System.out.println(strVsBlock);
if (/*block.getHardness() <= 10000.6*/ (strVsBlock <= strMax && strVsBlock >= strMin) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public boolean canGrab(Level parWorld, BlockState state, BlockPos pos)
state.getBlock() != Blocks.FIRE &&
//TODO: 1.14 uncomment
/*state.getBlock() != CommonProxy.blockRepairingBlock &&*/
WeatherUtil.shouldGrabBlock(parWorld, state) &&
WeatherUtil.shouldGrabBlock(parWorld, state, pos) &&
!isBlockGrabbingBlocked(parWorld, state, pos))
{
return canGrabEventCheck(parWorld, state, pos);
Expand Down

0 comments on commit 1bcae16

Please sign in to comment.