1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Updated all electric machines

This commit is contained in:
TheBusyBiscuit 2020-08-04 15:43:00 +02:00
parent bc387ee47a
commit b6ba6ce754
26 changed files with 110 additions and 226 deletions

View File

@ -80,10 +80,7 @@ public class SlimefunRegistry {
private final Map<String, BlockInfoConfig> chunks = new HashMap<>();
private final Map<SlimefunGuideLayout, SlimefunGuideImplementation> layouts = new EnumMap<>(SlimefunGuideLayout.class);
private final Map<EntityType, Set<ItemStack>> mobDrops = new EnumMap<>(EntityType.class);
@Deprecated
private final Map<String, Integer> capacities = new HashMap<>();
private final Map<String, BlockMenuPreset> blockMenuPresets = new HashMap<>();
private final Map<String, UniversalBlockMenu> universalInventories = new HashMap<>();
private final Map<Class<? extends ItemHandler>, Set<ItemHandler>> globalItemHandlers = new HashMap<>();
@ -237,11 +234,6 @@ public class SlimefunRegistry {
return slimefunIds;
}
@Deprecated
public Map<String, Integer> getEnergyCapacities() {
return capacities;
}
public Map<String, BlockMenuPreset> getMenuPresets() {
return blockMenuPresets;
}

View File

@ -2,19 +2,30 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets
import java.util.Optional;
import org.bukkit.block.Block;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.math.DoubleHandler;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
/**
* The {@link Multimeter} is used to measure charge and capacity of any {@link EnergyNetComponent}.
*
* @author TheBusyBiscuit
*
* @see EnergyNet
* @see EnergyNetComponent
*
*/
public class Multimeter extends SimpleSlimefunItem<ItemUseHandler> {
public Multimeter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
@ -24,21 +35,26 @@ public class Multimeter extends SimpleSlimefunItem<ItemUseHandler> {
@Override
public ItemUseHandler getItemHandler() {
return e -> {
Optional<Block> block = e.getClickedBlock();
Optional<SlimefunItem> block = e.getSlimefunBlock();
if (block.isPresent()) {
Block b = block.get();
if (e.getClickedBlock().isPresent() && block.isPresent()) {
SlimefunItem item = block.get();
if (ChargableBlock.isChargable(b)) {
e.cancel();
if (item instanceof EnergyNetComponent) {
EnergyNetComponent component = (EnergyNetComponent) item;
String stored = DoubleHandler.getFancyDouble(ChargableBlock.getCharge(b)) + " J";
String capacity = DoubleHandler.getFancyDouble(ChargableBlock.getMaxCharge(b)) + " J";
if (component.isChargeable()) {
e.cancel();
Player p = e.getPlayer();
p.sendMessage("");
SlimefunPlugin.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity));
p.sendMessage("");
Location l = e.getClickedBlock().get().getLocation();
String stored = DoubleHandler.getFancyDouble(component.getCharge(l)) + " J";
String capacity = DoubleHandler.getFancyDouble(component.getCapacity()) + " J";
Player p = e.getPlayer();
p.sendMessage("");
SlimefunPlugin.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity));
p.sendMessage("");
}
}
}
};

View File

@ -30,7 +30,6 @@ import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
@ -195,7 +194,7 @@ public abstract class AbstractEntityAssembler<T extends Entity> extends SimpleSl
return;
}
if (lifetime % 60 == 0 && ChargableBlock.getCharge(b) >= getEnergyConsumption()) {
if (lifetime % 60 == 0 && getCharge(b.getLocation()) >= getEnergyConsumption()) {
BlockMenu menu = BlockStorage.getInventory(b);
boolean hasBody = findResource(menu, getBody(), bodySlots);
@ -204,7 +203,7 @@ public abstract class AbstractEntityAssembler<T extends Entity> extends SimpleSl
if (hasBody && hasHead) {
consumeResources(menu);
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
double offset = Double.parseDouble(BlockStorage.getLocationInfo(b.getLocation(), KEY_OFFSET));
Slimefun.runSync(() -> {

View File

@ -23,7 +23,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -47,7 +46,7 @@ public class AnimalGrowthAccelerator extends SlimefunItem implements InventoryBl
if (inv != null) {
inv.dropItems(b.getLocation(), getInputSlots());
}
return true;
});
}
@ -100,11 +99,11 @@ public class AnimalGrowthAccelerator extends SlimefunItem implements InventoryBl
for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 3.0, 3.0, 3.0, n -> n instanceof Ageable && n.isValid() && !((Ageable) n).isAdult())) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) {
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) {
return;
}
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
inv.consumeItem(slot);
((Ageable) n).setAge(((Ageable) n).getAge() + 2000);

