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

@ -46,14 +46,14 @@ public abstract class AReactor extends SlimefunItem {
private static final BlockFace[] cooling = private static final BlockFace[] cooling =
{ {
BlockFace.NORTH, BlockFace.NORTH,
BlockFace.NORTH_EAST, BlockFace.NORTH_EAST,
BlockFace.EAST, BlockFace.EAST,
BlockFace.SOUTH_EAST, BlockFace.SOUTH_EAST,
BlockFace.SOUTH, BlockFace.SOUTH,
BlockFace.SOUTH_WEST, BlockFace.SOUTH_WEST,
BlockFace.WEST, BlockFace.WEST,
BlockFace.NORTH_WEST BlockFace.NORTH_WEST
}; };
private Set<MachineFuel> recipes = new HashSet<MachineFuel>(); private Set<MachineFuel> recipes = new HashSet<MachineFuel>();
@ -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 = {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_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_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[] 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) { public AReactor(Category category, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, id, recipeType, recipe); super(category, item, id, recipeType, recipe);
@ -96,10 +97,29 @@ public abstract class AReactor extends SlimefunItem {
return false; 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) { } catch(Exception x) {
} }
} }
@Override @Override
public boolean canOpen(Block b, Player p) { public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true); return p.hasPermission("slimefun.inventory.bypass") || CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true);
@ -153,34 +173,34 @@ public abstract class AReactor extends SlimefunItem {
private void constructMenu(BlockMenuPreset preset) { private void constructMenu(BlockMenuPreset preset) {
for (int i : border) { for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), 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) { for (int i : border_1) {
preset.addItem(i, new CustomItem(new ItemStack(Material.LIME_STAINED_GLASS_PANE), " "), 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) { for (int i : border_3) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GREEN_STAINED_GLASS_PANE), " "), 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), " "), 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"), 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) { for (int i : border_2) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "),
(p, slot, item, action) -> false (p, slot, item, action) -> false
); );
} }
if (needsCooling()) { if (needsCooling()) {
@ -191,8 +211,8 @@ public abstract class AReactor extends SlimefunItem {
for (int i : border_4) { for (int i : border_4) {
preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"), preset.addItem(i, new CustomItem(new ItemStack(Material.BARRIER), "&cNo Coolant Required"),
(p, slot, item, action) -> false (p, slot, item, action) -> false
); );
} }
} }
} }
@ -349,15 +369,15 @@ public abstract class AReactor extends SlimefunItem {
} }
outer: outer:
for (MachineFuel recipe: recipes) { for (MachineFuel recipe: recipes) {
for (int slot: getFuelSlots()) { for (int slot: getFuelSlots()) {
if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), recipe.getInput(), true)) { if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(l).getItemInSlot(slot), recipe.getInput(), true)) {
found.put(slot, recipe.getInput().getAmount()); found.put(slot, recipe.getInput().getAmount());
r = recipe; r = recipe;
break outer; break outer;
}
} }
} }
}
if (r != null) { if (r != null) {
for (Map.Entry<Integer, Integer> entry: found.entrySet()) { for (Map.Entry<Integer, Integer> entry: found.entrySet()) {
@ -447,6 +467,7 @@ public abstract class AReactor extends SlimefunItem {
public BlockMenu getAccessPort(Location l) { public BlockMenu getAccessPort(Location l) {
Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ()); Location portL = new Location(l.getWorld(), l.getX(), l.getY() + 3, l.getZ());
if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL); if (BlockStorage.check(portL, "REACTOR_ACCESS_PORT")) return BlockStorage.getInventory(portL);
return null; 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.SlimefunBlockHandler;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.UnregisterReason; 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.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
@ -47,6 +48,33 @@ public class ReactorAccessPort extends SlimefunItem {
@Override @Override
public boolean canOpen(Block b, Player p) { 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); 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}; 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) { private static Inventory inject(Location l) {
int size = BlockStorage.getInventory(l).toInventory().getSize(); int size = BlockStorage.getInventory(l).toInventory().getSize();
Inventory inv = Bukkit.createInventory(null, size); Inventory inv = Bukkit.createInventory(null, size);