use of io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent in project Slimefun4 by Slimefun.
the class EnergyNet method onClassificationChange.
@Override
public void onClassificationChange(Location l, NetworkComponent from, NetworkComponent to) {
if (from == NetworkComponent.TERMINUS) {
generators.remove(l);
consumers.remove(l);
}
EnergyNetComponent component = getComponent(l);
if (component != null) {
switch(component.getEnergyComponentType()) {
case CAPACITOR:
capacitors.put(l, component);
break;
case CONSUMER:
consumers.put(l, component);
break;
case GENERATOR:
if (component instanceof EnergyNetProvider) {
generators.put(l, (EnergyNetProvider) component);
} else if (component instanceof SlimefunItem) {
((SlimefunItem) component).warn("This Item is marked as a GENERATOR but does not implement the interface EnergyNetProvider!");
}
break;
default:
break;
}
}
}
use of io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent in project Slimefun4 by Slimefun.
the class EnergyNet method storeRemainingEnergy.
private void storeRemainingEnergy(int remainingEnergy) {
for (Map.Entry<Location, EnergyNetComponent> entry : capacitors.entrySet()) {
Location loc = entry.getKey();
EnergyNetComponent component = entry.getValue();
if (remainingEnergy > 0) {
int capacity = component.getCapacity();
if (remainingEnergy > capacity) {
component.setCharge(loc, capacity);
remainingEnergy -= capacity;
} else {
component.setCharge(loc, remainingEnergy);
remainingEnergy = 0;
}
} else {
component.setCharge(loc, 0);
}
}
for (Map.Entry<Location, EnergyNetProvider> entry : generators.entrySet()) {
Location loc = entry.getKey();
EnergyNetProvider component = entry.getValue();
int capacity = component.getCapacity();
if (remainingEnergy > 0) {
if (remainingEnergy > capacity) {
component.setCharge(loc, capacity);
remainingEnergy -= capacity;
} else {
component.setCharge(loc, remainingEnergy);
remainingEnergy = 0;
}
} else {
component.setCharge(loc, 0);
}
}
}
use of io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent in project FluffyMachines by NCBPFluffyBear.
the class FluffyWrench method onWrenchInteract.
@EventHandler
public void onWrenchInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
ItemStack wrenchItem = e.getItem();
Long cooldown = cooldowns.get(p.getUniqueId());
if (isItem(wrenchItem) && cooldown != null) {
if ((System.currentTimeMillis() - cooldown) < WRENCH_DELAY) {
return;
}
}
cooldowns.put(p.getUniqueId(), System.currentTimeMillis());
Block block = e.getClickedBlock();
// Can't use offhand because a player can offhand the wrench to escape the event
if (isItem(e.getItem()) && !isItem(p.getInventory().getItemInOffHand()) && e.getAction().toString().endsWith("_BLOCK") && Slimefun.getProtectionManager().hasPermission(e.getPlayer(), block.getLocation(), Interaction.BREAK_BLOCK)) {
e.setCancelled(true);
SlimefunItem slimefunBlock = BlockStorage.check(block);
// Check if slimefunBlock is not a machine or a cargo component
if (slimefunBlock == null || (!(slimefunBlock instanceof EnergyNetComponent) && !slimefunBlock.getId().startsWith("CARGO_NODE") && !slimefunBlock.getId().equals(SlimefunItems.CARGO_MANAGER.getItemId()) && !(slimefunBlock instanceof TrashCan))) {
return;
}
if (!type.isElectric) {
damageItem(p, wrenchItem);
breakBlock(block, p);
} else if (removeItemCharge(wrenchItem, 1)) {
breakBlock(block, p);
}
}
}
use of io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent in project Slimefun4 by Slimefun.
the class EnergyNet method tick.
public void tick(@Nonnull Block b) {
AtomicLong timestamp = new AtomicLong(Slimefun.getProfiler().newEntry());
if (!regulator.equals(b.getLocation())) {
updateHologram(b, "&4Multiple Energy Regulators connected");
Slimefun.getProfiler().closeEntry(b.getLocation(), SlimefunItems.ENERGY_REGULATOR.getItem(), timestamp.get());
return;
}
super.tick();
if (connectorNodes.isEmpty() && terminusNodes.isEmpty()) {
updateHologram(b, "&4No Energy Network found");
} else {
int supply = tickAllGenerators(timestamp::getAndAdd) + tickAllCapacitors();
int remainingEnergy = supply;
int demand = 0;
for (Map.Entry<Location, EnergyNetComponent> entry : consumers.entrySet()) {
Location loc = entry.getKey();
EnergyNetComponent component = entry.getValue();
int capacity = component.getCapacity();
int charge = component.getCharge(loc);
if (charge < capacity) {
int availableSpace = capacity - charge;
demand += availableSpace;
if (remainingEnergy > 0) {
if (remainingEnergy > availableSpace) {
component.setCharge(loc, capacity);
remainingEnergy -= availableSpace;
} else {
component.setCharge(loc, charge + remainingEnergy);
remainingEnergy = 0;
}
}
}
}
storeRemainingEnergy(remainingEnergy);
updateHologram(b, supply, demand);
}
// We have subtracted the timings from Generators, so they do not show up twice.
Slimefun.getProfiler().closeEntry(b.getLocation(), SlimefunItems.ENERGY_REGULATOR.getItem(), timestamp.get());
}
use of io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent in project Slimefun4 by Slimefun.
the class DebugFishListener method sendInfo.
@ParametersAreNonnullByDefault
private void sendInfo(Player p, Block b) {
SlimefunItem item = BlockStorage.check(b);
p.sendMessage(" ");
p.sendMessage(ChatColors.color("&d" + b.getType() + " &e@ X: " + b.getX() + " Y: " + b.getY() + " Z: " + b.getZ()));
p.sendMessage(ChatColors.color("&dId: " + "&e" + item.getId()));
p.sendMessage(ChatColors.color("&dPlugin: " + "&e" + item.getAddon().getName()));
if (b.getState() instanceof Skull) {
p.sendMessage(ChatColors.color("&dSkull: " + greenCheckmark));
// Check if the skull is a wall skull, and if so use Directional instead of Rotatable.
if (b.getType() == Material.PLAYER_WALL_HEAD) {
p.sendMessage(ChatColors.color(" &dFacing: &e" + ((Directional) b.getBlockData()).getFacing().toString()));
} else {
p.sendMessage(ChatColors.color(" &dRotation: &e" + ((Rotatable) b.getBlockData()).getRotation().toString()));
}
}
if (BlockStorage.getStorage(b.getWorld()).hasInventory(b.getLocation())) {
p.sendMessage(ChatColors.color("&dInventory: " + greenCheckmark));
} else {
p.sendMessage(ChatColors.color("&dInventory: " + redCross));
}
if (item.isTicking()) {
p.sendMessage(ChatColors.color("&dTicking: " + greenCheckmark));
p.sendMessage(ChatColors.color(" &dAsync: &e" + (item.getBlockTicker().isSynchronized() ? redCross : greenCheckmark)));
} else if (item instanceof EnergyNetProvider) {
p.sendMessage(ChatColors.color("&dTicking: &3Indirect (Generator)"));
} else {
p.sendMessage(ChatColors.color("&dTicking: " + redCross));
}
if (Slimefun.getProfiler().hasTimings(b)) {
p.sendMessage(ChatColors.color(" &dTimings: &e" + Slimefun.getProfiler().getTime(b)));
p.sendMessage(ChatColors.color(" &dTotal Timings: &e" + Slimefun.getProfiler().getTime(item)));
p.sendMessage(ChatColors.color(" &dChunk Timings: &e" + Slimefun.getProfiler().getTime(b.getChunk())));
}
if (item instanceof EnergyNetComponent) {
EnergyNetComponent component = (EnergyNetComponent) item;
p.sendMessage(ChatColors.color("&dEnergyNet Component"));
p.sendMessage(ChatColors.color(" &dType: &e" + component.getEnergyComponentType()));
if (component.isChargeable()) {
p.sendMessage(ChatColors.color(" &dChargeable: " + greenCheckmark));
p.sendMessage(ChatColors.color(" &dEnergy: &e" + component.getCharge(b.getLocation()) + " / " + component.getCapacity()));
} else {
p.sendMessage(ChatColors.color("&dChargeable: " + redCross));
}
}
p.sendMessage(ChatColors.color("&6" + BlockStorage.getBlockInfoAsJson(b)));
p.sendMessage(" ");
}
Aggregations