1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

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.
This commit is contained in:
dNiym 2019-08-05 01:15:12 -04:00
parent 33a9a066a3
commit bac456da25
2 changed files with 708 additions and 646 deletions

View File

@ -61,8 +61,9 @@ public abstract class AReactor extends SlimefunItem {
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_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);
@ -96,10 +97,29 @@ public abstract class AReactor extends SlimefunItem {
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);
@ -447,6 +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;
}

View File

@ -18,6 +18,7 @@ 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;
@ -47,6 +48,28 @@ public class ReactorAccessPort extends SlimefunItem {
@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);
}
@ -163,6 +186,24 @@ public class ReactorAccessPort extends SlimefunItem {
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);