View File

@ -16,7 +16,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public abstract class AutoAnvil extends AContainer {
@ -57,15 +56,15 @@ public abstract class AutoAnvil extends AContainer {
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
menu.pushItem(processing.get(b).getOutput()[0].clone(), getOutputSlots());
progress.remove(b);

View File

@ -22,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -90,6 +89,7 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN
public boolean isSynchronized() {
return true;
}
});
}
@ -99,11 +99,11 @@ public class AutoBreeder extends SlimefunItem implements InventoryBlock, EnergyN
for (Entity n : b.getWorld().getNearbyEntities(b.getLocation(), 4.0, 2.0, 4.0, this::canBreed)) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFood, false)) {
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) {
return;
}
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
inv.consumeItem(slot);
((Animals) n).setLoveModeTicks(600);

View File

@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
/**
@ -68,11 +67,11 @@ public abstract class AutoBrewer extends AContainer {
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {

View File

@ -28,7 +28,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
/**
@ -78,11 +77,11 @@ public class AutoDisenchanter extends AContainer {
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {

View File

@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
/**
@ -104,15 +103,15 @@ public class AutoDrier extends AContainer implements RecipeDisplayItem {
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
menu.pushItem(processing.get(b).getOutput()[0], getOutputSlots());
progress.remove(b);

View File

@ -24,7 +24,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public class AutoEnchanter extends AContainer {
@ -67,15 +66,15 @@ public class AutoEnchanter extends AContainer {
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
for (ItemStack item : processing.get(b).getOutput()) {
menu.pushItem(item, getOutputSlots());
@ -137,6 +136,7 @@ public class AutoEnchanter extends AContainer {
emeraldEnchantments.add(enchantment);
}
}
specialAmount += EmeraldEnchants.getInstance().getRegistry().getEnchantments(target).size();
}

View File

@ -31,7 +31,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
@ -56,7 +55,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
@Override
public void newInstance(BlockMenu menu, Block b) {
if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "enabled") == null || BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals(String.valueOf(false))) {
menu.replaceExistingItem(6, new CustomItem(new ItemStack(Material.GUNPOWDER), "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine"));
menu.replaceExistingItem(6, new CustomItem(Material.GUNPOWDER, "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine"));
menu.addMenuClickHandler(6, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "enabled", String.valueOf(true));
newInstance(menu, b);
@ -64,7 +63,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
});
}
else {
menu.replaceExistingItem(6, new CustomItem(new ItemStack(Material.REDSTONE), "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine"));
menu.replaceExistingItem(6, new CustomItem(Material.REDSTONE, "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine"));
menu.addMenuClickHandler(6, (p, slot, item, action) -> {
BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
newInstance(menu, b);
@ -72,7 +71,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
});
}
menu.replaceExistingItem(7, new CustomItem(new ItemStack(Material.CRAFTING_TABLE), "&7Craft Last", "", "&e> Click to craft the last shaped recipe", "&cOnly works with the last one"));
menu.replaceExistingItem(7, new CustomItem(Material.CRAFTING_TABLE, "&7Craft Last", "", "&e> Click to craft the last shaped recipe", "&cOnly works with the last one"));
menu.addMenuClickHandler(7, (p, slot, item, action) -> {
tick(b, true);
return false;
@ -215,7 +214,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
return;
}
if (ChargableBlock.getCharge(block) < getEnergyConsumption()) {
if (getCharge(block.getLocation()) < getEnergyConsumption()) {
return;
}
@ -259,7 +258,7 @@ public abstract class AutomatedCraftingChamber extends SlimefunItem implements I
ItemStack output = SlimefunPlugin.getRegistry().getAutomatedCraftingChamberRecipes().get(input);
if (output != null && menu.fits(output, getOutputSlots())) {
menu.pushItem(output.clone(), getOutputSlots());
ChargableBlock.addCharge(block, -getEnergyConsumption());
removeCharge(block.getLocation(), getEnergyConsumption());
for (int j = 0; j < 9; j++) {
if (menu.getItemInSlot(getInputSlots()[j]) != null) {

View File

@ -11,7 +11,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public class ChargingBench extends AContainer {
@ -42,7 +41,7 @@ public class ChargingBench extends AContainer {
@Override
protected void tick(Block b) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
@ -64,7 +63,7 @@ public class ChargingBench extends AContainer {
float charge = getEnergyConsumption() / 2F;
if (((Rechargeable) sfItem).addItemCharge(item, charge)) {
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
}
else if (inv.fits(item, getOutputSlots())) {
inv.pushItem(item, getOutputSlots());

View File

@ -26,7 +26,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -116,7 +115,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem implements Inve
protected void tick(Block b) {
BlockMenu inv = BlockStorage.getInventory(b);
if (ChargableBlock.getCharge(b) >= getEnergyConsumption()) {
if (getCharge(b.getLocation()) >= getEnergyConsumption()) {
for (int x = -getRadius(); x <= getRadius(); x++) {
for (int z = -getRadius(); z <= getRadius(); z++) {
Block block = b.getRelative(x, 0, z);
@ -135,7 +134,7 @@ public abstract class CropGrowthAccelerator extends SlimefunItem implements Inve
if (ageable.getAge() < ageable.getMaximumAge()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
ChargableBlock.addCharge(machine, -getEnergyConsumption());
removeCharge(machine.getLocation(), getEnergyConsumption());
inv.consumeItem(slot);
ageable.setAge(ageable.getAge() + 1);

View File

@ -16,7 +16,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public abstract class ElectricDustWasher extends AContainer {
@ -59,21 +58,21 @@ public abstract class ElectricDustWasher extends AContainer {
if (timeleft > 0 && getSpeed() < 10) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
menu.pushItem(processing.get(b).getOutput()[0].clone(), getOutputSlots());
progress.remove(b);
@ -90,7 +89,7 @@ public abstract class ElectricDustWasher extends AContainer {
}
private boolean process(Block b, BlockMenu menu, int slot) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true)) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.SIFTED_ORE, true, false)) {
if (!legacyMode && !hasFreeSlot(menu)) {
return true;
}
@ -106,7 +105,7 @@ public abstract class ElectricDustWasher extends AContainer {
return true;
}
else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.PULVERIZED_ORE, true)) {
else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), SlimefunItems.PULVERIZED_ORE, true, false)) {
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER });
if (menu.fits(r.getOutput()[0], getOutputSlots())) {

View File

@ -19,7 +19,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
public abstract class ElectricGoldPan extends AContainer implements RecipeDisplayItem {
@ -63,21 +62,21 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla
if (timeleft > 0 && getSpeed() < 10) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
ItemStack output = processing.get(b).getOutput()[0];
@ -109,7 +108,7 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla
}
private boolean process(Block b, BlockMenu menu, int slot) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true)) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.GRAVEL), true, false)) {
ItemStack output = goldPan.getRandomOutput();
MachineRecipe r = new MachineRecipe(3 / getSpeed(), new ItemStack[0], new ItemStack[] { output });
@ -122,7 +121,7 @@ public abstract class ElectricGoldPan extends AContainer implements RecipeDispla
return true;
}
else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true)) {
else if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.SOUL_SAND), true, false)) {
ItemStack output = netherGoldPan.getRandomOutput();
MachineRecipe r = new MachineRecipe(4 / getSpeed(), new ItemStack[0], new ItemStack[] { output });

View File

@ -27,7 +27,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -59,14 +58,14 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
private 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());
}
for (int i : getOutputSlots()) {
@ -109,16 +108,16 @@ public class FluidPump extends SimpleSlimefunItem<BlockTicker> implements Invent
Block fluid = b.getRelative(BlockFace.DOWN);
Optional<ItemStack> bucket = getFilledBucket(fluid);
if (bucket.isPresent() && ChargableBlock.getCharge(b) >= ENERGY_CONSUMPTION) {
if (bucket.isPresent() && getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) {
BlockMenu menu = BlockStorage.getInventory(b);
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.BUCKET), true)) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), new ItemStack(Material.BUCKET), true, false)) {
if (!menu.fits(bucket.get(), getOutputSlots())) {
return;
}
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
menu.consumeItem(slot);
menu.pushItem(bucket.get().clone(), getOutputSlots());
consumeFluid(fluid);

View File

@ -3,9 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -16,19 +14,11 @@ import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
@ -57,7 +47,9 @@ public abstract class HeatedPressureChamber extends AContainer {
@Override
public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) {
if (flow == ItemTransportFlow.WITHDRAW) return getOutputSlots();
if (flow == ItemTransportFlow.WITHDRAW) {
return getOutputSlots();
}
List<Integer> slots = new ArrayList<>();
@ -122,88 +114,6 @@ public abstract class HeatedPressureChamber extends AContainer {
return new int[] { 24, 25 };
}
@Override
public void preRegister() {
addItemHandler(new BlockTicker() {
@Override
public void tick(Block b, SlimefunItem sf, Config data) {
HeatedPressureChamber.this.tick(b);
}
@Override
public boolean isSynchronized() {
return false;
}
});
}
@Override
protected void tick(Block b) {
BlockMenu menu = BlockStorage.getInventory(b);
if (isProcessing(b)) {
int timeleft = progress.get(b);
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(menu, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
menu.replaceExistingItem(22, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
menu.pushItem(processing.get(b).getOutput()[0], getOutputSlots());
progress.remove(b);
processing.remove(b);
}
}
else {
Map<Integer, Integer> found = new HashMap<>();
MachineRecipe recipe = findRecipe(menu, found);
if (recipe != null) {
if (!menu.fits(recipe.getOutput()[0], getOutputSlots())) {
return;
}
for (Map.Entry<Integer, Integer> entry : found.entrySet()) {
menu.consumeItem(entry.getKey(), entry.getValue());
}
processing.put(b, recipe);
progress.put(b, recipe.getTicks());
}
}
}
private MachineRecipe findRecipe(BlockMenu menu, Map<Integer, Integer> found) {
for (MachineRecipe recipe : recipes) {
for (ItemStack input : recipe.getInput()) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(menu.getItemInSlot(slot), input, true)) {
found.put(slot, input.getAmount());
break;
}
}
}
if (found.size() == recipe.getInput().length) {
return recipe;
}
else {
found.clear();
}
}
return null;
}
@Override
public String getMachineIdentifier() {
return "HEATED_PRESSURE_CHAMBER";

View File

@ -22,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -107,7 +106,7 @@ public class TreeGrowthAccelerator extends SlimefunItem implements InventoryBloc
protected void tick(Block b) {
BlockMenu inv = BlockStorage.getInventory(b);
if (ChargableBlock.getCharge(b) >= ENERGY_CONSUMPTION) {
if (getCharge(b.getLocation()) >= ENERGY_CONSUMPTION) {
for (int x = -RADIUS; x <= RADIUS; x++) {
for (int z = -RADIUS; z <= RADIUS; z++) {
Block block = b.getRelative(x, 0, z);
@ -126,8 +125,8 @@ public class TreeGrowthAccelerator extends SlimefunItem implements InventoryBloc
private boolean grow(Block machine, Block block, BlockMenu inv, Sapling sapling) {
for (int slot : getInputSlots()) {
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
ChargableBlock.addCharge(machine, -ENERGY_CONSUMPTION);
if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false, false)) {
removeCharge(machine.getLocation(), ENERGY_CONSUMPTION);
sapling.setStage(sapling.getStage() + 1);
block.setBlockData(sapling);

View File

@ -22,7 +22,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -109,13 +108,13 @@ public class XPCollector extends SlimefunItem implements InventoryBlock, EnergyN
while (iterator.hasNext() && experiencePoints == 0) {
Entity entity = iterator.next();
if (ChargableBlock.getCharge(b) < ENERGY_CONSUMPTION) {
if (getCharge(b.getLocation()) < ENERGY_CONSUMPTION) {
return;
}
experiencePoints = getStoredExperience(b) + ((ExperienceOrb) entity).getExperience();
ChargableBlock.addCharge(b, -ENERGY_CONSUMPTION);
removeCharge(b.getLocation(), ENERGY_CONSUMPTION);
entity.remove();
int withdrawn = 0;

View File

@ -28,7 +28,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecip
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -149,16 +148,15 @@ public abstract class GEOMiner extends AContainer implements InventoryBlock, Rec
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(inv, 4, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {
inv.replaceExistingItem(4, new CustomItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE), " "));
inv.replaceExistingItem(4, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " "));
inv.pushItem(processing.get(b).getOutput()[0], getOutputSlots());
progress.remove(b);

View File

@ -24,7 +24,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
@ -101,11 +100,11 @@ public abstract class OilPump extends AContainer implements RecipeDisplayItem {
if (timeleft > 0) {
ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {

View File

@ -18,7 +18,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
public abstract class GPSTransmitter extends SimpleSlimefunItem<BlockTicker> implements EnergyNetComponent {
@ -53,12 +52,12 @@ public abstract class GPSTransmitter extends SimpleSlimefunItem<BlockTicker> imp
@Override
public void tick(Block b, SlimefunItem item, Config data) {
int charge = ChargableBlock.getCharge(b);
int charge = getCharge(b.getLocation());
UUID owner = UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner"));
if (charge >= getEnergyConsumption()) {
SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), owner, true);
ChargableBlock.setCharge(b.getLocation(), charge - getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
}
else {
SlimefunPlugin.getGPSNetwork().updateTransmitter(b.getLocation(), owner, false);

View File

@ -27,7 +27,6 @@ import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemExcepti
import io.github.thebusybiscuit.slimefun4.api.exceptions.WrongItemStackException;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.api.items.ItemState;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.attributes.Placeable;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
@ -370,14 +369,6 @@ public class SlimefunItem implements Placeable {
SlimefunPlugin.getRegistry().getRadioactiveItems().add(this);
}
if (this instanceof EnergyNetComponent && !SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(getID())) {
int capacity = ((EnergyNetComponent) this).getCapacity();
if (capacity > 0) {
SlimefunPlugin.getRegistry().getEnergyCapacities().put(id, capacity);
}
}
if (SlimefunPlugin.getItemCfg().getBoolean(id + ".enabled")) {
if (!category.isRegistered()) {

View File

@ -28,7 +28,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
@ -234,11 +233,11 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(b).getTicks(), getProgressBar());
if (isChargeable()) {
if (ChargableBlock.getCharge(b) < getEnergyConsumption()) {
if (getCharge(b.getLocation()) < getEnergyConsumption()) {
return;
}
ChargableBlock.addCharge(b, -getEnergyConsumption());
removeCharge(b.getLocation(), getEnergyConsumption());
progress.put(b, timeleft - 1);
}
else {

View File

@ -25,7 +25,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.api.energy.ChargableBlock;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
@ -141,7 +140,7 @@ public abstract class AGenerator extends AbstractEnergyProvider {
ChestMenuUtils.updateProgressbar(inv, 22, timeleft, processing.get(l).getTicks(), getProgressBar());
if (isChargeable()) {
int charge = ChargableBlock.getCharge(l);
int charge = getCharge(l);
if (getCapacity() - charge >= getEnergyProduction()) {
progress.put(l, timeleft - 1);

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.block.Block;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.Capacitor;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -27,13 +26,8 @@ public final class ChargableBlock {
}
public static boolean isChargable(Location l) {
String id = BlockStorage.checkID(l);
if (id == null) {
return false;
}
return SlimefunPlugin.getRegistry().getEnergyCapacities().containsKey(id);
SlimefunItem item = BlockStorage.check(l);
return item instanceof EnergyNetComponent && ((EnergyNetComponent) item).isChargeable();
}
public static int getCharge(Block b) {
@ -84,14 +78,14 @@ public final class ChargableBlock {
}
public static int addCharge(Location l, int addedCharge) {
String id = BlockStorage.checkID(l);
SlimefunItem item = BlockStorage.check(l);
if (id == null) {
if (item == null) {
BlockStorage.clearBlockInfo(l);
return 0;
}
int capacity = SlimefunPlugin.getRegistry().getEnergyCapacities().getOrDefault(id, 0);
int capacity = ((EnergyNetComponent) item).getCapacity();
int charge = getCharge(l);
int availableSpace = capacity - charge;
@ -109,7 +103,7 @@ public final class ChargableBlock {
setCharge(l, charge);
if (SlimefunItem.getByID(id) instanceof Capacitor) {
if (item instanceof Capacitor) {
SlimefunUtils.updateCapacitorTexture(l, charge, capacity);
}
}
@ -117,7 +111,7 @@ public final class ChargableBlock {
charge += addedCharge;
setCharge(l, charge);
if (SlimefunItem.getByID(id) instanceof Capacitor) {
if (item instanceof Capacitor) {
SlimefunUtils.updateCapacitorTexture(l, charge, capacity);
}
}
@ -130,14 +124,15 @@ public final class ChargableBlock {
}
public static int getMaxCharge(Location l) {
String id = BlockStorage.checkID(l);
SlimefunItem item = BlockStorage.check(l);
if (id == null) {
if (item == null) {
BlockStorage.clearBlockInfo(l);
return 0;
}
return SlimefunPlugin.getRegistry().getEnergyCapacities().getOrDefault(id, 0);
return item instanceof EnergyNetComponent ? ((EnergyNetComponent) item).getCapacity() : 0;
}
}