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

Fixed Ignition Chamber Bug

This commit is contained in:
TheBusyBiscuit 2019-08-27 17:55:20 +02:00
parent 04444fc298
commit 3d3f1b6c87
4 changed files with 27 additions and 38 deletions

View File

@ -87,7 +87,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem {
public int[] getSlotsAccessedByItemTransport(BlockMenu menu, ItemTransportFlow flow, ItemStack item) { public int[] getSlotsAccessedByItemTransport(BlockMenu menu, ItemTransportFlow flow, ItemStack item) {
if (flow.equals(ItemTransportFlow.WITHDRAW)) return getOutputSlots(); if (flow.equals(ItemTransportFlow.WITHDRAW)) return getOutputSlots();
List<Integer> slots = new ArrayList<Integer>(); List<Integer> slots = new ArrayList<>();
for (int slot : getInputSlots()) { for (int slot : getInputSlots()) {
if (menu.getItemInSlot(slot) != null) slots.add(slot); if (menu.getItemInSlot(slot) != null) slots.add(slot);
} }
@ -134,19 +134,15 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem {
protected void constructMenu(BlockMenuPreset preset) { protected 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_in) { for (int i : border_in) {
preset.addItem(i, new CustomItem(new ItemStack(Material.BLUE_STAINED_GLASS_PANE), " "), preset.addItem(i, new CustomItem(new ItemStack(Material.BLUE_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
(p, slot, item, action) -> false
);
} }
for (int i : border_out) { for (int i : border_out) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), (p, slot, item, action) -> false);
(p, slot, item, action) -> false
);
} }
for (int i : getOutputSlots()) { for (int i : getOutputSlots()) {
@ -164,9 +160,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem {
}); });
} }
preset.addItem(2, new CustomItem(new ItemStack(Material.CRAFTING_TABLE), "&eRecipe", "", "&bPut in the Recipe you want to craft", "&4Enhanced Crafting Table Recipes ONLY"), preset.addItem(2, new CustomItem(new ItemStack(Material.CRAFTING_TABLE), "&eRecipe", "", "&bPut in the Recipe you want to craft", "&4Enhanced Crafting Table Recipes ONLY"), (p, slot, item, action) -> false);
(p, slot, item, action) -> false
);
} }
public abstract int getEnergyConsumption(); public abstract int getEnergyConsumption();
@ -182,12 +176,15 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem {
private Inventory inject(Block b) { private Inventory inject(Block b) {
int size = BlockStorage.getInventory(b).toInventory().getSize(); int size = BlockStorage.getInventory(b).toInventory().getSize();
Inventory inv = Bukkit.createInventory(null, size); Inventory inv = Bukkit.createInventory(null, size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US")); inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US"));
} }
for (int slot : getOutputSlots()) { for (int slot : getOutputSlots()) {
inv.setItem(slot, BlockStorage.getInventory(b).getItemInSlot(slot)); inv.setItem(slot, BlockStorage.getInventory(b).getItemInSlot(slot));
} }
return inv; return inv;
} }
@ -240,9 +237,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem {
} }
ItemStack item = menu.getItemInSlot(getInputSlots()[j]); ItemStack item = menu.getItemInSlot(getInputSlots()[j]);
if (item != null && item.getAmount() == 1) return; if (item != null && item.getAmount() == 1) return;
builder.append(CustomItemSerializer.serialize(item, ItemFlag.MATERIAL, ItemFlag.ITEMMETA_DISPLAY_NAME, ItemFlag.ITEMMETA_LORE)); builder.append(CustomItemSerializer.serialize(item, ItemFlag.MATERIAL, ItemFlag.ITEMMETA_DISPLAY_NAME, ItemFlag.ITEMMETA_LORE));
i++; i++;

View File

@ -721,8 +721,6 @@ public class SlimefunSetup {
new String[] {"chance.fireBreak"}, new Integer[] {34}) new String[] {"chance.fireBreak"}, new Integer[] {34})
.register(true, new MultiBlockInteractionHandler() { .register(true, new MultiBlockInteractionHandler() {
private final String chamberID = "IGNITION_CHAMBER";
@Override @Override
public boolean onInteract(Player p, MultiBlock mb, Block b) { public boolean onInteract(Player p, MultiBlock mb, Block b) {
@ -761,24 +759,8 @@ public class SlimefunSetup {
outputInv.addItem(adding); outputInv.addItem(adding);
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1);
p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
// Block raw_disp = b.getRelative(BlockFace.DOWN);
// raw_disp has been removed since the outputInv functionality already uses such an object which is declared above as dispBlock.
// The chamber methods have been updated to reflect this change.
// Maybe this code snippet should be turned into a loop?
Hopper chamber = null;
if (BlockStorage.check(dispBlock.getRelative(BlockFace.EAST).getState().getBlock(), chamberID)) { Hopper chamber = findHopper(dispBlock, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
chamber = (Hopper) dispBlock.getRelative(BlockFace.EAST).getState();
}
else if (BlockStorage.check(dispBlock.getRelative(BlockFace.WEST).getState().getBlock(), chamberID)) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.WEST).getState();
}
else if (BlockStorage.check(dispBlock.getRelative(BlockFace.NORTH).getState().getBlock(), chamberID)) {
chamber = (Hopper) dispBlock.getRelative(BlockFace.NORTH).getState();
}
else if (BlockStorage.check(dispBlock.getRelative(BlockFace.SOUTH).getState().getBlock(), chamberID)){
chamber = (Hopper) dispBlock.getRelative(BlockFace.SOUTH).getState();
}
if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak"))) { if (SlimefunStartup.chance(100, (Integer) Slimefun.getItemValue("SMELTERY", "chance.fireBreak"))) {
if (chamber != null) { if (chamber != null) {
@ -787,10 +769,12 @@ public class SlimefunSetup {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + 1); ((Damageable) meta).setDamage(((Damageable) meta).getDamage() + 1);
item.setItemMeta(meta); item.setItemMeta(meta);
if (((Damageable) item.getItemMeta()).getDamage() >= item.getType().getMaxDurability()) { if (((Damageable) item.getItemMeta()).getDamage() >= item.getType().getMaxDurability()) {
item.setAmount(0); item.setAmount(0);
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
} }
p.getWorld().playSound(p.getLocation(), Sound.ITEM_FLINTANDSTEEL_USE, 1, 1); p.getWorld().playSound(p.getLocation(), Sound.ITEM_FLINTANDSTEEL_USE, 1, 1);
} }
else { else {
@ -820,6 +804,16 @@ public class SlimefunSetup {
} }
else return false; else return false;
} }
private Hopper findHopper(Block b, BlockFace... faces) {
for (BlockFace face: faces) {
if (b.getRelative(face).getType() == Material.HOPPER && BlockStorage.check(b.getRelative(face), "IGNITION_CHAMBER")) {
return (Hopper) b.getRelative(face).getState();
}
}
return null;
}
}); });

View File

@ -6,7 +6,7 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public class RecipeSorter implements Comparator<Integer> { public class RecipeSorter implements Comparator<Integer> {
BlockMenu menu; private BlockMenu menu;
public RecipeSorter(BlockMenu menu) { public RecipeSorter(BlockMenu menu) {
this.menu = menu; this.menu = menu;