From bac456da2576f0432ba7bb5b9c0c76279e8ae475 Mon Sep 17 00:00:00 2001 From: dNiym Date: Mon, 5 Aug 2019 01:15:12 -0400 Subject: [PATCH 1/4] REACTOR/PORT UPDATE Update Reactor and Reactor Access Port to be a bit easier to use, now when a reactor detects an attached access port the GUI will be updated to show the two are linked. Once linked the reactor access port will show the status of the actual reactor rather than it's own inventory, allowing users to remotely control the reactor's priority and see the remaining fuel/coolant. Items can still be added to the access port manually or sent in from the cargo manager. --- .../SlimefunItem/abstractItems/AReactor.java | 929 +++++++++--------- .../machines/ReactorAccessPort.java | 425 ++++---- 2 files changed, 708 insertions(+), 646 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java index f1d21858e..ed172e8a3 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java @@ -1,454 +1,475 @@ -package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; -import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; -import me.mrCookieSlime.Slimefun.SlimefunStartup; -import me.mrCookieSlime.Slimefun.Lists.RecipeType; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.ReactorAccessPort; -import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; -import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; -import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; -import me.mrCookieSlime.Slimefun.holograms.ReactorHologram; - -public abstract class AReactor extends SlimefunItem { - - public static Map processing = new HashMap(); - public static Map progress = new HashMap(); - - private static final BlockFace[] cooling = - { - BlockFace.NORTH, - BlockFace.NORTH_EAST, - BlockFace.EAST, - BlockFace.SOUTH_EAST, - BlockFace.SOUTH, - BlockFace.SOUTH_WEST, - BlockFace.WEST, - BlockFace.NORTH_WEST - }; - - private Set recipes = new HashSet(); - - private static final int[] border = {0, 1, 2, 3, 5, 6, 7, 8, 12, 13, 14, 21, 23}; - private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47}; - private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53}; - private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 49, 50}; - private static final int[] border_4 = {25, 34, 43}; // No coolant border - - public AReactor(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) { - super(category, item, id, recipeType, recipe); - - new BlockMenuPreset(id, getInventoryTitle()) { - - @Override - public void init() { - constructMenu(this); - } - - @Override - public void newInstance(final BlockMenu menu, final Block b) { - try { - if (BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode") == null){ - BlockStorage.addBlockInfo(b, "reactor-mode", "generator"); - } - if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode").equals("generator")) { - menu.replaceExistingItem(4, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTM0M2NlNThkYTU0Yzc5OTI0YTJjOTMzMWNmYzQxN2ZlOGNjYmJlYTliZTQ1YTdhYzg1ODYwYTZjNzMwIn19fQ=="), "&7Focus: &eElectricity", "", "&6Your Reactor will focus on Power Generation", "&6If your Energy Network doesn't need Power", "&6it will not produce any either", "", "&7> Click to change the Focus to &eProduction")); - menu.addMenuClickHandler(4, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "reactor-mode", "production"); - newInstance(menu, b); - return false; - }); - } - else { - menu.replaceExistingItem(4, new CustomItem(SlimefunItems.PLUTONIUM, "&7Focus: &eProduction", "", "&6Your Reactor will focus on producing goods", "&6If your Energy Network doesn't need Power", "&6it will continue to run and simply will", "&6not generate any Power in the mean time", "", "&7> Click to change the Focus to &ePower Generation")); - menu.addMenuClickHandler(4, (p, slot, item, action) -> { - BlockStorage.addBlockInfo(b, "reactor-mode", "generator"); - newInstance(menu, b); - return false; - }); - } - } catch(Exception x) { - } - } - - @Override - public boolean canOpen(Block b, Player p) { - return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true); - } - - @Override - public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { - return new int[0]; - } - }; - - registerBlockHandler(id, new SlimefunBlockHandler() { - - @Override - public void onPlace(Player p, Block b, SlimefunItem item) { - } - - @Override - public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { - BlockMenu inv = BlockStorage.getInventory(b); - if (inv != null) { - for (int slot : getFuelSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - for (int slot : getCoolantSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - for (int slot : getOutputSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - } - progress.remove(b.getLocation()); - processing.remove(b.getLocation()); - ReactorHologram.remove(b.getLocation()); - return true; - } - }); - - this.registerDefaultRecipes(); - } - - private void constructMenu(BlockMenuPreset preset) { - for (int i : border) { - preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - for (int i : border_1) { - preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - for (int i : border_3) { - preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - - preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), - (p, slot, item, action) -> false - ); - - for (int i : border_2) { - preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - if (needsCooling()) { - preset.addItem(7, new CustomItem(this.getCoolant(), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode")); - } - else { - preset.addItem(7, new CustomItem(new ItemStack(Material.BARRIER), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells")); - - for (int i : border_4) { - preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), - (p, slot, item, action) -> false - ); - } - } - } - - public abstract String getInventoryTitle(); - - public abstract void registerDefaultRecipes(); - - public abstract int getEnergyProduction(); - - public abstract void extraTick(Location l); - - public abstract ItemStack getCoolant(); - - public boolean needsCooling() { - return getCoolant() != null; - } - - public int[] getInputSlots() { - return new int[] {19, 28, 37, 25, 34, 43}; - } - - public int[] getFuelSlots() { - return new int[] {19, 28, 37}; - } - - public int[] getCoolantSlots() { - return needsCooling() ? new int[] {25, 34, 43} : new int[]{}; - } - - public int[] getOutputSlots() { - return new int[] {40}; - } - - public MachineFuel getProcessing(Location l) { - return processing.get(l); - } - - public boolean isProcessing(Location l) { - return progress.containsKey(l); - } - - public void registerFuel(MachineFuel fuel) { - this.recipes.add(fuel); - } - - @Override - public void register(boolean slimefun) { - addItemHandler(new EnergyTicker() { - - Set explode = new HashSet(); - - @Override - public double generateEnergy(final Location l, SlimefunItem sf, Config data) { - BlockMenu port = getAccessPort(l); - - if (isProcessing(l)) { - extraTick(l); - int timeleft = progress.get(l); - if (timeleft > 0) { - int produced = getEnergyProduction(); - int space = ChargableBlock.getMaxCharge(l) - ChargableBlock.getCharge(l); - if (space >= produced) { - ChargableBlock.addCharge(l, getEnergyProduction()); - space -= produced; - } - if (space >= produced || !BlockStorage.getLocationInfo(l, "reactor-mode").equals("generator")) { - progress.put(l, timeleft - 1); - - Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> { - if (!l.getBlock().getRelative(cooling[CSCoreLib.randomizer().nextInt(cooling.length)]).isLiquid()) explode.add(l); - }); - - ItemStack item = getProgressBar().clone(); - ItemMeta im = item.getItemMeta(); - im.setDisplayName(" "); - List lore = new ArrayList(); - lore.add(MachineHelper.getProgress(timeleft, processing.get(l).getTicks())); - lore.add(MachineHelper.getCoolant(timeleft, processing.get(l).getTicks())); - lore.add(""); - lore.add(MachineHelper.getTimeLeft(timeleft / 2)); - im.setLore(lore); - item.setItemMeta(im); - - BlockStorage.getInventory(l).replaceExistingItem(22, item); - - if (needsCooling()) { - boolean coolant = (processing.get(l).getTicks() - timeleft) % 25 == 0; - - if (coolant) { - if (port != null) { - for (int slot: getCoolantSlots()) { - if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), getCoolant(), true)) { - port.replaceExistingItem(slot, pushItems(l, port.getItemInSlot(slot), getCoolantSlots())); - } - } - } - - boolean explosion = true; - for (int slot: getCoolantSlots()) { - if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), getCoolant(), true)) { - BlockStorage.getInventory(l).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(l).getItemInSlot(slot), 1)); - ReactorHologram.update(l, "&b\u2744 &7100%"); - explosion = false; - break; - } - } - - if (explosion) { - explode.add(l); - return 0; - } - } - else { - ReactorHologram.update(l, "&b\u2744 &7" + MachineHelper.getPercentage(timeleft, processing.get(l).getTicks()) + "%"); - } - } - - return ChargableBlock.getCharge(l); - } - return 0; - } - else { - BlockStorage.getInventory(l).replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); - if (processing.get(l).getOutput() != null) pushItems(l, processing.get(l).getOutput()); - - if (port != null) { - for (int slot: getOutputSlots()) { - if (BlockStorage.getInventory(l).getItemInSlot(slot) != null) BlockStorage.getInventory(l).replaceExistingItem(slot, ReactorAccessPort.pushItems(port.getLocation(), BlockStorage.getInventory(l).getItemInSlot(slot))); - } - } - - progress.remove(l); - processing.remove(l); - return 0; - } - } - else { - MachineFuel r = null; - Map found = new HashMap(); - - if (port != null) { - refill: - for (int slot: getFuelSlots()) { - for (MachineFuel recipe: recipes) { - if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), recipe.getInput(), true)) { - if (pushItems(l, new CustomItem(port.getItemInSlot(slot), 1), getFuelSlots()) == null) { - port.replaceExistingItem(slot, InvUtils.decreaseItem(port.getItemInSlot(slot), 1)); - break refill; - } - } - } - } - } - - outer: - for (MachineFuel recipe: recipes) { - for (int slot: getFuelSlots()) { - if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), recipe.getInput(), true)) { - found.put(slot, recipe.getInput().getAmount()); - r = recipe; - break outer; - } - } - } - - if (r != null) { - for (Map.Entry entry: found.entrySet()) { - BlockStorage.getInventory(l).replaceExistingItem(entry.getKey(), InvUtils.decreaseItem(BlockStorage.getInventory(l).getItemInSlot(entry.getKey()), entry.getValue())); - } - processing.put(l, r); - progress.put(l, r.getTicks()); - } - return 0; - } - } - - @Override - public boolean explode(final Location l) { - final boolean explosion = explode.contains(l); - if (explosion) { - BlockStorage.getInventory(l).close(); - - Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> { - ReactorHologram.remove(l); - }, 0); - - explode.remove(l); - processing.remove(l); - progress.remove(l); - } - return explosion; - } - }); - - super.register(slimefun); - } - - private Inventory inject(Location l) { - int size = BlockStorage.getInventory(l).toInventory().getSize(); - Inventory inv = Bukkit.createInventory(null, size); - for (int i = 0; i < size; i++) { - inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); - } - for (int slot : getOutputSlots()) { - inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); - } - return inv; - } - - private Inventory inject(Location l, int[] slots) { - int size = BlockStorage.getInventory(l).toInventory().getSize(); - Inventory inv = Bukkit.createInventory(null, size); - for (int i = 0; i < size; i++) { - inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); - } - for (int slot : slots) { - inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); - } - return inv; - } - - public void pushItems(Location l, ItemStack item) { - Inventory inv = inject(l); - inv.addItem(item); - - for (int slot: getOutputSlots()) { - BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot)); - } - } - - public ItemStack pushItems(Location l, ItemStack item, int[] slots) { - Inventory inv = inject(l, slots); - Map map = inv.addItem(item); - - for (int slot : slots) { - BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot)); - } - - for (Map.Entry entry : map.entrySet()) { - return entry.getValue(); - } - - return null; - } - - public abstract ItemStack getProgressBar(); - - public Set getFuelTypes() { - return this.recipes; - } - - public BlockMenu getAccessPort(Location l) { - Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ()); - if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL); - return null; - } - -} +package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.InvUtils; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; +import me.mrCookieSlime.CSCoreLibPlugin.general.World.CustomSkull; +import me.mrCookieSlime.Slimefun.SlimefunStartup; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines.ReactorAccessPort; +import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock; +import me.mrCookieSlime.Slimefun.api.energy.EnergyTicker; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; +import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; +import me.mrCookieSlime.Slimefun.holograms.ReactorHologram; + +public abstract class AReactor extends SlimefunItem { + + public static Map processing = new HashMap(); + public static Map progress = new HashMap(); + + private static final BlockFace[] cooling = + { + BlockFace.NORTH, + BlockFace.NORTH_EAST, + BlockFace.EAST, + BlockFace.SOUTH_EAST, + BlockFace.SOUTH, + BlockFace.SOUTH_WEST, + BlockFace.WEST, + BlockFace.NORTH_WEST + }; + + private Set recipes = new HashSet(); + + private static final int[] border = {0, 1, 2, 3, 5, 6, 7, 8, 12, 13, 14, 21, 23}; + private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47}; + private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53}; + private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 50}; + private static final int[] border_4 = {25, 34, 43}; // No coolant border + private static final int infoSlot = 49; + + public AReactor(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, id, recipeType, recipe); + + new BlockMenuPreset(id, getInventoryTitle()) { + + @Override + public void init() { + constructMenu(this); + } + + @Override + public void newInstance(final BlockMenu menu, final Block b) { + try { + if (BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode") == null){ + BlockStorage.addBlockInfo(b, "reactor-mode", "generator"); + } + if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "reactor-mode").equals("generator")) { + menu.replaceExistingItem(4, new CustomItem(CustomSkull.getItem("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTM0M2NlNThkYTU0Yzc5OTI0YTJjOTMzMWNmYzQxN2ZlOGNjYmJlYTliZTQ1YTdhYzg1ODYwYTZjNzMwIn19fQ=="), "&7Focus: &eElectricity", "", "&6Your Reactor will focus on Power Generation", "&6If your Energy Network doesn't need Power", "&6it will not produce any either", "", "&7> Click to change the Focus to &eProduction")); + menu.addMenuClickHandler(4, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "reactor-mode", "production"); + newInstance(menu, b); + return false; + }); + } + else { + menu.replaceExistingItem(4, new CustomItem(SlimefunItems.PLUTONIUM, "&7Focus: &eProduction", "", "&6Your Reactor will focus on producing goods", "&6If your Energy Network doesn't need Power", "&6it will continue to run and simply will", "&6not generate any Power in the mean time", "", "&7> Click to change the Focus to &ePower Generation")); + menu.addMenuClickHandler(4, (p, slot, item, action) -> { + BlockStorage.addBlockInfo(b, "reactor-mode", "generator"); + newInstance(menu, b); + return false; + }); + } + BlockMenu ap = getAccessPort(b.getLocation()); + if(ap != null) { + menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to open Access Port")); + menu.addMenuClickHandler(infoSlot, (p, slot, item, action) -> { + ap.open(p); + newInstance(menu, b); + + return false; + }); + } else { + menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.RED_WOOL), "&7Access Port", "", "&cNot Detected", "", "&7Access Port Must Be", "&7Placed 3 Blocks Above", "&7Reactor!")); + menu.addMenuClickHandler(infoSlot, (p, slot, item, action) -> { + newInstance(menu, b); + menu.open(p); + return false; + }); + } + + } catch(Exception x) { + } + } + + + @Override + public boolean canOpen(Block b, Player p) { + return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true); + } + + @Override + public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { + return new int[0]; + } + }; + + registerBlockHandler(id, new SlimefunBlockHandler() { + + @Override + public void onPlace(Player p, Block b, SlimefunItem item) { + } + + @Override + public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { + BlockMenu inv = BlockStorage.getInventory(b); + if (inv != null) { + for (int slot : getFuelSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + for (int slot : getCoolantSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + for (int slot : getOutputSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + } + progress.remove(b.getLocation()); + processing.remove(b.getLocation()); + ReactorHologram.remove(b.getLocation()); + return true; + } + }); + + this.registerDefaultRecipes(); + } + + private void constructMenu(BlockMenuPreset preset) { + for (int i : border) { + preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + for (int i : border_1) { + preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + for (int i : border_3) { + preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + + preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), + (p, slot, item, action) -> false + ); + + for (int i : border_2) { + preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + if (needsCooling()) { + preset.addItem(7, new CustomItem(this.getCoolant(), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode")); + } + else { + preset.addItem(7, new CustomItem(new ItemStack(Material.BARRIER), "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells")); + + for (int i : border_4) { + preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), + (p, slot, item, action) -> false + ); + } + } + } + + public abstract String getInventoryTitle(); + + public abstract void registerDefaultRecipes(); + + public abstract int getEnergyProduction(); + + public abstract void extraTick(Location l); + + public abstract ItemStack getCoolant(); + + public boolean needsCooling() { + return getCoolant() != null; + } + + public int[] getInputSlots() { + return new int[] {19, 28, 37, 25, 34, 43}; + } + + public int[] getFuelSlots() { + return new int[] {19, 28, 37}; + } + + public int[] getCoolantSlots() { + return needsCooling() ? new int[] {25, 34, 43} : new int[]{}; + } + + public int[] getOutputSlots() { + return new int[] {40}; + } + + public MachineFuel getProcessing(Location l) { + return processing.get(l); + } + + public boolean isProcessing(Location l) { + return progress.containsKey(l); + } + + public void registerFuel(MachineFuel fuel) { + this.recipes.add(fuel); + } + + @Override + public void register(boolean slimefun) { + addItemHandler(new EnergyTicker() { + + Set explode = new HashSet(); + + @Override + public double generateEnergy(final Location l, SlimefunItem sf, Config data) { + BlockMenu port = getAccessPort(l); + + if (isProcessing(l)) { + extraTick(l); + int timeleft = progress.get(l); + if (timeleft > 0) { + int produced = getEnergyProduction(); + int space = ChargableBlock.getMaxCharge(l) - ChargableBlock.getCharge(l); + if (space >= produced) { + ChargableBlock.addCharge(l, getEnergyProduction()); + space -= produced; + } + if (space >= produced || !BlockStorage.getLocationInfo(l, "reactor-mode").equals("generator")) { + progress.put(l, timeleft - 1); + + Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> { + if (!l.getBlock().getRelative(cooling[CSCoreLib.randomizer().nextInt(cooling.length)]).isLiquid()) explode.add(l); + }); + + ItemStack item = getProgressBar().clone(); + ItemMeta im = item.getItemMeta(); + im.setDisplayName(" "); + List lore = new ArrayList(); + lore.add(MachineHelper.getProgress(timeleft, processing.get(l).getTicks())); + lore.add(MachineHelper.getCoolant(timeleft, processing.get(l).getTicks())); + lore.add(""); + lore.add(MachineHelper.getTimeLeft(timeleft / 2)); + im.setLore(lore); + item.setItemMeta(im); + + BlockStorage.getInventory(l).replaceExistingItem(22, item); + + if (needsCooling()) { + boolean coolant = (processing.get(l).getTicks() - timeleft) % 25 == 0; + + if (coolant) { + if (port != null) { + for (int slot: getCoolantSlots()) { + if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), getCoolant(), true)) { + port.replaceExistingItem(slot, pushItems(l, port.getItemInSlot(slot), getCoolantSlots())); + } + } + } + + boolean explosion = true; + for (int slot: getCoolantSlots()) { + if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), getCoolant(), true)) { + BlockStorage.getInventory(l).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(l).getItemInSlot(slot), 1)); + ReactorHologram.update(l, "&b\u2744 &7100%"); + explosion = false; + break; + } + } + + if (explosion) { + explode.add(l); + return 0; + } + } + else { + ReactorHologram.update(l, "&b\u2744 &7" + MachineHelper.getPercentage(timeleft, processing.get(l).getTicks()) + "%"); + } + } + + return ChargableBlock.getCharge(l); + } + return 0; + } + else { + BlockStorage.getInventory(l).replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " ")); + if (processing.get(l).getOutput() != null) pushItems(l, processing.get(l).getOutput()); + + if (port != null) { + for (int slot: getOutputSlots()) { + if (BlockStorage.getInventory(l).getItemInSlot(slot) != null) BlockStorage.getInventory(l).replaceExistingItem(slot, ReactorAccessPort.pushItems(port.getLocation(), BlockStorage.getInventory(l).getItemInSlot(slot))); + } + } + + progress.remove(l); + processing.remove(l); + return 0; + } + } + else { + MachineFuel r = null; + Map found = new HashMap(); + + if (port != null) { + refill: + for (int slot: getFuelSlots()) { + for (MachineFuel recipe: recipes) { + if (SlimefunManager.isItemSimiliar(port.getItemInSlot(slot), recipe.getInput(), true)) { + if (pushItems(l, new CustomItem(port.getItemInSlot(slot), 1), getFuelSlots()) == null) { + port.replaceExistingItem(slot, InvUtils.decreaseItem(port.getItemInSlot(slot), 1)); + break refill; + } + } + } + } + } + + outer: + for (MachineFuel recipe: recipes) { + for (int slot: getFuelSlots()) { + if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), recipe.getInput(), true)) { + found.put(slot, recipe.getInput().getAmount()); + r = recipe; + break outer; + } + } + } + + if (r != null) { + for (Map.Entry entry: found.entrySet()) { + BlockStorage.getInventory(l).replaceExistingItem(entry.getKey(), InvUtils.decreaseItem(BlockStorage.getInventory(l).getItemInSlot(entry.getKey()), entry.getValue())); + } + processing.put(l, r); + progress.put(l, r.getTicks()); + } + return 0; + } + } + + @Override + public boolean explode(final Location l) { + final boolean explosion = explode.contains(l); + if (explosion) { + BlockStorage.getInventory(l).close(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> { + ReactorHologram.remove(l); + }, 0); + + explode.remove(l); + processing.remove(l); + progress.remove(l); + } + return explosion; + } + }); + + super.register(slimefun); + } + + private Inventory inject(Location l) { + int size = BlockStorage.getInventory(l).toInventory().getSize(); + Inventory inv = Bukkit.createInventory(null, size); + for (int i = 0; i < size; i++) { + inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); + } + for (int slot : getOutputSlots()) { + inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); + } + return inv; + } + + private Inventory inject(Location l, int[] slots) { + int size = BlockStorage.getInventory(l).toInventory().getSize(); + Inventory inv = Bukkit.createInventory(null, size); + for (int i = 0; i < size; i++) { + inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); + } + for (int slot : slots) { + inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); + } + return inv; + } + + public void pushItems(Location l, ItemStack item) { + Inventory inv = inject(l); + inv.addItem(item); + + for (int slot: getOutputSlots()) { + BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot)); + } + } + + public ItemStack pushItems(Location l, ItemStack item, int[] slots) { + Inventory inv = inject(l, slots); + Map map = inv.addItem(item); + + for (int slot : slots) { + BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot)); + } + + for (Map.Entry entry : map.entrySet()) { + return entry.getValue(); + } + + return null; + } + + public abstract ItemStack getProgressBar(); + + public Set getFuelTypes() { + return this.recipes; + } + + public BlockMenu getAccessPort(Location l) { + Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ()); + + if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL); + return null; + } + +} diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java index 75b7c1a45..6b583eda8 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java @@ -1,192 +1,233 @@ -package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines; - -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; -import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; -import me.mrCookieSlime.Slimefun.Lists.RecipeType; -import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; -import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; -import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; -import me.mrCookieSlime.Slimefun.api.BlockStorage; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; -import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; - -public class ReactorAccessPort extends SlimefunItem { - - private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 21, 23}; - private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47}; - private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53}; - private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 49, 50}; - - public ReactorAccessPort(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) { - super(category, item, name, recipeType, recipe); - - new BlockMenuPreset(name, getInventoryTitle()) { - - @Override - public void init() { - constructMenu(this); - } - - @Override - public void newInstance(BlockMenu menu, Block b) { - } - - @Override - public boolean canOpen(Block b, Player p) { - return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true); - } - - @Override - public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { - if (flow.equals(ItemTransportFlow.INSERT)) return getInputSlots(); - else return getOutputSlots(); - } - - @Override - public int[] getSlotsAccessedByItemTransport(BlockMenu menu, ItemTransportFlow flow, ItemStack item) { - if (flow.equals(ItemTransportFlow.INSERT)) { - if (SlimefunManager.isItemSimiliar(item, SlimefunItems.REACTOR_COOLANT_CELL, true)) return getCoolantSlots(); - else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.NETHER_ICE_COOLANT_CELL, true)) return getCoolantSlots(); - else return getFuelSlots(); - } - else return getOutputSlots(); - } - }; - - registerBlockHandler(name, new SlimefunBlockHandler() { - - @Override - public void onPlace(Player p, Block b, SlimefunItem item) { - } - - @Override - public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { - BlockMenu inv = BlockStorage.getInventory(b); - if (inv != null) { - for (int slot : getFuelSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - for (int slot : getCoolantSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - for (int slot : getOutputSlots()) { - if (inv.getItemInSlot(slot) != null) { - b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); - inv.replaceExistingItem(slot, null); - } - } - } - return true; - } - }); - } - - private void constructMenu(BlockMenuPreset preset) { - for (int i : border) { - preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - for (int i : border_1) { - preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - for (int i : border_2) { - preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - for (int i : border_3) { - preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); - } - - preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), - (p, slot, item, action) -> false - ); - - preset.addItem(22, new CustomItem(SlimefunItems.PLUTONIUM, "&7Byproduct Slot", "", "&rThis Slot contains the Reactor's Byproduct", "&rsuch as &aNeptunium &ror &7Plutonium"), - (p, slot, item, action) -> false - ); - - preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"), - (p, slot, item, action) -> false - ); - - preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"), - (p, slot, item, action) -> false - ); - } - - public String getInventoryTitle() { - return "&2Reactor Access Port"; - } - - public int[] getInputSlots() { - return new int[] {19, 28, 37, 25, 34, 43}; - } - - public int[] getFuelSlots() { - return new int[] {19, 28, 37}; - } - - public int[] getCoolantSlots() { - return new int[] {25, 34, 43}; - } - - public static int[] getOutputSlots() { - return new int[] {40}; - } - - private static Inventory inject(Location l) { - int size = BlockStorage.getInventory(l).toInventory().getSize(); - Inventory inv = Bukkit.createInventory(null, size); - for (int i = 0; i < size; i++) { - inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); - } - for (int slot : getOutputSlots()) { - inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); - } - return inv; - } - - public static ItemStack pushItems(Location l, ItemStack item) { - Inventory inv = inject(l); - Map map = inv.addItem(item); - - for (int slot: getOutputSlots()) { - BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot)); - } - - for (Map.Entry entry: map.entrySet()) { - return entry.getValue(); - } - return null; - } - -} +package me.mrCookieSlime.Slimefun.Objects.SlimefunItem.machines; + +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import me.mrCookieSlime.CSCoreLibPlugin.CSCoreLib; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AReactor; +import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; +import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; + +public class ReactorAccessPort extends SlimefunItem { + + private static final int[] border = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 13, 14, 21, 23}; + private static final int[] border_1 = {9, 10, 11, 18, 20, 27, 29, 36, 38, 45, 46, 47}; + private static final int[] border_2 = {15, 16, 17, 24, 26, 33, 35, 42, 44, 51, 52, 53}; + private static final int[] border_3 = {30, 31, 32, 39, 41, 48, 49, 50}; + + public ReactorAccessPort(Category category, ItemStack item, String name, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, name, recipeType, recipe); + + new BlockMenuPreset(name, getInventoryTitle()) { + + @Override + public void init() { + constructMenu(this); + } + + @Override + public void newInstance(BlockMenu menu, Block b) { + } + + @Override + public boolean canOpen(Block b, Player p) { + AReactor reactor = getReactor(b.getLocation()); + if(reactor != null) { + boolean empty = true; + BlockMenu bm = getReactorMenu(b.getLocation()); + if(bm != null) { + for(int slot:reactor.getCoolantSlots()) + if(bm.getItemInSlot(slot) != null) + empty = false; + for(int slot:reactor.getFuelSlots()) + if(bm.getItemInSlot(slot) != null) + empty = false; + + if(!p.isSneaking() && !empty && (p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(),b,true))) { + //reactor is not empty, lets view it's inventory instead. + bm.open(p); + return false; + } + } + + + + } + return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true); + } + + @Override + public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) { + if (flow.equals(ItemTransportFlow.INSERT)) return getInputSlots(); + else return getOutputSlots(); + } + + @Override + public int[] getSlotsAccessedByItemTransport(BlockMenu menu, ItemTransportFlow flow, ItemStack item) { + if (flow.equals(ItemTransportFlow.INSERT)) { + if (SlimefunManager.isItemSimiliar(item, SlimefunItems.REACTOR_COOLANT_CELL, true)) return getCoolantSlots(); + else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.NETHER_ICE_COOLANT_CELL, true)) return getCoolantSlots(); + else return getFuelSlots(); + } + else return getOutputSlots(); + } + }; + + registerBlockHandler(name, new SlimefunBlockHandler() { + + @Override + public void onPlace(Player p, Block b, SlimefunItem item) { + } + + @Override + public boolean onBreak(Player p, Block b, SlimefunItem item, UnregisterReason reason) { + BlockMenu inv = BlockStorage.getInventory(b); + if (inv != null) { + for (int slot : getFuelSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + for (int slot : getCoolantSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + for (int slot : getOutputSlots()) { + if (inv.getItemInSlot(slot) != null) { + b.getWorld().dropItemNaturally(b.getLocation(), inv.getItemInSlot(slot)); + inv.replaceExistingItem(slot, null); + } + } + } + return true; + } + }); + } + + private void constructMenu(BlockMenuPreset preset) { + for (int i : border) { + preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + for (int i : border_1) { + preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + for (int i : border_2) { + preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + for (int i : border_3) { + preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), + (p, slot, item, action) -> false + ); + } + + preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), + (p, slot, item, action) -> false + ); + + preset.addItem(22, new CustomItem(SlimefunItems.PLUTONIUM, "&7Byproduct Slot", "", "&rThis Slot contains the Reactor's Byproduct", "&rsuch as &aNeptunium &ror &7Plutonium"), + (p, slot, item, action) -> false + ); + + preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"), + (p, slot, item, action) -> false + ); + + preset.addItem(7, new CustomItem(SlimefunItems.REACTOR_COOLANT_CELL, "&bCoolant Slot", "", "&rThis Slot accepts Coolant Cells", "&4Without any Coolant Cells, your Reactor", "&4will explode"), + (p, slot, item, action) -> false + ); + } + + public String getInventoryTitle() { + return "&2Reactor Access Port"; + } + + public int[] getInputSlots() { + return new int[] {19, 28, 37, 25, 34, 43}; + } + + public int[] getFuelSlots() { + return new int[] {19, 28, 37}; + } + + public int[] getCoolantSlots() { + return new int[] {25, 34, 43}; + } + + public static int[] getOutputSlots() { + return new int[] {40}; + } + + public AReactor getReactor(Location l) { + Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); + SlimefunItem item = BlockStorage.check(reactorL.getBlock()); + if(item instanceof AReactor) + return (AReactor) item; + + return null; + } + + public BlockMenu getReactorMenu(Location l) { + Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); + + if (BlockStorage.check(reactorL, "NUCLEAR_REACTOR")) return BlockStorage.getInventory(reactorL); + + if (BlockStorage.check(reactorL, "NETHERSTAR_REACTOR")) return BlockStorage.getInventory(reactorL); + return null; + } + + private static Inventory inject(Location l) { + int size = BlockStorage.getInventory(l).toInventory().getSize(); + Inventory inv = Bukkit.createInventory(null, size); + for (int i = 0; i < size; i++) { + inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); + } + for (int slot : getOutputSlots()) { + inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); + } + return inv; + } + + public static ItemStack pushItems(Location l, ItemStack item) { + Inventory inv = inject(l); + Map map = inv.addItem(item); + + for (int slot: getOutputSlots()) { + BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot)); + } + + for (Map.Entry entry: map.entrySet()) { + return entry.getValue(); + } + return null; + } + +} From 8a569399318172dd2d1ec6eb1f8b5b86f5a6831d Mon Sep 17 00:00:00 2001 From: dNiym Date: Mon, 5 Aug 2019 09:44:40 -0400 Subject: [PATCH 2/4] Made Requested Changes --- .../SlimefunItem/abstractItems/AReactor.java | 4 ++-- .../SlimefunItem/machines/ReactorAccessPort.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java index ed172e8a3..ec5c7ad3e 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java @@ -99,7 +99,7 @@ public abstract class AReactor extends SlimefunItem { } BlockMenu ap = getAccessPort(b.getLocation()); if(ap != null) { - menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to open Access Port")); + menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to view Access Port")); menu.addMenuClickHandler(infoSlot, (p, slot, item, action) -> { ap.open(p); newInstance(menu, b); @@ -107,7 +107,7 @@ public abstract class AReactor extends SlimefunItem { return false; }); } else { - menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.RED_WOOL), "&7Access Port", "", "&cNot Detected", "", "&7Access Port Must Be", "&7Placed 3 Blocks Above", "&7Reactor!")); + menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.RED_WOOL), "&7Access Port", "", "&cNot detected", "", "&7Access Port must be", "&7placed 3 blocks above", "&7a reactor!")); menu.addMenuClickHandler(infoSlot, (p, slot, item, action) -> { newInstance(menu, b); menu.open(p); diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java index 6b583eda8..f7be9efcb 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java @@ -48,6 +48,11 @@ public class ReactorAccessPort extends SlimefunItem { @Override public boolean canOpen(Block b, Player p) { + if(p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(),b,true)) { + return false; + } + + AReactor reactor = getReactor(b.getLocation()); if(reactor != null) { boolean empty = true; @@ -60,7 +65,7 @@ public class ReactorAccessPort extends SlimefunItem { if(bm.getItemInSlot(slot) != null) empty = false; - if(!p.isSneaking() && !empty && (p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(),b,true))) { + if(!empty || !p.isSneaking()) { //reactor is not empty, lets view it's inventory instead. bm.open(p); return false; @@ -198,9 +203,11 @@ public class ReactorAccessPort extends SlimefunItem { public BlockMenu getReactorMenu(Location l) { Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); - if (BlockStorage.check(reactorL, "NUCLEAR_REACTOR")) return BlockStorage.getInventory(reactorL); + SlimefunItem item = BlockStorage.check(reactorL); + + if(item != null && (item.getID().equals("NUCLEAR_REACTOR") || item.getID().equals("NETHERSTAR_REACTOR"))) + return BlockStorage.getInventory(reactorL); - if (BlockStorage.check(reactorL, "NETHERSTAR_REACTOR")) return BlockStorage.getInventory(reactorL); return null; } From aeacac0b01418636d65749627096e7f3fa60764e Mon Sep 17 00:00:00 2001 From: dNiym Date: Sun, 18 Aug 2019 14:47:25 -0400 Subject: [PATCH 3/4] Updated with requested changes --- .../SlimefunItem/abstractItems/AReactor.java | 74 +++++++++---------- .../machines/ReactorAccessPort.java | 5 +- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java index ec5c7ad3e..7621e48de 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AReactor.java @@ -46,14 +46,14 @@ public abstract class AReactor extends SlimefunItem { private static final BlockFace[] cooling = { - BlockFace.NORTH, - BlockFace.NORTH_EAST, - BlockFace.EAST, - BlockFace.SOUTH_EAST, - BlockFace.SOUTH, - BlockFace.SOUTH_WEST, - BlockFace.WEST, - BlockFace.NORTH_WEST + BlockFace.NORTH, + BlockFace.NORTH_EAST, + BlockFace.EAST, + BlockFace.SOUTH_EAST, + BlockFace.SOUTH, + BlockFace.SOUTH_WEST, + BlockFace.WEST, + BlockFace.NORTH_WEST }; private Set recipes = new HashSet(); @@ -101,9 +101,9 @@ public abstract class AReactor extends SlimefunItem { if(ap != null) { menu.replaceExistingItem(infoSlot, new CustomItem(new ItemStack(Material.GREEN_WOOL), "&7Access Port", "", "&6Detected", "", "&7> Click to view Access Port")); menu.addMenuClickHandler(infoSlot, (p, slot, item, action) -> { - ap.open(p); - newInstance(menu, b); - + ap.open(p); + newInstance(menu, b); + return false; }); } else { @@ -114,12 +114,12 @@ public abstract class AReactor extends SlimefunItem { return false; }); } - + } catch(Exception x) { } } - + @Override public boolean canOpen(Block b, Player p) { return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true); @@ -173,34 +173,34 @@ public abstract class AReactor extends SlimefunItem { private void constructMenu(BlockMenuPreset preset) { for (int i : border) { preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); } for (int i : border_1) { preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); } for (int i : border_3) { preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); } preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); preset.addItem(1, new CustomItem(SlimefunItems.URANIUM, "&7Fuel Slot", "", "&rThis Slot accepts radioactive Fuel such as:", "&2Uranium &ror &aNeptunium"), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); for (int i : border_2) { preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); } if (needsCooling()) { @@ -211,8 +211,8 @@ public abstract class AReactor extends SlimefunItem { for (int i : border_4) { preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), - (p, slot, item, action) -> false - ); + (p, slot, item, action) -> false + ); } } } @@ -369,15 +369,15 @@ public abstract class AReactor extends SlimefunItem { } outer: - for (MachineFuel recipe: recipes) { - for (int slot: getFuelSlots()) { - if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), recipe.getInput(), true)) { - found.put(slot, recipe.getInput().getAmount()); - r = recipe; - break outer; + for (MachineFuel recipe: recipes) { + for (int slot: getFuelSlots()) { + if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), recipe.getInput(), true)) { + found.put(slot, recipe.getInput().getAmount()); + r = recipe; + break outer; + } } } - } if (r != null) { for (Map.Entry entry: found.entrySet()) { @@ -395,11 +395,11 @@ public abstract class AReactor extends SlimefunItem { final boolean explosion = explode.contains(l); if (explosion) { BlockStorage.getInventory(l).close(); - + Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> { ReactorHologram.remove(l); }, 0); - + explode.remove(l); processing.remove(l); progress.remove(l); @@ -467,7 +467,7 @@ public abstract class AReactor extends SlimefunItem { public BlockMenu getAccessPort(Location l) { Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ()); - + if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL); return null; } diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java index f7be9efcb..05520775e 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java @@ -193,6 +193,7 @@ public class ReactorAccessPort extends SlimefunItem { public AReactor getReactor(Location l) { Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); + SlimefunItem item = BlockStorage.check(reactorL.getBlock()); if(item instanceof AReactor) return (AReactor) item; @@ -203,9 +204,7 @@ public class ReactorAccessPort extends SlimefunItem { public BlockMenu getReactorMenu(Location l) { Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); - SlimefunItem item = BlockStorage.check(reactorL); - - if(item != null && (item.getID().equals("NUCLEAR_REACTOR") || item.getID().equals("NETHERSTAR_REACTOR"))) + if(BlockStorage.checkID(reactorL).equals("NUCLEAR_REACTOR") || BlockStorage.checkID(reactorL).equals("NETHERSTAR_REACTOR")) return BlockStorage.getInventory(reactorL); return null; From 24187648063e3f7f12146cc88e85cc9fb838fabb Mon Sep 17 00:00:00 2001 From: dNiym Date: Sun, 18 Aug 2019 23:43:22 -0400 Subject: [PATCH 4/4] Use a variable to compare reactor id types. --- .../Objects/SlimefunItem/machines/ReactorAccessPort.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java index 05520775e..52f266cca 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/machines/ReactorAccessPort.java @@ -204,7 +204,9 @@ public class ReactorAccessPort extends SlimefunItem { public BlockMenu getReactorMenu(Location l) { Location reactorL = new Location(l.getWorld(), l.getX(), l.getY() - 3, l.getZ()); - if(BlockStorage.checkID(reactorL).equals("NUCLEAR_REACTOR") || BlockStorage.checkID(reactorL).equals("NETHERSTAR_REACTOR")) + String id = BlockStorage.checkID(reactorL); + + if(id.equals("NUCLEAR_REACTOR") || id.equals("NETHERSTAR_REACTOR")) return BlockStorage.getInventory(reactorL); return null;