Skip to content

Commit

Permalink
Merge pull request #859 from JWJUN233233/fix/georesource
Browse files Browse the repository at this point in the history
fix #858
  • Loading branch information
StarWishsama authored May 18, 2024
2 parents 53a00c8 + 0e8202a commit 951bb5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import io.github.thebusybiscuit.slimefun4.utils.HeadTexture;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.OptionalInt;
import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -246,7 +248,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 +284,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> supplyMap = 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));
supplyMap.put(resource, supplies);
});

for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) {
GEOResource resource = resources.get(i);
int supplies = supplyMap.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 success = 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;

success = true;

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

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

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

0 comments on commit 951bb5f

Please sign in to comment.