Skip to content

Conversation

Intybyte
Copy link
Contributor

@Intybyte Intybyte commented Aug 26, 2024

Describe in detail what your pull request accomplishes

Add a validator for waterlogged blocks and a relative tag

Related issues:

Checklist

  • Tested

@oh-noey
Copy link
Collaborator

oh-noey commented Aug 30, 2024

Please see @TylerS1066's comment on that issue

Upon some further discussion, I think it's best if we add a separate craft flag for maximum water (or possibly maximum liquid) rather than add an edge case that interprets waterlogged as water.

The issue is about limiting overall liquids not just waterlogging.

@Intybyte
Copy link
Contributor Author

Please see @TylerS1066's comment on that issue

Upon some further discussion, I think it's best if we add a separate craft flag for maximum water (or possibly maximum liquid) rather than add an edge case that interprets waterlogged as water.

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?

Comment on lines +23 to +60
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);
}
}
}
Copy link
Contributor

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

Copy link
Contributor Author

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

Comment on lines +84 to +91
public int getTotalBlocks(Map<Material, Deque<MovecraftLocation>> materialDequeMap) {
int amount = 0;
for (var locationList : materialDequeMap.values()) {
amount += locationList.size();
}

return amount;
}
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make waterlogged blocks count as water.

3 participants