Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Arcane Magnet #3968

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum SoundEffect {
ANCIENT_ALTAR_FINISH_SOUND(Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F),
ANCIENT_ALTAR_START_SOUND(Sound.ENTITY_ILLUSIONER_PREPARE_MIRROR, 1F, 1F),
ANCIENT_PEDESTAL_ITEM_PLACE_SOUND(Sound.ENTITY_ITEM_PICKUP, 0.5F, 0.5F),
ARCANE_MAGNET_TELEPORT_SOUND(Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.2F, 1F),
ARMOR_FORGE_FINISH_SOUND(Sound.BLOCK_ANVIL_USE, 1F, 1F),
ARMOR_FORGE_WORKING_SOUND(Sound.ENTITY_ARROW_HIT_PLAYER, 1F, 1F),
AUTO_CRAFTER_GUI_CLICK_SOUND(Sound.UI_BUTTON_CLICK, 1F, 1F),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private SlimefunItems() {}
public static final SlimefunItemStack ELYTRA_CAP = new SlimefunItemStack("ELYTRA_CAP", Material.LEATHER_HELMET, Color.PURPLE, "&5Elytra Cap", "", "&7This helmet will protect you from", "&7crashing while flying with an elytra.");
public static final SlimefunItemStack FARMER_SHOES = new SlimefunItemStack("FARMER_SHOES", Material.LEATHER_BOOTS, Color.YELLOW, "&eFarmer Shoes", "", "&6&oPrevents you from trampling your Crops");
public static final SlimefunItemStack INFUSED_MAGNET = new SlimefunItemStack("INFUSED_MAGNET", HeadTexture.MAGNET, "&aInfused Magnet", "", "&fMagical infused Magnets", "&fattract nearby Items", "&fas long as it is somewhere in", "&fyour Inventory", "", "&7Hold &eShift&7 to pick up nearby Items");
public static final SlimefunItemStack ARCANE_MAGNET = new SlimefunItemStack("ARCANE_MAGNET", HeadTexture.MAGNET, "&aArcane Magnet", "", "&fMagical Arcane Magnets", "&fattract nearby Items and", "&fExperience as long as it is", "&fsomewhere in your Inventory", "", "&7Hold &eShift&7 to pick up nearby", "&7Items and Experience");
public static final SlimefunItemStack RAG = new SlimefunItemStack("RAG", Material.PAPER, "&cRag", "", "&aLevel I - Medical Supply", "", "&fRestores 2 Hearts", "&fExtinguishes Fire", "", LoreBuilder.RIGHT_CLICK_TO_USE);
public static final SlimefunItemStack BANDAGE = new SlimefunItemStack("BANDAGE", Material.PAPER, "&cBandage", "", "&aLevel II - Medical Supply", "", "&fRestores 4 Hearts", "&fExtinguishes Fire", "", LoreBuilder.RIGHT_CLICK_TO_USE);
public static final SlimefunItemStack SPLINT = new SlimefunItemStack("SPLINT", Material.STICK, "&cSplint", "", "&aLevel I - Medical Supply", "", "&fRestores 2 Hearts", "", LoreBuilder.RIGHT_CLICK_TO_USE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.magical;

import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.items.settings.DoubleRangeSetting;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import javax.annotation.ParametersAreNonnullByDefault;

/**
* The {@link ArcaneMagnet} is a {@link SlimefunItem} that allows a {@link Player} to
* automatically pick up {@link Item items} and {@link ExperienceOrb experience} in a certain radius while holding shift and having an
* {@link ArcaneMagnet} in their {@link Inventory}.
*
* @author TheBusyBiscuit
J3fftw1 marked this conversation as resolved.
Show resolved Hide resolved
* @author JustAHuman
*
* @see InfusedMagnet
*/
public class ArcaneMagnet extends UnplaceableBlock {
private final ItemSetting<Double> itemRadius = new DoubleRangeSetting(this, "items-pickup-radius", 0.1, 6.0, Double.MAX_VALUE);
private final ItemSetting<Double> experienceRadius = new DoubleRangeSetting(this, "xp-pickup-radius", 0.1, 10.0, Double.MAX_VALUE);

@ParametersAreNonnullByDefault
public ArcaneMagnet(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);

addItemSetting(itemRadius, experienceRadius);
}

/**
* This returns the radius in which {@link Item items} are picked up
*
* @return The radius of the {@link ArcaneMagnet}
*/
public double getItemRadius() {
return itemRadius.getValue();
}

/**
* This returns the radius in which {@link ExperienceOrb experience} is picked up
*
* @return The radius of the {@link ArcaneMagnet}
*/
public double getExperienceRadius() {
return experienceRadius.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.ParametersAreNonnullByDefault;

import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand All @@ -16,11 +17,10 @@

/**
* The {@link InfusedMagnet} is a {@link SlimefunItem} that allows a {@link Player} to
* automatically pick up items in a certain radius while holding shift and having an
* automatically pick up {@link Item items} in a certain radius while holding shift and having an
* {@link InfusedMagnet} in their {@link Inventory}.
*
* @author TheBusyBiscuit
*
*/
public class InfusedMagnet extends UnplaceableBlock {

Expand All @@ -34,7 +34,7 @@ public InfusedMagnet(ItemGroup itemGroup, SlimefunItemStack item, RecipeType rec
}

/**
* This returns the radius in which items are picked up
* This returns the radius in which {@link Item items} are picked up
*
* @return The radius of the {@link InfusedMagnet}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.JetBoots;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Jetpack;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfusedMagnet;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.ArcaneMagnet;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.InfusedMagnetTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.ArcaneMagnetTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.JetBootsTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.JetpackTask;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.player.ParachuteTask;
Expand All @@ -32,7 +34,7 @@
* @see JetBootsTask
* @see ParachuteTask
* @see InfusedMagnetTask
*
* @see ArcaneMagnetTask
*/
public class GadgetsListener implements Listener {

Expand All @@ -42,25 +44,33 @@ public GadgetsListener(@Nonnull Slimefun plugin) {

@EventHandler
public void onToggleSneak(PlayerToggleSneakEvent e) {
if (e.isSneaking()) {
Player p = e.getPlayer();
if (!e.isSneaking()) {
return;
}

if (p.getInventory().getChestplate() != null) {
SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
handleChestplate(p, chestplate);
}
Player p = e.getPlayer();

if (p.getInventory().getBoots() != null) {
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
handleBoots(p, boots);
}
if (p.getInventory().getChestplate() != null) {
SlimefunItem chestplate = SlimefunItem.getByItem(p.getInventory().getChestplate());
handleChestplate(p, chestplate);
}

if (SlimefunUtils.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true)) {
InfusedMagnet magnet = (InfusedMagnet) SlimefunItems.INFUSED_MAGNET.getItem();
if (p.getInventory().getBoots() != null) {
SlimefunItem boots = SlimefunItem.getByItem(p.getInventory().getBoots());
handleBoots(p, boots);
}

if (SlimefunUtils.containsSimilarItem(p.getInventory(), SlimefunItems.ARCANE_MAGNET, true)) {
ArcaneMagnet magnet = (ArcaneMagnet) SlimefunItems.ARCANE_MAGNET.getItem();

if (magnet.canUse(p, true)) {
new ArcaneMagnetTask(p, magnet.getItemRadius(), magnet.getExperienceRadius()).scheduleRepeating(0, 8);
}
} else if (SlimefunUtils.containsSimilarItem(p.getInventory(), SlimefunItems.INFUSED_MAGNET, true)) {
InfusedMagnet magnet = (InfusedMagnet) SlimefunItems.INFUSED_MAGNET.getItem();

if (magnet.canUse(p, true)) {
new InfusedMagnetTask(p, magnet.getRadius()).scheduleRepeating(0, 8);
}
if (magnet.canUse(p, true)) {
new InfusedMagnetTask(p, magnet.getRadius()).scheduleRepeating(0, 8);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static void setupResearches() {
register("ender_talismans", 112, "Ender Talismans", 28, new String[0]);
register("nickel_and_cobalt", 115, "Even more Ores", 10, SlimefunItems.NICKEL_INGOT, SlimefunItems.COBALT_INGOT);
register("magnet", 116, "Magnetic Metals", 16, SlimefunItems.MAGNET);
register("infused_magnet", 117, "Infused Magnets", 18, SlimefunItems.INFUSED_MAGNET);
register("infused_magnet", 117, "Infused Magnets", 18, SlimefunItems.INFUSED_MAGNET, SlimefunItems.ARCANE_MAGNET);
register("cobalt_pickaxe", 118, "Speedy Pickaxe", 14, SlimefunItems.COBALT_PICKAXE);
register("essence_of_afterlife", 119, "Necromancy", 19, SlimefunItems.NECROTIC_SKULL, SlimefunItems.ESSENCE_OF_AFTERLIFE);
register("bound_backpack", 120, "Soulbound Storage", 22, SlimefunItems.BOUND_BACKPACK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfernalBonemeal;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfusedHopper;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfusedMagnet;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.ArcaneMagnet;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.KnowledgeFlask;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.KnowledgeTome;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.MagicEyeOfEnder;
Expand Down Expand Up @@ -1164,6 +1165,10 @@ public static void setup(@Nonnull Slimefun plugin) {
new ItemStack[] {SlimefunItems.MAGIC_LUMP_3, null, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.ENDER_LUMP_2, SlimefunItems.MAGNET, SlimefunItems.ENDER_LUMP_2, SlimefunItems.MAGIC_LUMP_3, null, SlimefunItems.MAGIC_LUMP_3})
.register(plugin);

new ArcaneMagnet(itemGroups.magicalGadgets, SlimefunItems.ARCANE_MAGNET, RecipeType.ANCIENT_ALTAR,
new ItemStack[] {SlimefunItems.MAGICAL_GLASS, null, SlimefunItems.MAGICAL_GLASS, SlimefunItems.GOLD_24K, SlimefunItems.INFUSED_MAGNET, SlimefunItems.MAGNESIUM_INGOT, SlimefunItems.GOLD_24K, SlimefunItems.SYNTHETIC_EMERALD, SlimefunItems.MAGNESIUM_INGOT})
.register(plugin);

new SlimefunItem(itemGroups.tools, SlimefunItems.COBALT_PICKAXE, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {SlimefunItems.COBALT_INGOT, SlimefunItems.COBALT_INGOT, SlimefunItems.COBALT_INGOT, null, SlimefunItems.NICKEL_INGOT, null, null, SlimefunItems.NICKEL_INGOT, null})
.register(plugin);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.github.thebusybiscuit.slimefun4.implementation.tasks.player;

import javax.annotation.Nonnull;

import org.bukkit.GameMode;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;

import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.ArcaneMagnet;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;

/**
* This {@link AbstractPlayerTask} is run when a {@link Player} carries an {@link ArcaneMagnet}.
* It manages the automatic pickup of nearby {@link Item items} and {@link ExperienceOrb experience}.
*
* @author TheBusyBiscuit
J3fftw1 marked this conversation as resolved.
Show resolved Hide resolved
* @author JustAHuman
*
* @see ArcaneMagnet
* @see InfusedMagnetTask
*/
public class ArcaneMagnetTask extends AbstractPlayerTask {

/**
* The radius in which an {@link Item} is picked up.
*/
private final double itemRadius;
/**
* The radius in which an {@link ExperienceOrb} is picked up.
*/
private final double experienceRadius;

/**
* This creates a new {@link ArcaneMagnetTask} for the given {@link Player} with the given
* pickup radius.
*
* @param p
* The {@link Player} who {@link Item items} should be teleported to
* @param itemRadius
* The radius in which {@link Item items} should be picked up
* @param experienceRadius
* The radius in which {@link ExperienceOrb experience} should be picked up
*/
public ArcaneMagnetTask(@Nonnull Player p, double itemRadius, double experienceRadius) {
super(p);

this.itemRadius = itemRadius;
this.experienceRadius = experienceRadius;
}

@Override
protected void executeTask() {
boolean playSound = false;
double maxRadius = Math.max(itemRadius, experienceRadius);

for (Entity entity : p.getNearbyEntities(maxRadius, maxRadius, maxRadius)) {
if (!(entity instanceof Item) && !(entity instanceof ExperienceOrb)) {
continue;
}

double distance = p.getLocation().distanceSquared(entity.getLocation());
if (distance <= 0.3) {
continue;
}

if (entity instanceof Item item && !SlimefunUtils.hasNoPickupFlag(item) && item.getPickupDelay() <= 0 && distance <= Math.pow(itemRadius, 2)) {
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
item.teleport(p.getLocation());
playSound = true;
} else if (entity instanceof ExperienceOrb orb && distance <= Math.pow(experienceRadius, 2)) {
JustAHuman-xD marked this conversation as resolved.
Show resolved Hide resolved
orb.teleport(p.getLocation());
playSound = true;
}
}

// Only play a sound if an entity was found
if (playSound) {
SoundEffect.ARCANE_MAGNET_TELEPORT_SOUND.playFor(p);
}
}

@Override
protected boolean isValid() {
return super.isValid() && p.getGameMode() != GameMode.SPECTATOR;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

/**
* This {@link AbstractPlayerTask} is run when a {@link Player} carries an {@link InfusedMagnet}.
* It manages the automatic pickup of nearby items.
* It manages the automatic pickup of nearby {@link Item items}.
*
* @author TheBusyBiscuit
*
* @see InfusedMagnet
*
*/
public class InfusedMagnetTask extends AbstractPlayerTask {

Expand All @@ -32,9 +31,9 @@ public class InfusedMagnetTask extends AbstractPlayerTask {
* pickup radius.
*
* @param p
* The {@link Player} who items should be teleported to
* The {@link Player} who {@link Item items} should be teleported to
* @param radius
* The radius in which items should be picked up
* The radius in which {@link Item items} should be picked up
*/
public InfusedMagnetTask(@Nonnull Player p, double radius) {
super(p);
Expand Down
Loading