1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Maybe fixes #1951 (+ performance improvements)

This commit is contained in:
TheBusyBiscuit 2020-08-20 23:25:43 +02:00
parent 1a8dbb587a
commit 167326292d
3 changed files with 52 additions and 27 deletions

View File

@ -44,6 +44,7 @@
* Small performance improvements for Slimefun guides
* Small performance improvements for Cargo networks
* Small performance improvements for Miner Androids
* Small performance improvements for all machines, especially Electric Smelteries
#### Fixes
* Fixed Programmable Androids rotating in the wrong direction
@ -70,6 +71,7 @@
* Fixed ChestTerminal timings showing up as cargo nodes
* Fixed timings reports never arriving sometimes
* Fixed #2138
* Fixed #1951 (again)
## Release Candidate 15 (01 Aug 2020)

View File

@ -14,6 +14,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler;
@ -28,6 +29,12 @@ import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
/**
* The {@link ElectricSmeltery} is an electric version of the standard {@link Smeltery}.
*
* @author TheBusyBiscuit
*
*/
public abstract class ElectricSmeltery extends AContainer {
private static final int[] border = { 4, 5, 6, 7, 8, 13, 31, 40, 41, 42, 43, 44 };
@ -65,8 +72,8 @@ public abstract class ElectricSmeltery extends AContainer {
for (int slot : getInputSlots()) {
ItemStack stack = menu.getItemInSlot(slot);
if (stack != null && SlimefunUtils.isItemSimilar(stack, item, true)) {
if (stack.getAmount() < stack.getMaxStackSize()) {
if (stack != null && SlimefunUtils.isItemSimilar(stack, item, true, false)) {
if (stack.getAmount() >= stack.getMaxStackSize()) {
fullSlots++;
}
@ -117,18 +124,18 @@ public abstract class ElectricSmeltery extends AContainer {
@Override
protected void constructMenu(BlockMenuPreset preset) {
for (int i : border) {
preset.addItem(i, new CustomItem(new ItemStack(Material.GRAY_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
preset.addItem(i, new CustomItem(Material.GRAY_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : inputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.CYAN_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
for (int i : outputBorder) {
preset.addItem(i, new CustomItem(new ItemStack(Material.ORANGE_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
preset.addItem(i, new CustomItem(Material.ORANGE_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
}
preset.addItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "), ChestMenuUtils.getEmptyClickHandler());
preset.addItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler());
for (int i : getOutputSlots()) {
preset.addMenuClickHandler(i, new AdvancedMenuClickHandler() {

View File

@ -18,6 +18,7 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction;
@ -257,39 +258,54 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
}
}
else {
MachineRecipe r = null;
Map<Integer, Integer> found = new HashMap<>();
MachineRecipe next = nextRecipe(inv);
for (MachineRecipe recipe : recipes) {
for (ItemStack input : recipe.getInput()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), input, true)) {
found.put(slot, input.getAmount());
break;
}
if (next != null) {
processing.put(b, next);
progress.put(b, next.getTicks());
}
}
}
private MachineRecipe nextRecipe(BlockMenu inv) {
Map<Integer, ItemStack> inventory = new HashMap<>();
for (int slot : getInputSlots()) {
ItemStack item = inv.getItemInSlot(slot);
if (item != null) {
inventory.put(slot, new ItemStackWrapper(item));
}
}
Map<Integer, Integer> found = new HashMap<>();
for (MachineRecipe recipe : recipes) {
for (ItemStack input : recipe.getInput()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inventory.get(slot), input, true)) {
found.put(slot, input.getAmount());
break;
}
}
if (found.size() == recipe.getInput().length) {
r = recipe;
break;
}
else {
found.clear();
}
}
if (r != null) {
if (!InvUtils.fitAll(inv.toInventory(), r.getOutput(), getOutputSlots())) {
return;
if (found.size() == recipe.getInput().length) {
if (!InvUtils.fitAll(inv.toInventory(), recipe.getOutput(), getOutputSlots())) {
return null;
}
for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
inv.consumeItem(entry.getKey(), entry.getValue());
}
processing.put(b, r);
progress.put(b, r.getTicks());
return recipe;
}
else {
found.clear();
}
}
return null;
}
}