-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
…chRobotic and TechCollector in a given chunk (default: 100)
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.
Not sure that's how I would implement it, I'd look for a more performant and cleaner way.
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; | ||
} |
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.
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.
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.
Not sure how to implement your suggestion, could you help with that part? Or do you have any examples of these mechanisms?
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)"); | ||
} |
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.
I would do something to help the readability of this
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)"); |
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.
Readability and potentially abstract this?
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)"); | ||
} |
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.
Readability and potentially abstraction
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)"); | ||
} |
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.
Readability and potential abstraction
And I'll look into a way to make them more performant |
new PR: #42 |
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.