mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Added an item setting to the Infused Hopper to toggle it with redstone
This commit is contained in:
parent
3bd595a930
commit
f689c2fc4f
@ -32,6 +32,7 @@
|
||||
* (API) Added CoolerFeedPlayerEvent
|
||||
* Added a config option to delete excess cargo network items
|
||||
* Added an item setting to configure the Wind Staff velocity
|
||||
* Added an item setting to the Infused Hopper to toggle it with redstone
|
||||
|
||||
#### Changes
|
||||
* Removed 1.13 support
|
||||
|
@ -1,10 +1,14 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.blocks;
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.items.magical;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.Hopper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -22,15 +26,27 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
/**
|
||||
* The {@link InfusedHopper} is a special kind of {@link Hopper} which teleports any
|
||||
* neaby {@link Item} to itself.
|
||||
* The radius can be configured in the config.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
* @see InfusedMagnet
|
||||
*
|
||||
*/
|
||||
public class InfusedHopper extends SimpleSlimefunItem<BlockTicker> {
|
||||
|
||||
private final ItemSetting<Boolean> silent = new ItemSetting<>("silent", false);
|
||||
private final ItemSetting<Boolean> toggleable = new ItemSetting<>("toggleable-with-redstone", false);
|
||||
private final ItemSetting<Double> radius = new DoubleRangeSetting("radius", 0.1, 3.5, Double.MAX_VALUE);
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
public InfusedHopper(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||
super(category, item, recipeType, recipe);
|
||||
|
||||
addItemSetting(silent, radius);
|
||||
addItemSetting(silent, radius, toggleable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,17 +61,35 @@ public class InfusedHopper extends SimpleSlimefunItem<BlockTicker> {
|
||||
return;
|
||||
}
|
||||
|
||||
Location l = b.getLocation().add(0.5, 1.2, 0.5);
|
||||
boolean sound = false;
|
||||
double range = radius.getValue();
|
||||
// Check if this was enabled in the config
|
||||
if (toggleable.getValue()) {
|
||||
Hopper hopper = (Hopper) b.getBlockData();
|
||||
|
||||
/**
|
||||
* If the Hopper was disabled by a redstone signal,
|
||||
* we just don't do anything.
|
||||
*/
|
||||
if (!hopper.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Location l = b.getLocation().add(0.5, 1.2, 0.5);
|
||||
double range = radius.getValue();
|
||||
boolean playSound = false;
|
||||
|
||||
// Check for any nearby Items that can be picked up
|
||||
for (Entity item : b.getWorld().getNearbyEntities(l, range, range, range, n -> isValidItem(l, n))) {
|
||||
item.setVelocity(new Vector(0, 0.1, 0));
|
||||
item.teleport(l);
|
||||
sound = true;
|
||||
playSound = true;
|
||||
}
|
||||
|
||||
if (sound && !silent.getValue().booleanValue()) {
|
||||
/**
|
||||
* Play a sound if at least one item was teleported and
|
||||
* the "silent" setting is set to false.
|
||||
*/
|
||||
if (playSound && !silent.getValue().booleanValue()) {
|
||||
b.getWorld().playSound(b.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.BLOCKS, 1F, 2F);
|
||||
}
|
||||
}
|
||||
@ -67,7 +101,7 @@ public class InfusedHopper extends SimpleSlimefunItem<BlockTicker> {
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isValidItem(Location l, Entity entity) {
|
||||
private boolean isValidItem(@Nonnull Location l, @Nonnull Entity entity) {
|
||||
if (entity instanceof Item && entity.isValid()) {
|
||||
Item item = (Item) entity;
|
||||
return !SlimefunUtils.hasNoPickupFlag(item) && item.getLocation().distanceSquared(l) > 0.25;
|
@ -4,13 +4,22 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
|
||||
/**
|
||||
* This {@link Listener} makes sure that any {@link Firework} caused by a {@link Player}
|
||||
* unlocking a {@link Research} does not cause damage to be dealt.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
*/
|
||||
public class FireworksListener implements Listener {
|
||||
|
||||
public FireworksListener(@Nonnull SlimefunPlugin plugin) {
|
||||
@ -23,6 +32,12 @@ public class FireworksListener implements Listener {
|
||||
Firework firework = (Firework) e.getDamager();
|
||||
FireworkMeta meta = firework.getFireworkMeta();
|
||||
|
||||
/**
|
||||
* We could use Peristent Data for this in the future, but ItemMeta display names
|
||||
* work pretty reliably too and they don't cause any memory leaks like metadata.
|
||||
*
|
||||
* Entity display names do not work either as Firework cannot be named.
|
||||
*/
|
||||
if (meta.hasDisplayName() && meta.getDisplayName().equals(ChatColor.GREEN + "Slimefun Research")) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
/**
|
||||
* This {@link Listener} makes sure that an {@link IronGolem} cannot be healed with
|
||||
* a {@link SlimefunItem}.
|
||||
* This fixes Issue 1332.
|
||||
*
|
||||
* @author TheBusyBiscuit
|
||||
*
|
||||
@ -42,6 +41,7 @@ public class IronGolemListener implements Listener {
|
||||
item = inv.getItemInOffHand();
|
||||
}
|
||||
|
||||
// Check if the Golem was clicked using an Iron Ingot
|
||||
if (item != null && item.getType() == Material.IRON_INGOT) {
|
||||
SlimefunItem sfItem = SlimefunItem.getByItem(item);
|
||||
|
||||
@ -49,8 +49,10 @@ public class IronGolemListener implements Listener {
|
||||
e.setCancelled(true);
|
||||
SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.no-iron-golem-heal");
|
||||
|
||||
// This is just there to update the Inventory...
|
||||
// Somehow cancelling it isn't enough.
|
||||
/**
|
||||
* This is just there to update the Inventory...
|
||||
* Somehow cancelling it isn't enough.
|
||||
*/
|
||||
if (e.getHand() == EquipmentSlot.HAND) {
|
||||
inv.setItemInMainHand(item);
|
||||
} else if (e.getHand() == EquipmentSlot.OFF_HAND) {
|
||||
@ -61,4 +63,11 @@ public class IronGolemListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onIronGolemSpawn(PLEASE_GIMME_AN_EVENT e) {
|
||||
// if (e.getBlock().getType() == Material.IRON_BLOCK) {
|
||||
// e.setCancelled(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.Crucible;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.EnhancedFurnace;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HardenedGlass;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HologramProjector;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.InfusedHopper;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
|
||||
@ -129,6 +128,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.gps.PersonalActiv
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.gps.Teleporter;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.gps.TeleporterPylon;
|
||||
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.KnowledgeFlask;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.KnowledgeTome;
|
||||
|
Loading…
Reference in New Issue
Block a user