1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2020-07-19 10:53:09 +02:00
parent 14f88495c4
commit 14e062810b
3 changed files with 40 additions and 24 deletions

View File

@ -28,6 +28,9 @@
* Big performance improvements to Cargo networks when using ChestTerminal * Big performance improvements to Cargo networks when using ChestTerminal
* Slight changes to /sf timings * Slight changes to /sf timings
#### Fixes
* Fixed #2075
## Release Candidate 14 (12 Jul 2020) ## Release Candidate 14 (12 Jul 2020)
#### Additions #### Additions

View File

@ -314,7 +314,7 @@
<dependency> <dependency>
<groupId>com.github.TheBusyBiscuit</groupId> <groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>CS-CoreLib2</artifactId> <artifactId>CS-CoreLib2</artifactId>
<version>0.23.2</version> <version>0.24</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -12,6 +12,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -34,6 +35,7 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu;
@ -257,18 +259,13 @@ abstract class ChestTerminalNetwork extends Network {
} }
private void collectTerminalRequests() { private void collectTerminalRequests() {
SlimefunItem item = SlimefunItem.getByID("CHEST_TERMINAL");
for (Location terminal : terminals) { for (Location terminal : terminals) {
long timestamp = SlimefunPlugin.getProfiler().newEntry();
BlockMenu menu = BlockStorage.getInventory(terminal); BlockMenu menu = BlockStorage.getInventory(terminal);
ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT); ItemStack sendingItem = menu.getItemInSlot(TERMINAL_OUT_SLOT);
if (sendingItem != null) { if (sendingItem != null) {
itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT)); itemRequests.add(new ItemRequest(terminal, TERMINAL_OUT_SLOT, sendingItem, ItemTransportFlow.INSERT));
} }
SlimefunPlugin.getProfiler().closeEntry(terminal, item, timestamp);
} }
} }
@ -286,6 +283,10 @@ abstract class ChestTerminalNetwork extends Network {
return; return;
} }
// Timings will be slightly inaccurate here but most often people are gonna
// use no more than one terminal anyway, so this might be fine
long timestamp = SlimefunPlugin.getProfiler().newEntry();
SlimefunItem item = SlimefunItem.getByID("CHEST_TERMINAL");
List<ItemStackAndInteger> items = findAvailableItems(providers); List<ItemStackAndInteger> items = findAvailableItems(providers);
for (Location l : terminals) { for (Location l : terminals) {
@ -302,6 +303,8 @@ abstract class ChestTerminalNetwork extends Network {
int index = i + (TERMINAL_SLOTS.length * (page - 1)); int index = i + (TERMINAL_SLOTS.length * (page - 1));
updateTerminal(l, terminal, slot, index, items); updateTerminal(l, terminal, slot, index, items);
} }
SlimefunPlugin.getProfiler().closeEntry(l, item, timestamp);
} }
} }
@ -335,7 +338,8 @@ abstract class ChestTerminalNetwork extends Network {
terminal.replaceExistingItem(slot, stack); terminal.replaceExistingItem(slot, stack);
terminal.addMenuClickHandler(slot, (p, sl, is, action) -> { terminal.addMenuClickHandler(slot, (p, sl, is, action) -> {
int amount = item.getInt() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize() : item.getInt(); int amount = item.getInt() > item.getItem().getMaxStackSize() ? item.getItem().getMaxStackSize() : item.getInt();
itemRequests.add(new ItemRequest(l, 44, new CustomItem(item.getItem(), action.isRightClicked() ? amount : 1), ItemTransportFlow.WITHDRAW)); ItemStack requestedItem = new CustomItem(item.getItem(), action.isRightClicked() ? amount : 1);
itemRequests.add(new ItemRequest(l, 44, requestedItem, ItemTransportFlow.WITHDRAW));
return false; return false;
}); });
@ -364,10 +368,14 @@ abstract class ChestTerminalNetwork extends Network {
} }
else if (BlockStorage.hasInventory(target)) { else if (BlockStorage.hasInventory(target)) {
BlockMenu blockMenu = BlockStorage.getInventory(target); BlockMenu blockMenu = BlockStorage.getInventory(target);
Config cfg = BlockStorage.getLocationInfo(target.getLocation());
if (cfg.getString("id").startsWith("BARREL_") && cfg.getString("storedItems") != null) { if (blockMenu.getPreset().getID().startsWith("BARREL_")) {
gatherItemsFromBarrel(l, cfg, blockMenu, items); Config cfg = BlockStorage.getLocationInfo(target.getLocation());
String data = cfg.getString("storedItems");
if (data != null) {
gatherItemsFromBarrel(l, data, blockMenu, items);
}
} }
else { else {
handleWithdraw(blockMenu, items, l); handleWithdraw(blockMenu, items, l);
@ -391,27 +399,32 @@ abstract class ChestTerminalNetwork extends Network {
return items; return items;
} }
private void gatherItemsFromBarrel(Location l, Config cfg, BlockMenu blockMenu, List<ItemStackAndInteger> items) { private void gatherItemsFromBarrel(Location l, String data, BlockMenu blockMenu, List<ItemStackAndInteger> items) {
int stored = Integer.parseInt(cfg.getString("storedItems")); try {
int stored = Integer.parseInt(data);
for (int slot : blockMenu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) blockMenu, ItemTransportFlow.WITHDRAW, null)) { for (int slot : blockMenu.getPreset().getSlotsAccessedByItemTransport((DirtyChestMenu) blockMenu, ItemTransportFlow.WITHDRAW, null)) {
ItemStack is = blockMenu.getItemInSlot(slot); ItemStack is = blockMenu.getItemInSlot(slot);
if (is != null && CargoUtils.matchesFilter(l.getBlock(), is)) { if (is != null && CargoUtils.matchesFilter(l.getBlock(), is)) {
boolean add = true; boolean add = true;
for (ItemStackAndInteger item : items) { for (ItemStackAndInteger item : items) {
if (SlimefunUtils.isItemSimilar(is, item.getItemStackWrapper(), true, false)) { if (SlimefunUtils.isItemSimilar(is, item.getItemStackWrapper(), true, false)) {
add = false; add = false;
item.add(is.getAmount() + stored); item.add(is.getAmount() + stored);
}
}
if (add) {
items.add(new ItemStackAndInteger(is, is.getAmount() + stored));
} }
} }
if (add) {
items.add(new ItemStackAndInteger(is, is.getAmount() + stored));
}
} }
} }
catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, "An Exception occured while trying to read data from a Barrel", x);
}
} }
private void handleWithdraw(DirtyChestMenu menu, List<ItemStackAndInteger> items, Location l) { private void handleWithdraw(DirtyChestMenu menu, List<ItemStackAndInteger> items, Location l) {