Add CPU energy consumptions
This commit is contained in:
@@ -5,7 +5,7 @@ org.gradle.daemon=false
|
||||
|
||||
forge_version=47.2.32
|
||||
|
||||
semver=1.0.1
|
||||
semver=1.1.0
|
||||
|
||||
curse_project_id=1037738
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public final class Config {
|
||||
//TODO: Implement configuration of CPU MHzs
|
||||
@Path("vm") public static long maxAllocatedMemory = 512 * Constants.MEGABYTE;
|
||||
|
||||
@Path("energy.blocks") public static double busCableEnergyPerTick = 0.1;
|
||||
@@ -31,6 +32,7 @@ public final class Config {
|
||||
|
||||
@Path("energy.items") public static double memoryEnergyPerMegabytePerTick = 0.5;
|
||||
@Path("energy.items") public static double hardDriveEnergyPerMegabytePerTick = 1;
|
||||
@Path("energy.items") public static double cpuEnergyPerMegahertzPerTick = 0.1;
|
||||
@Path("energy.items") public static int redstoneInterfaceCardEnergyPerTick = 1;
|
||||
@Path("energy.items") public static int networkInterfaceEnergyPerTick = 1;
|
||||
@Path("energy.items") public static int fileImportExportCardEnergyPerTick = 1;
|
||||
|
||||
@@ -2,9 +2,13 @@ package li.cil.oc2r.common.bus.device.provider.item;
|
||||
|
||||
import li.cil.oc2r.api.bus.device.ItemDevice;
|
||||
import li.cil.oc2r.api.bus.device.provider.ItemDeviceQuery;
|
||||
import li.cil.oc2r.common.Config;
|
||||
import li.cil.oc2r.common.Constants;
|
||||
import li.cil.oc2r.common.bus.device.provider.util.AbstractItemDeviceProvider;
|
||||
import li.cil.oc2r.common.bus.device.rpc.item.CPUItemDevice;
|
||||
import li.cil.oc2r.common.item.CPUItem;
|
||||
import li.cil.oc2r.common.item.MemoryItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -22,6 +26,9 @@ public class CPUItemDeviceProvider extends AbstractItemDeviceProvider {
|
||||
|
||||
@Override
|
||||
protected int getItemDeviceEnergyConsumption(final ItemDeviceQuery query) {
|
||||
return 1;
|
||||
final ItemStack stack = query.getItemStack();
|
||||
final CPUItem item = (CPUItem) stack.getItem();
|
||||
final int freq = Math.max(item.getFrequency(), 0);
|
||||
return Math.max(1, (int) Math.round(freq * Config.cpuEnergyPerMegahertzPerTick / 1_000_000));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user