Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Fix BlockClick error check, for #47
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 25, 2018
1 parent 680f62e commit 3a4c86f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Expand Up @@ -116,18 +116,25 @@ public void onLeftClickBlock(InteractBlockEvent.Primary evt, @Root Player player
Optional<Location<World>> opt = evt.getTargetBlock().getLocation();
if (opt.isPresent()) {
event.location = new LocationTag(opt.get());
Vector3d point = evt.getInteractionPoint().get();
event.precise_location = new LocationTag(point, world);
event.intersection_point = new LocationTag(point.sub(opt.get().getPosition()));
event.impact_normal = new LocationTag(evt.getTargetSide().asOffset());
if (evt.getInteractionPoint().isPresent()) {
Vector3d point = evt.getInteractionPoint().get();
event.precise_location = new LocationTag(point, world);
event.intersection_point = new LocationTag(point.sub(opt.get().getPosition()));
event.impact_normal = new LocationTag(evt.getTargetSide().asOffset());
}
else {
BlockRayHit<World> brh = BlockRay.from(player).distanceLimit(Utilities.getHandReach(player)).build().end().get();
event.precise_location = new LocationTag(brh.getPosition(), world);
event.intersection_point = new LocationTag(brh.getPosition().sub(brh.getBlockPosition().toDouble()));
event.impact_normal = new LocationTag(brh.getNormal());
}
}
else {
BlockRayHit<World> brh = BlockRay.from(player)
.distanceLimit(Utilities.getHandReach(player)).build().end().get();
BlockRayHit<World> brh = BlockRay.from(player).distanceLimit(Utilities.getHandReach(player)).build().end().get();
event.location = new LocationTag(brh.getLocation());
event.precise_location = new LocationTag(brh.getPosition(), world);
event.intersection_point = new LocationTag(brh.getPosition().sub(brh.getBlockPosition().toDouble()));
event.impact_normal = new LocationTag(0, 0, 0);
event.impact_normal = new LocationTag(brh.getNormal());
}
event.cancelled = evt.isCancelled();
event.run();
Expand Down
Expand Up @@ -136,7 +136,7 @@ public void onRightClickBlock(InteractBlockEvent.Secondary evt, @Root Player pla
event.location = new LocationTag(brh.getLocation());
event.precise_location = new LocationTag(brh.getPosition(), world);
event.intersection_point = new LocationTag(brh.getPosition().sub(brh.getBlockPosition().toDouble()));
event.impact_normal = new LocationTag(0, 0, 0);
event.impact_normal = new LocationTag(brh.getNormal());
}
event.hInternal = evt.getHandType();
event.hand = new TextTag(Utilities.getIdWithoutDefaultPrefix(evt.getHandType().getId()));
Expand Down

0 comments on commit 3a4c86f

Please sign in to comment.