Skip to content

Commit

Permalink
Fix tripwire hooks counting all attached strings
Browse files Browse the repository at this point in the history
(cherry picked from commit 779d7dc)
  • Loading branch information
FrankHeijden committed Mar 5, 2022
1 parent ec53610 commit 13a51ff
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public void onBlockPlace(BlockPlaceEvent event) {
var player = event.getPlayer();

// In case of BlockMultiPlaceEvent, we may need to take a different delta.
// A closing tripwire hook triggers a BlockMultiPlaceEvent for all attached strings,
// but since they already exist in the world we do not need to count them.
var delta = 0;
if (event instanceof BlockMultiPlaceEvent) {
if (event instanceof BlockMultiPlaceEvent && material != Material.TRIPWIRE_HOOK) {
List<BlockState> replacedBlockStates = ((BlockMultiPlaceEvent) event).getReplacedBlockStates();
for (BlockState state : replacedBlockStates) {
if (BlockUtils.isSameChunk(location.getBlockX(), location.getBlockZ(), state.getX(), state.getZ())) {
Expand Down Expand Up @@ -87,7 +89,9 @@ public void onBlockPlaceMonitor(BlockPlaceEvent event) {
var player = event.getPlayer();

// In case of BlockMultiPlaceEvent, we need to update the cache differently.
if (event instanceof BlockMultiPlaceEvent) {
// A closing tripwire hook triggers a BlockMultiPlaceEvent for all attached strings,
// but since they already exist in the world we do not need to count them.
if (event instanceof BlockMultiPlaceEvent && material != Material.TRIPWIRE_HOOK) {
List<BlockState> replacedBlockStates = ((BlockMultiPlaceEvent) event).getReplacedBlockStates();
for (BlockState state : replacedBlockStates) {
var loc = state.getLocation();
Expand Down

0 comments on commit 13a51ff

Please sign in to comment.