Skip to content

Commit

Permalink
fix #858
Browse files Browse the repository at this point in the history
  • Loading branch information
JWJUN233233 committed Apr 26, 2024
1 parent c36e4c2 commit 841fbfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.OptionalInt;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
Expand Down Expand Up @@ -246,7 +242,7 @@ private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x,
* @param block
* The {@link Block} which the scan starts at
* @param page
* The page to display
* The zero-based page to display
*/
public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
if (Slimefun.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) {
Expand Down Expand Up @@ -282,12 +278,20 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) {
resources.sort(Comparator.comparing(a -> a.getName(p).toLowerCase(Locale.ROOT)));

int index = 10;
int pages = (resources.size() - 1) / 36 + 1;
int pages = (int) (Math.ceil((double) resources.size() / 36) + 1);

for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
Map<GEOResource, Integer> suppliemap = new HashMap<>();

// if resource is not generated, generate the first
resources.forEach(resource -> {
OptionalInt optional = getSupplies(resource, block.getWorld(), x, z);
int supplies = optional.orElseGet(() -> generate(resource, block.getWorld(), x, block.getY(), z));
suppliemap.put(resource, supplies);
});

for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
int supplies = suppliemap.get(resource);
String suffix = Slimefun.getLocalization()
.getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ public void onResult(SlimefunChunkData result) {
}

private void start(@Nonnull Block b, @Nonnull BlockMenu inv) {
boolean succeed = Slimefun.getRegistry().getGEOResources().values().isEmpty();
for (GEOResource resource : Slimefun.getRegistry().getGEOResources().values()) {
if (resource.isObtainableFromGEOMiner()) {
OptionalInt optional = Slimefun.getGPSNetwork()
.getResourceManager()
.getSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4);

if (!optional.isPresent()) {
updateHologram(b, "&4需要先进行地形扫描!");
return;
}
if (optional.isEmpty()) continue;

succeed = true;

int supplies = optional.getAsInt();
if (supplies > 0) {
Expand All @@ -370,6 +370,11 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) {
}
}

if (!succeed) {
updateHologram(b, "&4需要先进行地形扫描!");
return;
}

updateHologram(b, "&7开采完成");
}
}

0 comments on commit 841fbfa

Please sign in to comment.