mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added dual-wielding to the Climbing Pick
This commit is contained in:
parent
a45815ead9
commit
b81959e7a0
@ -36,6 +36,7 @@
|
||||
* Added Strange Nether Goo
|
||||
* Added Nitwit Rune
|
||||
* Added Synthetic Shulker Shells
|
||||
* Added Climbing Pick
|
||||
|
||||
#### Changes
|
||||
* Performance improvement for Programmable Android rotations
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
@ -16,13 +17,15 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
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.events.ClimbingPickLaunchEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
|
||||
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
|
||||
@ -42,11 +45,15 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
*/
|
||||
public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements DamageableItem, RecipeDisplayItem {
|
||||
|
||||
private static final double POWER = 0.75;
|
||||
|
||||
private final Map<Material, Double> materialSpeeds;
|
||||
private final ItemSetting<Boolean> dualWielding = new ItemSetting<>("dual-wielding", true);
|
||||
private final Set<UUID> users = new HashSet<>();
|
||||
|
||||
public ClimbingPick(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
addItemSetting(dualWielding);
|
||||
|
||||
String cfgKey = getID() + ".launch-amounts.";
|
||||
Config itemCfg = SlimefunPlugin.getItemCfg();
|
||||
@ -55,9 +62,11 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
for (Material mat : MaterialCollections.getAllIceBlocks()) {
|
||||
materialSpeeds.put(mat, itemCfg.getOrSetDefault(cfgKey + mat.name(), 1.0));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
@ -69,51 +78,105 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDualWieldingEnabled() {
|
||||
return dualWielding.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUseHandler getItemHandler() {
|
||||
return e -> {
|
||||
if (!e.getClickedBlock().isPresent()) return;
|
||||
if (!e.getClickedBlock().isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = e.getClickedBlock().get();
|
||||
ItemStack item = e.getItem();
|
||||
Player p = e.getPlayer();
|
||||
|
||||
if (p.getLocation().distanceSquared(block.getLocation()) > 2.25) return;
|
||||
if (e.getClickedFace() == BlockFace.DOWN || e.getClickedFace() == BlockFace.UP) return;
|
||||
if (p.getLocation().distanceSquared(block.getLocation()) > 2.8) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDualWieldingEnabled() && !isItem(getOtherHandItem(p, e.getHand()))) {
|
||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.climbing-pick.dual-wielding");
|
||||
}
|
||||
|
||||
if (e.getClickedFace() == BlockFace.DOWN || e.getClickedFace() == BlockFace.UP) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent players from spamming this
|
||||
if (!users.contains(p.getUniqueId())) {
|
||||
double launch = materialSpeeds.getOrDefault(block.getType(), 0D);
|
||||
climb(p, e.getHand(), e.getItem(), block);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ItemStack getOtherHandItem(Player p, EquipmentSlot hand) {
|
||||
if (hand == EquipmentSlot.HAND) {
|
||||
return p.getInventory().getItemInOffHand();
|
||||
}
|
||||
else {
|
||||
return p.getInventory().getItemInMainHand();
|
||||
}
|
||||
}
|
||||
|
||||
private void climb(Player p, EquipmentSlot hand, ItemStack item, Block block) {
|
||||
double power = materialSpeeds.getOrDefault(block.getType(), 0.0);
|
||||
|
||||
Vector velocity = new Vector(0, 0, 0);
|
||||
if (launch > 0.05) {
|
||||
int efficiencyLevel = item.getEnchantments().getOrDefault(Enchantment.DIG_SPEED, 0);
|
||||
if (power > 0.05) {
|
||||
int efficiencyLevel = item.getEnchantmentLevel(Enchantment.DIG_SPEED);
|
||||
|
||||
if (efficiencyLevel != 0) {
|
||||
launch += (efficiencyLevel * 0.2);
|
||||
power += efficiencyLevel * 0.1;
|
||||
}
|
||||
velocity.setY(launch);
|
||||
|
||||
velocity.setY(power * POWER);
|
||||
|
||||
users.add(p.getUniqueId());
|
||||
Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance(), () -> users.remove(p.getUniqueId()), 4L);
|
||||
}
|
||||
|
||||
ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, this, item, block);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
p.setVelocity(event.getVelocity());
|
||||
p.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, 1);
|
||||
p.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
||||
swing(p, hand, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void swing(Player p, EquipmentSlot hand, ItemStack item) {
|
||||
if (p.getGameMode() != GameMode.CREATIVE) {
|
||||
damageItem(p, e.getItem());
|
||||
if (isDualWieldingEnabled()) {
|
||||
if (ThreadLocalRandom.current().nextBoolean()) {
|
||||
p.swingMainHand();
|
||||
}
|
||||
else {
|
||||
p.swingOffHand();
|
||||
}
|
||||
|
||||
damageItem(p, p.getInventory().getItemInMainHand());
|
||||
damageItem(p, p.getInventory().getItemInOffHand());
|
||||
}
|
||||
else {
|
||||
damageItem(p, item);
|
||||
|
||||
if (hand == EquipmentSlot.HAND) {
|
||||
p.swingMainHand();
|
||||
}
|
||||
else {
|
||||
p.swingOffHand();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -124,6 +187,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
@Override
|
||||
public List<ItemStack> getDisplayRecipes() {
|
||||
List<ItemStack> display = new ArrayList<>();
|
||||
|
||||
for (Material mat : materialSpeeds.keySet()) {
|
||||
display.add(new ItemStack(mat));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user