Skip to content

Commit

Permalink
Added holder instanceof DoubleChest check to converter (#6823)
Browse files Browse the repository at this point in the history
* Added holder instanceof DoubleChest check to IntentoryHolder - Location converter

* Apply suggestions from code review

Co-authored-by: sovdee <[email protected]>

* Change ternary to if statements

* Fix indentation in test

* Address reviews

Co-authored-by: _tud <[email protected]>

* Update src/main/java/ch/njol/skript/classes/data/DefaultConverters.java

Co-authored-by: _tud <[email protected]>

---------

Co-authored-by: sovdee <[email protected]>
Co-authored-by: Pikachu920 <[email protected]>
Co-authored-by: _tud <[email protected]>
  • Loading branch information
4 people authored Jul 1, 2024
1 parent 9f62586 commit 6ee4628
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public DefaultConverters() {}
return ((Block) holder).getLocation();
if (holder instanceof BlockState)
return BlockUtils.getLocation(((BlockState) holder).getBlock());
if (holder instanceof DoubleChest) {
DoubleChest doubleChest = (DoubleChest) holder;
if (doubleChest.getLeftSide() != null) {
return BlockUtils.getLocation(((BlockState) doubleChest.getLeftSide()).getBlock());
} else if (((DoubleChest) holder).getRightSide() != null) {
return BlockUtils.getLocation(((BlockState) doubleChest.getRightSide()).getBlock());
}
}
return null;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test "inventory holder location double chest":
set {_b::1} to the block at spawn of world "world"
set {_b::2} to the block north of {_b::1}
set {_prev::1} to type of block at {_b::1}
set {_prev::2} to type of block at {_b::2}

set block at {_b::1} to chest[facing=east;type=right]
set block at {_b::2} to chest[facing=east;type=left]

set {_inv} to inventory of {_b::1}
set {_holder} to holder of {_inv}

set {_a-loc} to location of {_holder}
set {_b-loc::*} to location of {_b::1} and location of {_b::2}

# clean up first in case assert fails
set block at {_b::1} to {_prev::1}
set block at {_b::2} to {_prev::2}

assert {_b-loc::*} contains {_a-loc} with "holder location of double chest differs from block location"

0 comments on commit 6ee4628

Please sign in to comment.