Skip to content

Commit

Permalink
🎨 fix(Tesseract): Make tesseract act more consistently. Energy and It…
Browse files Browse the repository at this point in the history
…ems are both pulled instead of pull energy and push item
  • Loading branch information
ProfElements committed Sep 24, 2024
1 parent 40041c8 commit e9cc5bd
Showing 1 changed file with 26 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.profelements.dynatech.items.electric.transfer;

import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.ItemHandler;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
Expand All @@ -8,7 +9,6 @@
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.inventory.InvUtils;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;
import io.github.thebusybiscuit.slimefun4.libraries.paperlib.PaperLib;
Expand All @@ -22,6 +22,8 @@
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.profelements.dynatech.DynaTech;
import me.profelements.dynatech.registries.Items;
import me.profelements.dynatech.utils.EnergyUtils;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
Expand Down Expand Up @@ -144,28 +146,16 @@ private void sendItemsAndCharge(Block b, String wirelessLocation) {

if (BlockStorage.checkID(tesseractPair) != null
&& BlockStorage.checkID(tesseractPair).equals(Items.TESSERACT.stack().getItemId())) {
BlockMenu input = BlockStorage.getInventory(tesseractPair);
BlockMenu output = BlockStorage.getInventory(b);

if (input == null) {
return;
}
if (output == null) {
return;
}

updateKnowledgePane(output, getCharge(b.getLocation()));

for (int i : getInputSlots()) {
ItemStack itemStack = input.getItemInSlot(i);
BlockMenu toMenu = BlockStorage.getInventory(b.getLocation());

if (itemStack != null && itemStack.getType() != Material.AIR
&& InvUtils.fitAll(output.toInventory(), new ItemStack[] { itemStack }, getOutputSlots())) {
output.pushItem(itemStack, getOutputSlots());
itemStack.setAmount(0);
}
if (toMenu == null) {
return;
}

updateKnowledgePane(toMenu, getCharge(b.getLocation()));
EnergyUtils.moveInventoryFromTo(new BlockPosition(tesseractPair), new BlockPosition(b), getInputSlots(),
getOutputSlots());
}

}
Expand Down Expand Up @@ -193,27 +183,14 @@ public int getGeneratedOutput(Location l, Config data) {

if (BlockStorage.checkID(tesseractPair) != null
&& BlockStorage.checkID(tesseractPair).equals(Items.TESSERACT.stack().getItemId())) {
int bankCharge = getCharge(tesseractPair);

if (bankCharge > chargedNeeded && bankCharge != 0) {
if (chargedNeeded > getEnergyRate()) {
removeCharge(tesseractPair, getEnergyRate());
return getEnergyRate();
}
removeCharge(tesseractPair, chargedNeeded);
return chargedNeeded;
} else if (bankCharge > 0) {
if (chargedNeeded > getEnergyRate()) {
removeCharge(tesseractPair, getEnergyRate());
return getEnergyRate();
}
removeCharge(tesseractPair, bankCharge);
return bankCharge;
}

return EnergyUtils.moveEnergyFromTo(new BlockPosition(tesseractPair), new BlockPosition(l),
getEnergyRate(), getCapacity());
}

return 0;
}

return 0;
}

Expand All @@ -224,16 +201,17 @@ private void updateKnowledgePane(BlockMenu menu, int currentCharge) {

ItemStack knowledgePane = menu.getItemInSlot(4);
ItemMeta im = knowledgePane.getItemMeta();
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
List<Component> lore = im.hasLore() ? im.lore() : new ArrayList<>();

lore.clear();
lore.add(" ");
lore.add(ChatColor.WHITE + "Current Power: " + currentCharge);
lore.add(ChatColor.WHITE + "Current Status: " + ChatColor.RED + "CONNECTED");
knowledgePane.setType(Material.RED_STAINED_GLASS_PANE);
lore.add(Component.text(" "));
lore.add(Component.text(ChatColor.WHITE + "Current Power: " + currentCharge));
lore.add(Component.text(ChatColor.WHITE + "Current Status: " + ChatColor.RED + "CONNECTED"));

im.setLore(lore);
im.lore(lore);
knowledgePane.setItemMeta(im);

menu.replaceExistingItem(4, knowledgePane.withType(Material.RED_STAINED_GLASS_PANE));
}

// Boilerplate for machines.
Expand Down Expand Up @@ -278,17 +256,18 @@ public int getEnergyRate() {

public static void setItemLore(ItemStack item, Location l) {
ItemMeta im = item.getItemMeta();
List<String> lore = im.getLore();
List<Component> lore = im.lore();
for (int i = 0; i < lore.size(); i++) {
if (lore.get(i).contains("Location: ")) {
if (lore.get(i).contains(Component.text("Location: "))) {
lore.remove(i);
}
}

lore.add(ChatColor.WHITE + "Location: " + l.getWorld().getName() + " " + l.getBlockX() + " " + l.getBlockY()
+ " " + l.getBlockZ());
lore.add(Component.text(
ChatColor.WHITE + "Location: " + l.getWorld().getName() + " " + l.getBlockX() + " " + l.getBlockY()
+ " " + l.getBlockZ()));

im.setLore(lore);
im.lore(lore);
item.setItemMeta(im);

}
Expand Down

0 comments on commit e9cc5bd

Please sign in to comment.