This commit is contained in:
SeanOMik 2022-01-31 23:20:10 -05:00
parent 340c8caaea
commit 834935ec9d
5 changed files with 45 additions and 4 deletions

View File

@ -4,7 +4,7 @@
<groupId>net.seanomik</groupId> <groupId>net.seanomik</groupId>
<artifactId>energeticstorage</artifactId> <artifactId>energeticstorage</artifactId>
<name>EnergeticStorage</name> <name>EnergeticStorage</name>
<version>0.7.4-SNAPSHOT</version> <version>0.7.5-SNAPSHOT</version>
<build> <build>
<defaultGoal>clean package</defaultGoal> <defaultGoal>clean package</defaultGoal>
<resources> <resources>

View File

@ -6,7 +6,7 @@
<groupId>net.seanomik</groupId> <groupId>net.seanomik</groupId>
<artifactId>energeticstorage</artifactId> <artifactId>energeticstorage</artifactId>
<version>0.7.4-SNAPSHOT</version> <version>0.7.5-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>EnergeticStorage</name> <name>EnergeticStorage</name>

View File

@ -452,15 +452,40 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
} }
break; break;
case OUT_HALF:
case SHIFT_OUT: case SHIFT_OUT:
if (Utils.isItemValid(clickedItem)) {
ItemStack toRemoveStack = clickedItem.clone();
ItemStack addingItem = clickedItem.clone();
addingItem = Utils.removeAmountFromLore(addingItem);
HashMap<Integer, ItemStack> leftOverItems = player.getInventory().addItem(addingItem);
ItemStack leftOver = leftOverItems.get(0);
if (leftOver != null) {
toRemoveStack.setAmount(toRemoveStack.getAmount() - leftOver.getAmount());
}
openSystem.removeItem(toRemoveStack);
Bukkit.getScheduler().runTaskLater(EnergeticStorage.getPlugin(), () -> {
initializeItems(player, openSystem);
}, (long) 0.1);
/*for (Map.Entry<Integer, ItemStack> item : leftOverItems.entrySet()) {
System.out.println(item.getKey() + ", " + item.getValue());
}*/
}
break;
case OUT_HALF:
case OUT: case OUT:
if (Utils.isItemValid(clickedItem)) { if (Utils.isItemValid(clickedItem)) {
ItemStack takingItem = clickedItem.clone(); ItemStack takingItem = clickedItem.clone();
takingItem.setAmount((clickType == ClickType.OUT_HALF && clickedItem.getAmount() / 2 > 0) ? clickedItem.getAmount() / 2 : clickedItem.getMaxStackSize()); takingItem.setAmount((clickType == ClickType.OUT_HALF && clickedItem.getAmount() / 2 > 0) ? clickedItem.getAmount() / 2 : clickedItem.getMaxStackSize());
takingItem = openSystem.removeItem(takingItem); takingItem = openSystem.removeItem(takingItem);
// Remove the item from the search map if its in there // Remove the item from the search map if it's in there
if (openSearches.containsKey(player.getUniqueId())) { if (openSearches.containsKey(player.getUniqueId())) {
for (ItemStack item : openSearches.get(player.getUniqueId()).keySet()) { for (ItemStack item : openSearches.get(player.getUniqueId()).keySet()) {
ItemStack clone = item.clone(); ItemStack clone = item.clone();

View File

@ -191,6 +191,10 @@ public class ESDrive implements Cloneable, ConfigurationSerializable {
return item; return item;
} }
public int getItemAmount(ItemStack item) {
return (int) items.values().toArray()[Utils.indexOfSimilarItem(new ArrayList<>(items.keySet()), item)];
}
private String exceptionMessage(Exception e) { private String exceptionMessage(Exception e) {
return "An exception occurred in ESDrive (UUID:" + uuid + ", Exception: " + e.getMessage() + ")"; return "An exception occurred in ESDrive (UUID:" + uuid + ", Exception: " + e.getMessage() + ")";
} }

View File

@ -219,6 +219,18 @@ public class ESSystem implements Cloneable, ConfigurationSerializable {
return drive.removeItem(item); return drive.removeItem(item);
} }
public int getItemAmount(ItemStack item) {
ESDrive drive = null;
for (ESDrive esDrive : esDrives) {
for (Map.Entry<ItemStack, Integer> entry : esDrive.getItems().entrySet()) {
if (Utils.removeAmountFromLore(entry.getKey()).isSimilar(Utils.removeAmountFromLore(item))) {
return entry.getValue();
}
}
}
return 0;
}
// @TODO: Implement (has not been tested) // @TODO: Implement (has not been tested)
@NotNull @NotNull