-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/watertagged #704
base: main
Are you sure you want to change the base?
Feature/watertagged #704
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should utilize RequiredBlockEntry
's logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be calculated for us, look at how FlyBlockValidator
does this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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