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

Merge pull request #995 from dniym/ReactorFix

Reactor fix
This commit is contained in:
TheBusyBiscuit 2019-08-19 09:31:06 +02:00 committed by GitHub
commit 0a840ccea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 716 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 view 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", "&7a reactor!"));
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,33 @@ 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;
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(!empty || !p.isSneaking()) {
//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 +191,27 @@ 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());
String id = BlockStorage.checkID(reactorL);
if(id.equals("NUCLEAR_REACTOR") || id.equals("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);