mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Fixes #1224
This commit is contained in:
parent
5c860cbfa4
commit
beebbda2dd
@ -22,7 +22,9 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
|
|||||||
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
|
||||||
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
|
||||||
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
|
||||||
|
|
||||||
public class FluidPump extends SlimefunItem implements InventoryBlock {
|
public class FluidPump extends SlimefunItem implements InventoryBlock {
|
||||||
@ -33,8 +35,8 @@ public class FluidPump extends SlimefunItem implements InventoryBlock {
|
|||||||
|
|
||||||
protected int energyConsumption = 32;
|
protected int energyConsumption = 32;
|
||||||
|
|
||||||
public FluidPump(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) {
|
public FluidPump(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
|
||||||
super(category, item, name, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
createPreset(this, "&9Fluid Pump", this::constructMenu);
|
createPreset(this, "&9Fluid Pump", this::constructMenu);
|
||||||
}
|
}
|
||||||
@ -79,40 +81,32 @@ public class FluidPump extends SlimefunItem implements InventoryBlock {
|
|||||||
|
|
||||||
protected void tick(Block b) {
|
protected void tick(Block b) {
|
||||||
Block fluid = b.getRelative(BlockFace.DOWN);
|
Block fluid = b.getRelative(BlockFace.DOWN);
|
||||||
|
ItemStack output = null;
|
||||||
|
|
||||||
if (fluid.getType() == Material.LAVA) {
|
if (fluid.getType() == Material.LAVA) {
|
||||||
for (int slot : getInputSlots()) {
|
output = new ItemStack(Material.LAVA_BUCKET);
|
||||||
if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) {
|
|
||||||
if (ChargableBlock.getCharge(b) < energyConsumption) return;
|
|
||||||
|
|
||||||
ItemStack output = new ItemStack(Material.LAVA_BUCKET);
|
|
||||||
|
|
||||||
if (!fits(b, output)) return;
|
|
||||||
|
|
||||||
ChargableBlock.addCharge(b, -energyConsumption);
|
|
||||||
BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1));
|
|
||||||
pushItems(b, output);
|
|
||||||
|
|
||||||
List<Block> list = Vein.find(fluid, 50, block -> block.isLiquid() && block.getType() == fluid.getType());
|
|
||||||
list.get(list.size() - 1).setType(Material.AIR);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (fluid.getType() == Material.WATER) {
|
else if (fluid.getType() == Material.WATER) {
|
||||||
|
output = new ItemStack(Material.WATER_BUCKET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (output != null && ChargableBlock.getCharge(b) >= energyConsumption) {
|
||||||
|
BlockMenu menu = BlockStorage.getInventory(b);
|
||||||
for (int slot : getInputSlots()) {
|
for (int slot : getInputSlots()) {
|
||||||
if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) {
|
if (SlimefunManager.isItemSimiliar(menu.getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) {
|
||||||
if (ChargableBlock.getCharge(b) < energyConsumption) return;
|
if (!menu.fits(output, getOutputSlots())) return;
|
||||||
|
|
||||||
ItemStack output = new ItemStack(Material.WATER_BUCKET);
|
|
||||||
|
|
||||||
if (!fits(b, output)) return;
|
|
||||||
|
|
||||||
ChargableBlock.addCharge(b, -energyConsumption);
|
ChargableBlock.addCharge(b, -energyConsumption);
|
||||||
BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1));
|
menu.replaceExistingItem(slot, InvUtils.decreaseItem(menu.getItemInSlot(slot), 1));
|
||||||
pushItems(b, output);
|
menu.pushItem(output, getOutputSlots());
|
||||||
|
|
||||||
fluid.setType(Material.AIR);
|
if (fluid.getType() == Material.WATER) {
|
||||||
|
fluid.setType(Material.AIR);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
List<Block> list = Vein.find(fluid, 50, block -> block.isLiquid() && block.getType() == fluid.getType());
|
||||||
|
list.get(list.size() - 1).setType(Material.AIR);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,27 +30,30 @@ import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
|
|||||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
|
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem;
|
||||||
import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils;
|
import me.mrCookieSlime.CSCoreLibPlugin.general.String.StringUtils;
|
||||||
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||||
|
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
|
||||||
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
import me.mrCookieSlime.Slimefun.api.BlockStorage;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||||
import me.mrCookieSlime.Slimefun.utils.Utilities;
|
import me.mrCookieSlime.Slimefun.utils.Utilities;
|
||||||
|
|
||||||
public class AncientAltarListener implements Listener {
|
public class AncientAltarListener implements Listener {
|
||||||
|
|
||||||
private Utilities utilities;
|
private Utilities utilities;
|
||||||
|
|
||||||
|
private final List<Block> altars = new ArrayList<>();
|
||||||
|
private final Set<UUID> removedItems = new HashSet<>();
|
||||||
|
|
||||||
public AncientAltarListener(SlimefunPlugin plugin) {
|
public AncientAltarListener(SlimefunPlugin plugin) {
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
|
||||||
utilities = SlimefunPlugin.getUtilities();
|
utilities = SlimefunPlugin.getUtilities();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Block> altars = new ArrayList<>();
|
|
||||||
private Set<UUID> removedItems = new HashSet<>();
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onInteract(PlayerInteractEvent e) {
|
public void onInteract(PlayerInteractEvent e) {
|
||||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
Block b = e.getClickedBlock();
|
Block b = e.getClickedBlock();
|
||||||
String item = BlockStorage.checkID(b);
|
String item = BlockStorage.checkID(b);
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (item.equals("ANCIENT_PEDESTAL")) {
|
if (item.equals("ANCIENT_PEDESTAL")) {
|
||||||
if (utilities.altarinuse.contains(b.getLocation())) {
|
if (utilities.altarinuse.contains(b.getLocation())) {
|
||||||
@ -81,7 +84,7 @@ public class AncientAltarListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.equals("ANCIENT_ALTAR")) {
|
else if (item.equals("ANCIENT_ALTAR")) {
|
||||||
if (utilities.altarinuse.contains(b.getLocation())) {
|
if (Slimefun.hasUnlocked(e.getPlayer(), SlimefunItems.ANCIENT_ALTAR, true) || utilities.altarinuse.contains(b.getLocation())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -98,7 +101,7 @@ public class AncientAltarListener implements Listener {
|
|||||||
if (pedestals.size() == 8) {
|
if (pedestals.size() == 8) {
|
||||||
pedestals.forEach(block -> utilities.altarinuse.add(block.getLocation()));
|
pedestals.forEach(block -> utilities.altarinuse.add(block.getLocation()));
|
||||||
|
|
||||||
if (catalyst != null && catalyst.getType() != Material.AIR) {
|
if (catalyst.getType() != Material.AIR) {
|
||||||
List<ItemStack> input = new ArrayList<>();
|
List<ItemStack> input = new ArrayList<>();
|
||||||
for (Block pedestal: pedestals) {
|
for (Block pedestal: pedestals) {
|
||||||
Item stack = findItem(pedestal);
|
Item stack = findItem(pedestal);
|
||||||
|
@ -16,7 +16,7 @@ public final class ItemEnergy {
|
|||||||
// "&c&o&8\u21E8 &e\u26A1 &70 / 50 J"
|
// "&c&o&8\u21E8 &e\u26A1 &70 / 50 J"
|
||||||
|
|
||||||
public static float getStoredEnergy(ItemStack item) {
|
public static float getStoredEnergy(ItemStack item) {
|
||||||
if (item == null || item.getType() == null || item.getType() == Material.AIR) return 0F;
|
if (item == null || item.getType() == Material.AIR || item.getAmount() < 1) return 0F;
|
||||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
||||||
|
|
||||||
for (String line: item.getItemMeta().getLore()) {
|
for (String line: item.getItemMeta().getLore()) {
|
||||||
@ -29,7 +29,7 @@ public final class ItemEnergy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float getMaxEnergy(ItemStack item) {
|
public static float getMaxEnergy(ItemStack item) {
|
||||||
if (item == null || item.getType() == null || item.getType() == Material.AIR) return 0F;
|
if (item == null || item.getType() == Material.AIR || item.getAmount() < 1) return 0F;
|
||||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
||||||
|
|
||||||
for (String line: item.getItemMeta().getLore()) {
|
for (String line: item.getItemMeta().getLore()) {
|
||||||
@ -42,7 +42,7 @@ public final class ItemEnergy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float addStoredEnergy(ItemStack item, float energy) {
|
public static float addStoredEnergy(ItemStack item, float energy) {
|
||||||
if (item == null || item.getType() == null || item.getType() == Material.AIR) return 0F;
|
if (item == null || item.getType() == Material.AIR || item.getAmount() < 1) return 0F;
|
||||||
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
if (!item.hasItemMeta() || !item.getItemMeta().hasLore()) return 0F;
|
||||||
|
|
||||||
float rest = 0F;
|
float rest = 0F;
|
||||||
|
@ -14,7 +14,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.CookingRecipe;
|
import org.bukkit.inventory.CookingRecipe;
|
||||||
import org.bukkit.inventory.FurnaceRecipe;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.Recipe;
|
import org.bukkit.inventory.Recipe;
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
Loading…
Reference in New Issue
Block a user