Conversation
|
Please see @TylerS1066's comment on that issue
The issue is about limiting overall liquids not just waterlogging. |
So I just need to adda check for liquids too and I should be done right? |
| boolean blockNumber = !allowedAmountString.startsWith("N"); //if false use block percentage | ||
| final String errorMessage = "Too many waterlogged blocks on craft"; | ||
|
|
||
| int maxAmount; | ||
| try { | ||
| if (blockNumber) { | ||
| maxAmount = Integer.parseInt(allowedAmountString.substring(1)); | ||
| } else { | ||
| maxAmount = Integer.parseInt(allowedAmountString); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| return Result.failWithMessage("liquidsMaxAmount wasn't configurated properly"); | ||
| } | ||
|
|
||
| final int liquidBlocks = getLiquidAmount(materialDequeMap, world); | ||
| if (liquidBlocks == 0) | ||
| return Result.succeed(); | ||
|
|
||
| if (maxAmount == 0) | ||
| return Result.failWithMessage(errorMessage); | ||
|
|
||
| if(blockNumber) { | ||
| if (liquidBlocks <= maxAmount) { | ||
| return Result.succeed(); | ||
| } else { | ||
| return Result.failWithMessage(errorMessage); | ||
| } | ||
| } else { | ||
| int allBlocks = getTotalBlocks(materialDequeMap); | ||
| double percentage = ((double) liquidBlocks / allBlocks) * 100; | ||
|
|
||
| if (percentage <= maxAmount) { | ||
| return Result.succeed(); | ||
| } else { | ||
| return Result.failWithMessage(errorMessage); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This should utilize RequiredBlockEntry's logic
There was a problem hiding this comment.
How so, there is only a max amount no min amount in this case
...a/net/countercraft/movecraft/processing/tasks/detection/validators/LiquidBlockValidator.java
Outdated
Show resolved
Hide resolved
| public int getTotalBlocks(Map<Material, Deque<MovecraftLocation>> materialDequeMap) { | ||
| int amount = 0; | ||
| for (var locationList : materialDequeMap.values()) { | ||
| amount += locationList.size(); | ||
| } | ||
|
|
||
| return amount; | ||
| } |
There was a problem hiding this comment.
This should be calculated for us, look at how FlyBlockValidator does this.
There was a problem hiding this comment.
It does the same exact thing, just using a functional one liner approach:
int total = materialDequeMap.values().parallelStream().mapToInt(Deque::size).sum();Prefer this?
Describe in detail what your pull request accomplishes
Add a validator for waterlogged blocks and a relative tag
Related issues:
Checklist