From 8bbdc37130fc5f7454f807788da6eb651e71a9f9 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 4 Oct 2020 02:28:59 +0200 Subject: [PATCH] Refactored Climbing Picks and added Tags --- .../items/tools/ClimbableSurface.java | 51 ++++++++++++ .../items/tools/ClimbingPick.java | 80 +++++++++++-------- .../implementation/items/tools/GoldPan.java | 23 +++++- .../items/tools/NetherGoldPan.java | 2 +- .../slimefun4/utils/tags/SlimefunTag.java | 9 ++- ...son => climbing_pick_strong_surfaces.json} | 3 - .../tags/climbing_pick_weak_surfaces.json | 7 ++ 7 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java rename src/main/resources/tags/{climbing_pick_surfaces.json => climbing_pick_strong_surfaces.json} (77%) create mode 100644 src/main/resources/tags/climbing_pick_weak_surfaces.json diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java new file mode 100644 index 000000000..cf3ed08a4 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbableSurface.java @@ -0,0 +1,51 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.tools; + +import javax.annotation.Nonnull; + +import org.bukkit.Material; + +import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent; +import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; + +/** + * This is an {@link ItemSetting} + * + * @author TheBusyBiscuit + * + * @see ClimbingPick + * @see ClimbingPickLaunchEvent + * + */ +public class ClimbableSurface extends ItemSetting { + + private final Material type; + + /** + * This creates a new {@link ClimbableSurface} for the given {@link Material}. + * + * @param surface + * The {@link Material} of this surface + * @param defaultValue + * The default launch amount + */ + public ClimbableSurface(@Nonnull Material surface, double defaultValue) { + super("launch-amounts." + surface.name(), defaultValue); + this.type = surface; + } + + @Override + public boolean validateInput(Double input) { + return super.validateInput(input) && input >= 0; + } + + /** + * This returns the {@link Material} of this surface. + * + * @return The {@link Material} of this surface + */ + @Nonnull + public Material getType() { + return type; + } + +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java index 7730f1375..90368972a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ClimbingPick.java @@ -1,6 +1,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; import java.util.ArrayList; +import java.util.Collection; import java.util.EnumMap; import java.util.HashSet; import java.util.List; @@ -24,8 +25,6 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import io.github.thebusybiscuit.cscorelib2.config.Config; -import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent; import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting; @@ -34,6 +33,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; @@ -49,52 +49,68 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; */ public class ClimbingPick extends SimpleSlimefunItem implements DamageableItem, RecipeDisplayItem { - private static final double BASE_POWER = 1; private static final double MAX_DISTANCE = 4.4; + private static final double STRONG_SURFACE_DEFAULT = 1.0; + private static final double WEAK_SURFACE_DEFAULT = 0.6; + private static final long COOLDOWN = 4; private final ItemSetting dualWielding = new ItemSetting<>("dual-wielding", true); private final ItemSetting damageOnUse = new ItemSetting<>("damage-on-use", true); - private final Map materialSpeeds = new EnumMap<>(Material.class); + private final Map surfaces = new EnumMap<>(Material.class); private final Set users = new HashSet<>(); @ParametersAreNonnullByDefault public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); addItemSetting(dualWielding, damageOnUse); + addDefaultSurfaces(); + } - String cfgKey = getID() + ".launch-amounts."; - Config itemCfg = SlimefunPlugin.getItemCfg(); - - for (Material mat : MaterialCollections.getAllIceBlocks()) { - materialSpeeds.put(mat, itemCfg.getOrSetDefault(cfgKey + mat.name(), 1.0)); + protected void addDefaultSurfaces() { + // These are "strong" surfaces, they will give you the biggest boost + for (Material surface : SlimefunTag.CLIMBING_PICK_STRONG_SURFACES.getValues()) { + addSurface(surface, STRONG_SURFACE_DEFAULT); } - for (Material mat : MaterialCollections.getAllConcretePowderColors()) { - materialSpeeds.put(mat, itemCfg.getOrSetDefault(cfgKey + mat.name(), 1.0)); - } - - for (Material mat : MaterialCollections.getAllTerracottaColors()) { - materialSpeeds.put(mat, itemCfg.getOrSetDefault(cfgKey + mat.name(), 1.0)); - } - - materialSpeeds.put(Material.GRAVEL, itemCfg.getOrSetDefault(cfgKey + Material.GRAVEL.name(), 0.4)); - materialSpeeds.put(Material.SAND, itemCfg.getOrSetDefault(cfgKey + Material.SAND.name(), 0.4)); - materialSpeeds.put(Material.STONE, itemCfg.getOrSetDefault(cfgKey + Material.STONE.name(), 0.6)); - materialSpeeds.put(Material.DIORITE, itemCfg.getOrSetDefault(cfgKey + Material.DIORITE.name(), 0.6)); - materialSpeeds.put(Material.GRANITE, itemCfg.getOrSetDefault(cfgKey + Material.GRANITE.name(), 0.6)); - materialSpeeds.put(Material.ANDESITE, itemCfg.getOrSetDefault(cfgKey + Material.ANDESITE.name(), 0.6)); - materialSpeeds.put(Material.NETHERRACK, itemCfg.getOrSetDefault(cfgKey + Material.NETHERRACK.name(), 0.6)); - - if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) { - materialSpeeds.put(Material.BLACKSTONE, itemCfg.getOrSetDefault(cfgKey + Material.BLACKSTONE.name(), 0.6)); - materialSpeeds.put(Material.BASALT, itemCfg.getOrSetDefault(cfgKey + Material.BASALT.name(), 0.7)); + // These are "weak" surfaces, you can still climb them but they don't have + // such a high boost as the "strong" surfaces + for (Material surface : SlimefunTag.CLIMBING_PICK_WEAK_SURFACES.getValues()) { + addSurface(surface, WEAK_SURFACE_DEFAULT); } } + protected void addSurface(@Nonnull Material type, double defaultValue) { + ClimbableSurface surface = new ClimbableSurface(type, defaultValue); + addItemSetting(surface); + surfaces.put(type, surface); + } + + /** + * This returns whether the {@link ClimbingPick} needs to be held in both + * arms to work. + * + * @return Whether dual wielding is enabled + */ public boolean isDualWieldingEnabled() { return dualWielding.getValue(); } + /** + * This method returns a {@link Collection} of every {@link ClimbableSurface} the + * {@link ClimbingPick} can climb. + * + * @return A {@link Collection} of every {@link ClimbableSurface} + */ + @Nonnull + public Collection getClimbableSurfaces() { + return surfaces.values(); + } + + private double getClimbingSpeed(@Nonnull Material type) { + ClimbableSurface surface = surfaces.get(type); + return surface != null ? surface.getValue() : 0; + } + @Override public ItemUseHandler getItemHandler() { return e -> { @@ -138,7 +154,7 @@ public class ClimbingPick extends SimpleSlimefunItem implements @ParametersAreNonnullByDefault private void climb(Player p, EquipmentSlot hand, ItemStack item, Block block) { - double power = materialSpeeds.getOrDefault(block.getType(), 0.0); + double power = getClimbingSpeed(block.getType()); if (power > 0.05) { // Prevent players from spamming this @@ -149,8 +165,8 @@ public class ClimbingPick extends SimpleSlimefunItem implements power += efficiencyLevel * 0.1; } - SlimefunPlugin.runSync(() -> users.remove(p.getUniqueId()), 4L); - Vector velocity = new Vector(0, power * BASE_POWER, 0); + SlimefunPlugin.runSync(() -> users.remove(p.getUniqueId()), COOLDOWN); + Vector velocity = new Vector(0, power, 0); ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block); Bukkit.getPluginManager().callEvent(event); @@ -219,7 +235,7 @@ public class ClimbingPick extends SimpleSlimefunItem implements public List getDisplayRecipes() { List display = new ArrayList<>(); - for (Material mat : materialSpeeds.keySet()) { + for (Material mat : surfaces.keySet()) { display.add(new ItemStack(mat)); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java index 0c7101673..aba6e1374 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/GoldPan.java @@ -6,6 +6,9 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.block.Block; @@ -43,6 +46,7 @@ public class GoldPan extends SimpleSlimefunItem implements Recip private final RandomizedSet randomizer = new RandomizedSet<>(); private final Set drops = new HashSet<>(); + @ParametersAreNonnullByDefault public GoldPan(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); @@ -51,7 +55,13 @@ public class GoldPan extends SimpleSlimefunItem implements Recip addItemHandler(onEntityInteract()); } - protected Material getInput() { + /** + * This method returns the target {@link Material} for this {@link GoldPan}. + * + * @return The {@link Material} this {@link GoldPan} can be used on + */ + @Nonnull + protected Material getTargetMaterial() { return Material.GRAVEL; } @@ -84,6 +94,13 @@ public class GoldPan extends SimpleSlimefunItem implements Recip } } + /** + * This returns a random output {@link ItemStack} that can be obtained via + * this {@link GoldPan}. + * + * @return a random {@link ItemStack} obtained by this {@link GoldPan} + */ + @Nonnull public ItemStack getRandomOutput() { return randomizer.getRandom(); } @@ -101,7 +118,7 @@ public class GoldPan extends SimpleSlimefunItem implements Recip if (block.isPresent()) { Block b = block.get(); - if (b.getType() == getInput() && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), ProtectableAction.BREAK_BLOCK)) { + if (b.getType() == getTargetMaterial() && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), ProtectableAction.BREAK_BLOCK)) { ItemStack output = getRandomOutput(); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); @@ -133,7 +150,7 @@ public class GoldPan extends SimpleSlimefunItem implements Recip for (GoldPanDrop drop : drops) { if (drop.getValue() > 0) { - recipes.add(new ItemStack(getInput())); + recipes.add(new ItemStack(getTargetMaterial())); recipes.add(drop.getOutput()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java index f7c4500b7..300b5a0cd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/NetherGoldPan.java @@ -17,7 +17,7 @@ public class NetherGoldPan extends GoldPan { } @Override - protected Material getInput() { + protected Material getTargetMaterial() { return Material.SOUL_SAND; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java index c83560031..d5218059c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java @@ -156,9 +156,14 @@ public enum SlimefunTag implements Tag { CROP_GROWTH_ACCELERATOR_BLOCKS, /** - * All materials which the {@link ClimbingPick} is able to climb. + * All strong materials which the {@link ClimbingPick} is able to climb. */ - CLIMBING_PICK_SURFACES, + CLIMBING_PICK_STRONG_SURFACES, + + /** + * All weak materials which the {@link ClimbingPick} is able to climb. + */ + CLIMBING_PICK_WEAK_SURFACES, /** * All materials (ores) which trigger the Talisman of the Caveman. diff --git a/src/main/resources/tags/climbing_pick_surfaces.json b/src/main/resources/tags/climbing_pick_strong_surfaces.json similarity index 77% rename from src/main/resources/tags/climbing_pick_surfaces.json rename to src/main/resources/tags/climbing_pick_strong_surfaces.json index c72bb4368..ca798a9bd 100644 --- a/src/main/resources/tags/climbing_pick_surfaces.json +++ b/src/main/resources/tags/climbing_pick_strong_surfaces.json @@ -1,11 +1,8 @@ { "values" : [ "#slimefun:ice_variants", - "#slimefun:concrete_powders", "#slimefun:terracotta", "#slimefun:stone_variants", - "#minecraft:sand", - "minecraft:gravel", "minecraft:netherrack", { "id" : "minecraft:blackstone", diff --git a/src/main/resources/tags/climbing_pick_weak_surfaces.json b/src/main/resources/tags/climbing_pick_weak_surfaces.json new file mode 100644 index 000000000..902bfac23 --- /dev/null +++ b/src/main/resources/tags/climbing_pick_weak_surfaces.json @@ -0,0 +1,7 @@ +{ + "values" : [ + "#slimefun:concrete_powders", + "#minecraft:sand", + "minecraft:gravel" + ] +}