forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff1deb9
commit a3bcbae
Showing
102 changed files
with
3,868 additions
and
3,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 0 additions & 107 deletions
107
src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAPI.java
This file was deleted.
Oops, something went wrong.
101 changes: 60 additions & 41 deletions
101
src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/GEOResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,66 @@ | ||
package io.github.thebusybiscuit.slimefun4.api.geo; | ||
|
||
import org.bukkit.Chunk; | ||
import org.bukkit.Keyed; | ||
import org.bukkit.World.Environment; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public interface GEOResource { | ||
|
||
/** | ||
* Returns the default supply of this resource in that biome | ||
* | ||
* @return The default supply found in a {@link Chunk} with the given {@link Biome} | ||
*/ | ||
int getDefaultSupply(Biome biome); | ||
|
||
/** | ||
* Name/ID e.g. "Oil" | ||
* | ||
* @return The name of this Resource | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* This {@link ItemStack} is used for display-purposes in the GEO Scanner. | ||
* But will also determine the Output of the GEO Miner, if it is applicable for that. | ||
* | ||
* @return The {@link ItemStack} version of this Resource. | ||
*/ | ||
ItemStack getItem(); | ||
|
||
/** | ||
* Measurement Unit e.g. "Bucket" / "Buckets". | ||
* Use the amount parameter to determine whether to use singular or plural. | ||
* | ||
* @return The Measurement Unit for this resource, will be treated like a suffix. | ||
*/ | ||
String getMeasurementUnit(int amount); | ||
|
||
/** | ||
* Returns whether this Resource can be obtained using a GEO Miner. | ||
* This will automatically add it to the GEO - Miner. | ||
* | ||
* @return Whether you can get obtain this resource using a GEO Miner. | ||
*/ | ||
boolean isObtainableFromGEOMiner(); | ||
|
||
} | ||
import me.mrCookieSlime.Slimefun.SlimefunPlugin; | ||
|
||
public interface GEOResource extends Keyed { | ||
|
||
/** | ||
* Returns the default supply of this resource in that biome | ||
* | ||
* @param environment The {@link Environment} this area is currently in (NORMAL / NETHER / THE_END) | ||
* @param biome The {@link Biome} this area is currently in. | ||
* | ||
* @return The default supply found in a {@link Chunk} with the given {@link Biome} | ||
*/ | ||
int getDefaultSupply(Environment environment, Biome biome); | ||
|
||
/** | ||
* Returns how much the value may deviate from the default supply (positive only). | ||
* | ||
* @return The deviation or spread of the supply | ||
*/ | ||
int getMaxDeviation(); | ||
|
||
/** | ||
* Returns the name of this resource (e.g. "Oil") | ||
* | ||
* @return The name of this Resource | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* This {@link ItemStack} is used for display-purposes in the GEO Scanner. | ||
* But will also determine the Output of the GEO Miner, if it is applicable for that. | ||
* | ||
* @return The {@link ItemStack} version of this Resource. | ||
*/ | ||
ItemStack getItem(); | ||
|
||
/** | ||
* Returns whether this Resource can be obtained using a GEO Miner. | ||
* This will automatically add it to the GEO - Miner. | ||
* | ||
* @return Whether you can get obtain this resource using a GEO Miner. | ||
*/ | ||
boolean isObtainableFromGEOMiner(); | ||
|
||
/** | ||
* Registers this GEO Resource | ||
*/ | ||
default void register() { | ||
SlimefunPlugin.getGPSNetwork().getResourceManager().register(this); | ||
} | ||
|
||
default String getName(Player p) { | ||
String name = SlimefunPlugin.getLocal().getResourceString(p, "resources." + getKey().getNamespace() + "." + getKey().getKey()); | ||
return name == null ? getName(): name; | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package io.github.thebusybiscuit.slimefun4.api.geo; | ||
|
||
import java.util.OptionalInt; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import io.github.thebusybiscuit.cscorelib2.config.Config; | ||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem; | ||
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem; | ||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; | ||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; | ||
import me.mrCookieSlime.Slimefun.SlimefunPlugin; | ||
import me.mrCookieSlime.Slimefun.api.BlockStorage; | ||
|
||
public class ResourceManager { | ||
|
||
private final int[] backgroundSlots = {0, 1, 2, 3, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}; | ||
private final ItemStack chunkTexture = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODQ0OWI5MzE4ZTMzMTU4ZTY0YTQ2YWIwZGUxMjFjM2Q0MDAwMGUzMzMyYzE1NzQ5MzJiM2M4NDlkOGZhMGRjMiJ9fX0="); | ||
private final Config config = new Config("plugins/Slimefun/resources.yml"); | ||
|
||
public void register(GEOResource resource) { | ||
boolean enabled = config.getOrSetDefault(resource.getKey().toString().replace(':', '.') + ".enabled", true); | ||
|
||
if (enabled) { | ||
SlimefunPlugin.getRegistry().getGEOResources().add(resource); | ||
} | ||
|
||
config.save(); | ||
} | ||
|
||
public OptionalInt getSupplies(GEOResource resource, World world, int x, int z) { | ||
String key = resource.getKey().toString().replace(':', '-'); | ||
|
||
String value = BlockStorage.getChunkInfo(world, x, z, key); | ||
|
||
if (value != null) { | ||
return OptionalInt.of(Integer.parseInt(value)); | ||
} | ||
else { | ||
return OptionalInt.empty(); | ||
} | ||
} | ||
|
||
public void setSupplies(GEOResource resource, World world, int x, int z, int value) { | ||
String key = resource.getKey().toString().replace(':', '-'); | ||
BlockStorage.setChunkInfo(world, x, z, key, String.valueOf(value)); | ||
} | ||
|
||
private int generate(GEOResource resource, World world, int x, int z) { | ||
Block block = world.getBlockAt(x << 4, 72, z << 4); | ||
int value = resource.getDefaultSupply(world.getEnvironment(), block.getBiome()); | ||
|
||
if (value > 0) { | ||
value += ThreadLocalRandom.current().nextInt(resource.getMaxDeviation()); | ||
} | ||
|
||
setSupplies(resource, world, x, z, value); | ||
return value; | ||
} | ||
|
||
public void scan(Player p, Block block) { | ||
if (SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) { | ||
SlimefunPlugin.getLocal().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600")); | ||
return; | ||
} | ||
|
||
int x = block.getX() >> 4; | ||
int z = block.getZ() >> 4; | ||
|
||
ChestMenu menu = new ChestMenu("&4" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.results")); | ||
|
||
for (int slot : backgroundSlots) { | ||
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); | ||
} | ||
|
||
menu.addItem(4, new CustomItem(chunkTexture, | ||
"&e" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.chunk"), | ||
"", | ||
"&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(), | ||
"&8\u21E8 &7X: " + x + " Z: " + z | ||
), ChestMenuUtils.getEmptyClickHandler()); | ||
|
||
int index = 10; | ||
|
||
for (GEOResource resource : SlimefunPlugin.getRegistry().getGEOResources().values()) { | ||
OptionalInt optional = getSupplies(resource, block.getWorld(), x, z); | ||
int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, z); | ||
String suffix = SlimefunPlugin.getLocal().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units"); | ||
|
||
ItemStack item = new CustomItem(resource.getItem(), "&r" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix); | ||
|
||
if (supplies > 1) { | ||
item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize(): supplies); | ||
} | ||
|
||
menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler()); | ||
index++; | ||
|
||
if (index % 9 == 8) { | ||
index += 2; | ||
} | ||
} | ||
|
||
menu.open(p); | ||
} | ||
|
||
} |
Oops, something went wrong.