mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
optimize Cargo Node's filter index saving.
This commit is contained in:
parent
ebd8974155
commit
ec6698602c
@ -61,15 +61,15 @@ final class CargoUtils {
|
|||||||
ItemStack[] contents = inv.getContents();
|
ItemStack[] contents = inv.getContents();
|
||||||
int minSlot = 0;
|
int minSlot = 0;
|
||||||
int maxSlot = contents.length;
|
int maxSlot = contents.length;
|
||||||
|
|
||||||
if (inv instanceof FurnaceInventory) {
|
if (inv instanceof FurnaceInventory) {
|
||||||
minSlot = 2;
|
minSlot = 2;
|
||||||
maxSlot = 3;
|
maxSlot = 3;
|
||||||
}
|
}
|
||||||
else if (inv instanceof BrewerInventory) {
|
else if (inv instanceof BrewerInventory) {
|
||||||
maxSlot = 3;
|
maxSlot = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int slot = minSlot; slot < maxSlot; slot++) {
|
for (int slot = minSlot; slot < maxSlot; slot++) {
|
||||||
ItemStack itemInSlot = contents[slot]; // Mapped into inventory
|
ItemStack itemInSlot = contents[slot]; // Mapped into inventory
|
||||||
|
|
||||||
@ -77,14 +77,14 @@ final class CargoUtils {
|
|||||||
if (itemInSlot.getAmount() > template.getAmount()) {
|
if (itemInSlot.getAmount() > template.getAmount()) {
|
||||||
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
|
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
|
itemInSlot.setAmount(itemInSlot.getAmount() - template.getAmount());
|
||||||
return itemInSlot;
|
return itemInSlot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,21 +184,21 @@ final class CargoUtils {
|
|||||||
if (stack.getType().isFuel()) {
|
if (stack.getType().isFuel()) {
|
||||||
minSlot = 1;
|
minSlot = 1;
|
||||||
maxSlot = 2;
|
maxSlot = 2;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
maxSlot = 1;
|
maxSlot = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (inv instanceof BrewerInventory) {
|
else if (inv instanceof BrewerInventory) {
|
||||||
//Check if it goes in the potion slot,
|
//Check if it goes in the potion slot,
|
||||||
if (stack.getType() == Material.POTION || stack.getType() == Material.LINGERING_POTION || stack.getType() == Material.SPLASH_POTION) {
|
if (stack.getType() == Material.POTION || stack.getType() == Material.LINGERING_POTION || stack.getType() == Material.SPLASH_POTION) {
|
||||||
maxSlot = 3;
|
maxSlot = 3;
|
||||||
//The blaze powder slot,
|
//The blaze powder slot,
|
||||||
}
|
}
|
||||||
else if (stack.getType() == Material.BLAZE_POWDER) {
|
else if (stack.getType() == Material.BLAZE_POWDER) {
|
||||||
minSlot = 4;
|
minSlot = 4;
|
||||||
maxSlot = 5;
|
maxSlot = 5;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Or the input
|
//Or the input
|
||||||
minSlot = 3;
|
minSlot = 3;
|
||||||
@ -212,7 +212,7 @@ final class CargoUtils {
|
|||||||
if (itemInSlot == null) {
|
if (itemInSlot == null) {
|
||||||
inv.setItem(slot, stack);
|
inv.setItem(slot, stack);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int maxStackSize = itemInSlot.getType().getMaxStackSize();
|
int maxStackSize = itemInSlot.getType().getMaxStackSize();
|
||||||
if (SlimefunUtils.isItemSimilar(itemInSlot, stack, true, false) && itemInSlot.getAmount() < maxStackSize) {
|
if (SlimefunUtils.isItemSimilar(itemInSlot, stack, true, false) && itemInSlot.getAmount() < maxStackSize) {
|
||||||
@ -231,7 +231,7 @@ final class CargoUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,37 +256,38 @@ final class CargoUtils {
|
|||||||
boolean lore = "true".equals(blockInfo.getString("filter-lore"));
|
boolean lore = "true".equals(blockInfo.getString("filter-lore"));
|
||||||
|
|
||||||
if ("whitelist".equals(blockInfo.getString("filter-type"))) {
|
if ("whitelist".equals(blockInfo.getString("filter-type"))) {
|
||||||
List<ItemStack> items = new ArrayList<>();
|
List<ItemStack> templateItems = new ArrayList<>();
|
||||||
|
|
||||||
for (int slot : SLOTS) {
|
for (int slot : SLOTS) {
|
||||||
ItemStack template = menu.getItemInSlot(slot);
|
ItemStack template = menu.getItemInSlot(slot);
|
||||||
if (template != null) {
|
if (template != null) {
|
||||||
items.add(template);
|
templateItems.add(template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items.isEmpty()) {
|
if (templateItems.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
index++;
|
index++;
|
||||||
if (index > (items.size() - 1)) index = 0;
|
if (index > (templateItems.size() - 1)) index = 0;
|
||||||
|
|
||||||
BlockStorage.addBlockInfo(block, "index", String.valueOf(index));
|
blockInfo.setValue("index", String.valueOf(index));
|
||||||
|
BlockStorage.setBlockInfo(block, blockInfo, false);
|
||||||
|
|
||||||
return SlimefunUtils.isItemSimilar(item, items.get(index), lore);
|
return SlimefunUtils.isItemSimilar(item, templateItems.get(index), lore);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (ItemStack stack : items) {
|
for (ItemStack stack : templateItems) {
|
||||||
if (SlimefunUtils.isItemSimilar(item, stack, lore)) {
|
if (SlimefunUtils.isItemSimilar(item, stack, lore)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (int slot : SLOTS) {
|
for (int slot : SLOTS) {
|
||||||
ItemStack itemInSlot = menu.getItemInSlot(slot);
|
ItemStack itemInSlot = menu.getItemInSlot(slot);
|
||||||
@ -294,7 +295,7 @@ final class CargoUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ public class BlockStorage {
|
|||||||
|
|
||||||
private static final String PATH_BLOCKS = "data-storage/Slimefun/stored-blocks/";
|
private static final String PATH_BLOCKS = "data-storage/Slimefun/stored-blocks/";
|
||||||
private static final String PATH_CHUNKS = "data-storage/Slimefun/stored-chunks/";
|
private static final String PATH_CHUNKS = "data-storage/Slimefun/stored-chunks/";
|
||||||
|
private static final String PATH_INVENTORIES = "data-storage/Slimefun/stored-inventories/";
|
||||||
|
|
||||||
private final World world;
|
private final World world;
|
||||||
private final Map<Location, Config> storage = new ConcurrentHashMap<>();
|
private final Map<Location, Config> storage = new ConcurrentHashMap<>();
|
||||||
@ -450,14 +451,13 @@ public class BlockStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!storage.hasInventory(l)) {
|
else if (!storage.hasInventory(l)) {
|
||||||
File file = new File("data-storage/Slimefun/stored-inventories/" + serializeLocation(l) + ".sfi");
|
File file = new File(PATH_INVENTORIES + serializeLocation(l) + ".sfi");
|
||||||
|
|
||||||
if (file.exists()) storage.inventories.put(l, new BlockMenu(BlockMenuPreset.getPreset(id), l, new io.github.thebusybiscuit.cscorelib2.config.Config(file)));
|
if (file.exists()) storage.inventories.put(l, new BlockMenu(BlockMenuPreset.getPreset(id), l, new io.github.thebusybiscuit.cscorelib2.config.Config(file)));
|
||||||
else storage.loadInventory(l, BlockMenuPreset.getPreset(id));
|
else storage.loadInventory(l, BlockMenuPreset.getPreset(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshCache(getStorage(l.getWorld()), l, id, serializeBlockInfo(cfg), updateTicker);
|
refreshCache(storage, l, id, serializeBlockInfo(cfg), updateTicker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBlockInfo(Block b, String json, boolean updateTicker) {
|
public static void setBlockInfo(Block b, String json, boolean updateTicker) {
|
||||||
|
Loading…
Reference in New Issue
Block a user