mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Refactored Climbing Picks and added Tags
This commit is contained in:
parent
0e6fc92e28
commit
8bbdc37130
@ -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<Double> {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,8 +25,6 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
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.MinecraftVersion;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent;
|
import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
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.core.handlers.ItemUseHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
|
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.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
@ -49,52 +49,68 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
|||||||
*/
|
*/
|
||||||
public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements DamageableItem, RecipeDisplayItem {
|
public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements DamageableItem, RecipeDisplayItem {
|
||||||
|
|
||||||
private static final double BASE_POWER = 1;
|
|
||||||
private static final double MAX_DISTANCE = 4.4;
|
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<Boolean> dualWielding = new ItemSetting<>("dual-wielding", true);
|
private final ItemSetting<Boolean> dualWielding = new ItemSetting<>("dual-wielding", true);
|
||||||
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>("damage-on-use", true);
|
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>("damage-on-use", true);
|
||||||
private final Map<Material, Double> materialSpeeds = new EnumMap<>(Material.class);
|
private final Map<Material, ClimbableSurface> surfaces = new EnumMap<>(Material.class);
|
||||||
private final Set<UUID> users = new HashSet<>();
|
private final Set<UUID> users = new HashSet<>();
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
addItemSetting(dualWielding, damageOnUse);
|
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Material mat : MaterialCollections.getAllConcretePowderColors()) {
|
protected void addDefaultSurfaces() {
|
||||||
materialSpeeds.put(mat, itemCfg.getOrSetDefault(cfgKey + mat.name(), 1.0));
|
// 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.getAllTerracottaColors()) {
|
// These are "weak" surfaces, you can still climb them but they don't have
|
||||||
materialSpeeds.put(mat, itemCfg.getOrSetDefault(cfgKey + mat.name(), 1.0));
|
// such a high boost as the "strong" surfaces
|
||||||
}
|
for (Material surface : SlimefunTag.CLIMBING_PICK_WEAK_SURFACES.getValues()) {
|
||||||
|
addSurface(surface, WEAK_SURFACE_DEFAULT);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public boolean isDualWieldingEnabled() {
|
||||||
return dualWielding.getValue();
|
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<ClimbableSurface> getClimbableSurfaces() {
|
||||||
|
return surfaces.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getClimbingSpeed(@Nonnull Material type) {
|
||||||
|
ClimbableSurface surface = surfaces.get(type);
|
||||||
|
return surface != null ? surface.getValue() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemUseHandler getItemHandler() {
|
public ItemUseHandler getItemHandler() {
|
||||||
return e -> {
|
return e -> {
|
||||||
@ -138,7 +154,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
|||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
private void climb(Player p, EquipmentSlot hand, ItemStack item, Block block) {
|
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) {
|
if (power > 0.05) {
|
||||||
// Prevent players from spamming this
|
// Prevent players from spamming this
|
||||||
@ -149,8 +165,8 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
|||||||
power += efficiencyLevel * 0.1;
|
power += efficiencyLevel * 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlimefunPlugin.runSync(() -> users.remove(p.getUniqueId()), 4L);
|
SlimefunPlugin.runSync(() -> users.remove(p.getUniqueId()), COOLDOWN);
|
||||||
Vector velocity = new Vector(0, power * BASE_POWER, 0);
|
Vector velocity = new Vector(0, power, 0);
|
||||||
ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block);
|
ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
@ -219,7 +235,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
|||||||
public List<ItemStack> getDisplayRecipes() {
|
public List<ItemStack> getDisplayRecipes() {
|
||||||
List<ItemStack> display = new ArrayList<>();
|
List<ItemStack> display = new ArrayList<>();
|
||||||
|
|
||||||
for (Material mat : materialSpeeds.keySet()) {
|
for (Material mat : surfaces.keySet()) {
|
||||||
display.add(new ItemStack(mat));
|
display.add(new ItemStack(mat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -43,6 +46,7 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
|
|||||||
private final RandomizedSet<ItemStack> randomizer = new RandomizedSet<>();
|
private final RandomizedSet<ItemStack> randomizer = new RandomizedSet<>();
|
||||||
private final Set<GoldPanDrop> drops = new HashSet<>();
|
private final Set<GoldPanDrop> drops = new HashSet<>();
|
||||||
|
|
||||||
|
@ParametersAreNonnullByDefault
|
||||||
public GoldPan(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
public GoldPan(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
@ -51,7 +55,13 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
|
|||||||
addItemHandler(onEntityInteract());
|
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;
|
return Material.GRAVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +94,13 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> 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() {
|
public ItemStack getRandomOutput() {
|
||||||
return randomizer.getRandom();
|
return randomizer.getRandom();
|
||||||
}
|
}
|
||||||
@ -101,7 +118,7 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
|
|||||||
if (block.isPresent()) {
|
if (block.isPresent()) {
|
||||||
Block b = block.get();
|
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();
|
ItemStack output = getRandomOutput();
|
||||||
|
|
||||||
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
|
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
|
||||||
@ -133,7 +150,7 @@ public class GoldPan extends SimpleSlimefunItem<ItemUseHandler> implements Recip
|
|||||||
|
|
||||||
for (GoldPanDrop drop : drops) {
|
for (GoldPanDrop drop : drops) {
|
||||||
if (drop.getValue() > 0) {
|
if (drop.getValue() > 0) {
|
||||||
recipes.add(new ItemStack(getInput()));
|
recipes.add(new ItemStack(getTargetMaterial()));
|
||||||
recipes.add(drop.getOutput());
|
recipes.add(drop.getOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class NetherGoldPan extends GoldPan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Material getInput() {
|
protected Material getTargetMaterial() {
|
||||||
return Material.SOUL_SAND;
|
return Material.SOUL_SAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,9 +156,14 @@ public enum SlimefunTag implements Tag<Material> {
|
|||||||
CROP_GROWTH_ACCELERATOR_BLOCKS,
|
CROP_GROWTH_ACCELERATOR_BLOCKS,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All materials which the {@link ClimbingPick} is able to climb.
|
* All <strong>strong</strong> materials which the {@link ClimbingPick} is able to climb.
|
||||||
*/
|
*/
|
||||||
CLIMBING_PICK_SURFACES,
|
CLIMBING_PICK_STRONG_SURFACES,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All <strong>weak</strong> materials which the {@link ClimbingPick} is able to climb.
|
||||||
|
*/
|
||||||
|
CLIMBING_PICK_WEAK_SURFACES,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All materials (ores) which trigger the Talisman of the Caveman.
|
* All materials (ores) which trigger the Talisman of the Caveman.
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
{
|
{
|
||||||
"values" : [
|
"values" : [
|
||||||
"#slimefun:ice_variants",
|
"#slimefun:ice_variants",
|
||||||
"#slimefun:concrete_powders",
|
|
||||||
"#slimefun:terracotta",
|
"#slimefun:terracotta",
|
||||||
"#slimefun:stone_variants",
|
"#slimefun:stone_variants",
|
||||||
"#minecraft:sand",
|
|
||||||
"minecraft:gravel",
|
|
||||||
"minecraft:netherrack",
|
"minecraft:netherrack",
|
||||||
{
|
{
|
||||||
"id" : "minecraft:blackstone",
|
"id" : "minecraft:blackstone",
|
7
src/main/resources/tags/climbing_pick_weak_surfaces.json
Normal file
7
src/main/resources/tags/climbing_pick_weak_surfaces.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"values" : [
|
||||||
|
"#slimefun:concrete_powders",
|
||||||
|
"#minecraft:sand",
|
||||||
|
"minecraft:gravel"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user