Skip to content
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

issues-36: Option to limit the use of machine #37

Closed
wants to merge 1 commit into from

Conversation

RelativoBR
Copy link
Collaborator

Correction of some misspelled words and inclusion of a quantity limiter of 4 MobTech machines per chuck, during the onPlace event, checking the type of material in the chunk.

…chRobotic and TechCollector in a given chunk (default: 100)
@RelativoBR RelativoBR requested a review from a team April 6, 2023 21:56
@RelativoBR RelativoBR requested review from JustAHuman-xD and removed request for a team April 6, 2023 22:00
Copy link
Contributor

@JustAHuman-xD JustAHuman-xD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that's how I would implement it, I'd look for a more performant and cleaner way.

Comment on lines +30 to +46
public static boolean containsLimitMaterialInChunk(Chunk chunk, int limit, Material type) {
int found = 0;
for(int y = -64; y <= 320; y++) {
for(int x = 0; x <= 15; x++) {
for(int z = 0; z <= 15; z++) {
if(chunk.getBlock(x, y, z).getType() == type) {
if(found > limit) {
return true;
} else {
found++;
}
}
}
}
}
return found > limit;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not do this like this it's laggy and just not a great way to do it, instead I would save a counter in the chunks storage and check that instead, this also would count non -slimefun blocks and just is not something you want to do. By getting the storage in the on place and adding to it, and the opposite when removing. Just an idea though there are definitely other ways.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to implement your suggestion, could you help with that part? Or do you have any examples of these mechanisms?

Comment on lines +309 to +317
if(UtilMachine.containsLimitMaterialInChunk(block.getChunk(),
Supreme.getSupremeOptions().getChunkLimitMaxTechRobotic(),
TECH_ROBOTIC.getType())){
BlockStorage.clearBlockInfo(block.getLocation(), true);
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.WHITE + "TechRobotic: " +
ChatColor.RED + "Reached the machine limit for Chuck (" +
Supreme.getSupremeOptions().getChunkLimitMaxTechRobotic() + "x Material)");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do something to help the readability of this

Comment on lines +333 to +340
if(UtilMachine.containsLimitMaterialInChunk(block.getChunk(),
Supreme.getSupremeOptions().getChunkLimitMaxTechMutation(),
TECH_MUTATION_I.getType())){
BlockStorage.clearBlockInfo(block.getLocation(), true);
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.WHITE + "TechMutation: " +
ChatColor.RED + "Reached the machine limit for Chuck (" +
Supreme.getSupremeOptions().getChunkLimitMaxTechMutation() + "x Material)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability and potentially abstract this?

Comment on lines +453 to +460
Supreme.getSupremeOptions().getChunkLimitMaxTechGenerator(),
TECH_GENERATOR.getType())){
BlockStorage.clearBlockInfo(block.getLocation(), true);
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.WHITE + "TechGenerator: " +
ChatColor.RED + "Reached the machine limit for Chuck (" +
Supreme.getSupremeOptions().getChunkLimitMaxTechGenerator() + "x Material)");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability and potentially abstraction

Comment on lines +216 to +224
if(UtilMachine.containsLimitMaterialInChunk(block.getChunk(),
Supreme.getSupremeOptions().getChunkLimitMaxMobTechCollector(),
MOB_TECH_COLLECTOR_MACHINE_I.getType())){
BlockStorage.clearBlockInfo(block.getLocation(), true);
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.WHITE + "MobTechCollector: " +
ChatColor.RED + "Reached the machine limit for Chuck (" +
Supreme.getSupremeOptions().getChunkLimitMaxMobTechCollector() + "x Material)");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability and potential abstraction

@JustAHuman-xD
Copy link
Contributor

And I'll look into a way to make them more performant

@RelativoBR
Copy link
Collaborator Author

new PR: #42

@RelativoBR RelativoBR closed this Apr 12, 2023
@RelativoBR RelativoBR deleted the issues-36-optimization-techgenerator branch April 12, 2023 18:09
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.

3 participants