mirror of
https://github.com/GTNewHorizons/gendustry.git
synced 2026-11-19 11:59:32 +00:00
Separated DataSlotPower from MJ interface, added RF support (WIP)
This commit is contained in:
1 parent
c1a7ff3105
commit
25fcb30866
13 files changed
+228
-130
No files matched your search
+1
-1
@@ -21,7 +21,7 @@ buildscript {
|
||||
apply plugin: 'forge'
|
||||
apply plugin: 'scala'
|
||||
|
||||
version = "0.9.1"
|
||||
version = "0.9.2"
|
||||
ext.bdlibver = "0.9.0.2"
|
||||
ext.versuffix = "mc164"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* This file belongs to CoFHLib and is here temporarily, untill i implement full TE support
|
||||
* This file belongs to CoFHLib and is here temporarily, untill i switch to use @API interface stripping
|
||||
* It's licensed under LGPLv3
|
||||
*
|
||||
* https://github.com/KingLemming/CoFHLib
|
||||
@@ -11,23 +11,19 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
*
|
||||
* <p/>
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyContainerItem {
|
||||
|
||||
/**
|
||||
* Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be charged.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be sent into the item.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @param container ItemStack to be charged.
|
||||
* @param maxReceive Maximum amount of energy to be sent into the item.
|
||||
* @param simulate If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received by the item.
|
||||
*/
|
||||
int receiveEnergy(ItemStack container, int maxReceive, boolean simulate);
|
||||
@@ -36,12 +32,9 @@ public interface IEnergyContainerItem {
|
||||
* Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally
|
||||
* discharged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be discharged.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted from the item.
|
||||
* @param simulate
|
||||
* If TRUE, the discharge will only be simulated.
|
||||
* @param container ItemStack to be discharged.
|
||||
* @param maxExtract Maximum amount of energy to be extracted from the item.
|
||||
* @param simulate If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the item.
|
||||
*/
|
||||
int extractEnergy(ItemStack container, int maxExtract, boolean simulate);
|
||||
@@ -55,5 +48,4 @@ public interface IEnergyContainerItem {
|
||||
* Get the max amount of energy that can be stored in the container item.
|
||||
*/
|
||||
int getMaxEnergyStored(ItemStack container);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file belongs to CoFHLib and is here temporarily, untill i switch to use @API interface stripping
|
||||
* It's licensed under LGPLv3
|
||||
*
|
||||
* https://github.com/KingLemming/CoFHLib
|
||||
*/
|
||||
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p/>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*/
|
||||
public interface IEnergyHandler {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from Orientation the energy is received from.
|
||||
* @param maxReceive Maximum amount of energy to received.
|
||||
* @param simulate If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from Orientation the energy is extracted to.
|
||||
* @param maxExtract Maximum amount of energy to extract.
|
||||
* @param simulate If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns true if the Handler functions on a given side - if a Tile Entity can receive and/or send energy from a given side, this should return true.
|
||||
*/
|
||||
boolean canInterface(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.data
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import buildcraft.api.power.{IPowerReceptor, PowerHandler}
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlot}
|
||||
import net.bdew.gendustry.machines.PoweredMachine
|
||||
|
||||
case class DataSlotPower(name: String, parent: TileDataSlots, kind: PowerHandler.Type) extends DataSlot {
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
var oldVal = 0F
|
||||
|
||||
require(parent.isInstanceOf[IPowerReceptor])
|
||||
val handler = new PowerHandler(parent.asInstanceOf[IPowerReceptor], kind)
|
||||
|
||||
def configure(cfg: PoweredMachine): DataSlotPower = {
|
||||
handler.configure(cfg.minReceivedEnergy, cfg.maxReceivedEnergy, cfg.activationEnergy, cfg.maxStoredEnergy)
|
||||
handler.configurePowerPerdition(cfg.powerLoss, cfg.powerLossInterval)
|
||||
return this
|
||||
}
|
||||
|
||||
parent.serverTick.listen(checkUpdate)
|
||||
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
|
||||
def checkUpdate() {
|
||||
handler.update()
|
||||
if (getEnergyStored != oldVal) {
|
||||
oldVal = getEnergyStored
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
}
|
||||
|
||||
def useEnergy(min: Float, max: Float, doUse: Boolean): Float = handler.useEnergy(min, max, doUse)
|
||||
def getMinEnergyReceived: Float = handler.getMinEnergyReceived
|
||||
def getMaxEnergyReceived: Float = handler.getMaxEnergyReceived
|
||||
def getMaxEnergyStored: Float = handler.getMaxEnergyStored
|
||||
def getActivationEnergy: Float = handler.getActivationEnergy
|
||||
def getEnergyStored: Float = handler.getEnergyStored
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
handler.writeToNBT(t, name)
|
||||
if (kind == UpdateKind.GUI)
|
||||
t.getCompoundTag(name).setFloat("maxStored", getMaxEnergyStored)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
handler.readFromNBT(t, name)
|
||||
if (kind == UpdateKind.GUI)
|
||||
handler.configure(getMaxEnergyReceived, getMaxEnergyReceived, getActivationEnergy, t.getCompoundTag(name).getFloat("maxStored"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.data
|
||||
|
||||
import buildcraft.api.power.{PowerHandler, IPowerReceptor}
|
||||
import net.minecraft.world.World
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
|
||||
trait ExposePower extends TileExtended with IPowerReceptor {
|
||||
def getPowerDataslot(from: ForgeDirection): DataSlotPower
|
||||
def doWork(workProvider: PowerHandler) {}
|
||||
def getPowerReceiver(side: ForgeDirection) = getPowerDataslot(side).handler.getPowerReceiver
|
||||
def getWorld: World = worldObj
|
||||
}
|
||||
@@ -12,7 +12,7 @@ package net.bdew.gendustry.gui
|
||||
import net.bdew.lib.gui.{Point, TextureLocation, Rect}
|
||||
import scala.collection.mutable
|
||||
import java.text.DecimalFormat
|
||||
import net.bdew.gendustry.data.DataSlotPower
|
||||
import net.bdew.gendustry.power.DataSlotPower
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.bdew.lib.gui.widgets.Widget
|
||||
|
||||
@@ -21,9 +21,9 @@ class WidgetMJGauge(val rect: Rect, texture: TextureLocation, dslot: DataSlotPow
|
||||
|
||||
override def draw() {
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(texture.resource)
|
||||
val fill = (dslot.getEnergyStored / dslot.getMaxEnergyStored * rect.h).round
|
||||
val fill = (dslot.stored / dslot.capacity * rect.h).round
|
||||
parent.drawTexturedModalRect(rect.x, rect.y + rect.h - fill, texture.x, texture.y + rect.h - fill, rect.w, fill)
|
||||
}
|
||||
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += formater.format(dslot.getEnergyStored) + "/" + formater.format(dslot.getMaxEnergyStored) + " MJ"
|
||||
override def handleTooltip(p: Point, tip: mutable.MutableList[String]) = tip += formater.format(dslot.stored) + "/" + formater.format(dslot.capacity) + " MJ"
|
||||
}
|
||||
@@ -12,25 +12,24 @@ package net.bdew.gendustry.machines
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, SidedInventory, PersistentInventoryTile}
|
||||
import net.bdew.gendustry.data.{DataSlotPower, ExposePower}
|
||||
import net.bdew.gendustry.power.{TilePowered, DataSlotPower}
|
||||
import buildcraft.api.power.PowerHandler.Type
|
||||
import net.bdew.lib.data.DataSlotFloat
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
|
||||
abstract class TileBaseProcessor extends TileExtended
|
||||
with TileDataSlots
|
||||
with PersistentInventoryTile
|
||||
with BreakableInventoryTile
|
||||
with SidedInventory
|
||||
with ExposePower {
|
||||
with TilePowered {
|
||||
def cfg: ProcessorMachine
|
||||
val power = DataSlotPower("power", this, Type.MACHINE).configure(cfg)
|
||||
val power = DataSlotPower("power", this, Type.MACHINE)
|
||||
val progress = DataSlotFloat("progress", this).setUpdate(UpdateKind.SAVE, UpdateKind.GUI)
|
||||
|
||||
def getPowerDataslot(from: ForgeDirection): DataSlotPower = power
|
||||
configurePower(cfg)
|
||||
|
||||
override def tickServer() {
|
||||
if (power.getEnergyStored > cfg.activationEnergy) {
|
||||
if (power.stored > cfg.activationEnergy) {
|
||||
|
||||
if (!isWorking)
|
||||
if (tryStart())
|
||||
@@ -38,9 +37,9 @@ with ExposePower {
|
||||
|
||||
if (isWorking) {
|
||||
|
||||
if ((progress < 1) && (power.getEnergyStored > cfg.activationEnergy)) {
|
||||
val maxConsume = Math.min(Math.max(cfg.powerUseRate * power.getEnergyStored, cfg.activationEnergy), cfg.mjPerItem * (1 - progress))
|
||||
val consumed = power.useEnergy(0, maxConsume, true)
|
||||
if ((progress < 1) && (power.stored > cfg.activationEnergy)) {
|
||||
val maxConsume = Math.min(Math.max(cfg.powerUseRate * power.stored, cfg.activationEnergy), cfg.mjPerItem * (1 - progress))
|
||||
val consumed = power.extract(maxConsume, false)
|
||||
progress += consumed / cfg.mjPerItem
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ package net.bdew.gendustry.machines.apiary
|
||||
|
||||
import net.bdew.lib.data._
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, SidedInventory, PersistentInventoryTile}
|
||||
import net.bdew.gendustry.data.ExposePower
|
||||
import forestry.api.apiculture._
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import forestry.api.genetics.{AlleleManager, IIndividual}
|
||||
@@ -31,14 +30,14 @@ import net.bdew.lib.data.DataSlotFloat
|
||||
import net.bdew.lib.data.DataSlotInt
|
||||
import net.bdew.lib.data.DataSlotString
|
||||
import net.bdew.lib.data.DataSlotBoolean
|
||||
import net.bdew.gendustry.data.DataSlotPower
|
||||
import net.bdew.gendustry.power.{TilePowered, DataSlotPower}
|
||||
|
||||
class TileApiary extends TileExtended
|
||||
with TileDataSlots
|
||||
with PersistentInventoryTile
|
||||
with SidedInventory
|
||||
with BreakableInventoryTile
|
||||
with ExposePower
|
||||
with TilePowered
|
||||
with IBeeHousing {
|
||||
val slotsBees = 0 to 1
|
||||
val slotsUpgrades = 2 to 5
|
||||
@@ -51,12 +50,14 @@ with IBeeHousing {
|
||||
val logic = beeRoot.createBeekeepingLogic(this)
|
||||
lazy val cfg = Machines.apiary
|
||||
|
||||
val power = DataSlotPower("power", this, Type.MACHINE).configure(cfg)
|
||||
val power = DataSlotPower("power", this, Type.MACHINE)
|
||||
val errorState = DataSlotInt("error", this).setUpdate(UpdateKind.GUI, UpdateKind.SAVE, UpdateKind.WORLD)
|
||||
val owner = DataSlotString("owner", this, "").setUpdate(UpdateKind.SAVE)
|
||||
val guiProgress = DataSlotFloat("progress", this)
|
||||
val guiBreeding = DataSlotFloat("breeding", this)
|
||||
|
||||
configurePower(cfg)
|
||||
|
||||
// for client rendering and fx
|
||||
val hasLight = DataSlotBoolean("haslight", this).setUpdate(UpdateKind.WORLD)
|
||||
val queen = DataSlotItemStack("queen", this).setUpdate(UpdateKind.WORLD)
|
||||
@@ -100,10 +101,10 @@ with IBeeHousing {
|
||||
serverTick.listen(() => {
|
||||
movePrincess = false
|
||||
|
||||
if (power.getEnergyStored >= cfg.baseMjPerTick * mods.energy) {
|
||||
if (power.stored >= cfg.baseMjPerTick * mods.energy) {
|
||||
logic.update()
|
||||
if ((logic.getQueen != null || logic.getBreedingTime > 0) && (errorState :== 1))
|
||||
power.useEnergy(cfg.baseMjPerTick, cfg.baseMjPerTick * mods.energy, true)
|
||||
power.extract(cfg.baseMjPerTick * mods.energy, false)
|
||||
} else {
|
||||
setErrorState(-1)
|
||||
}
|
||||
|
||||
@@ -9,15 +9,8 @@
|
||||
|
||||
package net.bdew.gendustry.machines.sampler
|
||||
|
||||
import buildcraft.api.power.PowerHandler.Type
|
||||
import net.bdew.gendustry.data.{DataSlotPower, ExposePower}
|
||||
import net.bdew.gendustry.config.{Items, Machines}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.bdew.lib.data.{DataSlotItemStack, DataSlotFloat}
|
||||
import net.bdew.lib.tile.inventory.{BreakableInventoryTile, SidedInventory, PersistentInventoryTile}
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.lib.data.base.{UpdateKind, TileDataSlots}
|
||||
import forestry.api.genetics.AlleleManager
|
||||
import net.bdew.gendustry.machines.TileItemProcessor
|
||||
import scala.util.Random
|
||||
@@ -34,13 +27,13 @@ class TileSampler extends TileItemProcessor {
|
||||
if (root == null) return new ItemStack(Items.waste)
|
||||
val member = root.getMember(stack)
|
||||
val genome = member.getGenome
|
||||
val chromosomes = genome.getChromosomes.zipWithIndex.filter(_._1!=null)
|
||||
val chromosomes = genome.getChromosomes.zipWithIndex.filter(_._1 != null)
|
||||
val alleles = chromosomes.map({
|
||||
case (x,n)=>Seq(n -> x.getPrimaryAllele, n-> x.getSecondaryAllele)
|
||||
case (x, n) => Seq(n -> x.getPrimaryAllele, n -> x.getSecondaryAllele)
|
||||
}).flatten
|
||||
|
||||
val rand = new Random()
|
||||
val (chr,allele) = alleles(rand.nextInt(alleles.length))
|
||||
val (chr, allele) = alleles(rand.nextInt(alleles.length))
|
||||
return Items.geneSample.newStack(GeneSampleInfo(root, chr, allele))
|
||||
}
|
||||
|
||||
@@ -58,7 +51,6 @@ class TileSampler extends TileItemProcessor {
|
||||
} else return false
|
||||
}
|
||||
|
||||
|
||||
override def isItemValidForSlot(slot: Int, itemstack: ItemStack): Boolean = {
|
||||
if (itemstack == null || itemstack.getItem == null) return false
|
||||
slot match {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.power
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import buildcraft.api.power.PowerHandler
|
||||
import net.bdew.lib.data.base.{TileDataSlots, UpdateKind, DataSlot}
|
||||
import net.bdew.gendustry.machines.PoweredMachine
|
||||
import net.bdew.lib.Misc
|
||||
|
||||
case class DataSlotPower(name: String, parent: TileDataSlots, kind: PowerHandler.Type) extends DataSlot {
|
||||
updateKind = Set(UpdateKind.GUI, UpdateKind.SAVE)
|
||||
|
||||
var stored = 0F
|
||||
var capacity = 0F
|
||||
|
||||
def inject(v: Float, simulate: Boolean): Float = {
|
||||
val canAdd = Misc.clamp(v, 0F, capacity - stored)
|
||||
if ((canAdd > 0) && !simulate) {
|
||||
stored += canAdd
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
return canAdd
|
||||
}
|
||||
|
||||
def extract(v: Float, simulate: Boolean): Float = {
|
||||
val canExtract = Misc.clamp(v, 0F, stored)
|
||||
if ((canExtract > 0) && !simulate) {
|
||||
stored -= canExtract
|
||||
parent.dataSlotChanged(this)
|
||||
}
|
||||
return canExtract
|
||||
}
|
||||
|
||||
def configure(cfg: PoweredMachine) {
|
||||
capacity = cfg.maxStoredEnergy
|
||||
}
|
||||
|
||||
def save(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
val tag = new NBTTagCompound()
|
||||
tag.setFloat("stored", stored)
|
||||
if (kind == UpdateKind.GUI)
|
||||
tag.setFloat("capacity", capacity)
|
||||
t.setCompoundTag(name, tag)
|
||||
}
|
||||
|
||||
def load(t: NBTTagCompound, kind: UpdateKind.Value) {
|
||||
if (t.hasKey(name)) {
|
||||
val tag = t.getCompoundTag(name)
|
||||
stored = tag.getFloat("stored")
|
||||
if (kind == UpdateKind.GUI)
|
||||
capacity = tag.getFloat("capacity")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.power
|
||||
|
||||
import net.bdew.lib.tile.TileExtended
|
||||
import net.bdew.gendustry.machines.PoweredMachine
|
||||
|
||||
trait TilePoweredBase extends TileExtended {
|
||||
def power: DataSlotPower
|
||||
def configurePower(cfg: PoweredMachine) = power.configure(cfg)
|
||||
}
|
||||
|
||||
trait TilePowered extends TilePoweredBase with TilePoweredMJ with TilePoweredRF
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.power
|
||||
|
||||
import buildcraft.api.power.{PowerHandler, IPowerReceptor}
|
||||
import net.bdew.gendustry.machines.PoweredMachine
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
|
||||
trait TilePoweredMJ extends TilePoweredBase with IPowerReceptor {
|
||||
val powerHandler = new PowerHandler(this, PowerHandler.Type.MACHINE)
|
||||
|
||||
def doWork(workProvider: PowerHandler) {}
|
||||
def getPowerReceiver(side: ForgeDirection) = powerHandler.getPowerReceiver
|
||||
def getWorld = worldObj
|
||||
|
||||
serverTick.listen(() => {
|
||||
val transfer = power.inject(powerHandler.getEnergyStored, false)
|
||||
powerHandler.useEnergy(transfer, transfer, true)
|
||||
})
|
||||
|
||||
override def configurePower(cfg: PoweredMachine) {
|
||||
super.configurePower(cfg)
|
||||
powerHandler.configure(cfg.minReceivedEnergy, cfg.maxReceivedEnergy, cfg.activationEnergy, cfg.maxStoredEnergy)
|
||||
powerHandler.configurePowerPerdition(cfg.powerLoss, cfg.powerLossInterval)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013
|
||||
* https://github.com/bdew/gendustry
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/gendustry/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.gendustry.power
|
||||
|
||||
import cofh.api.energy.IEnergyHandler
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import net.bdew.gendustry.config.Tuning
|
||||
|
||||
trait TilePoweredRF extends TilePoweredBase with IEnergyHandler {
|
||||
lazy val ratio = Tuning.getSection("Power").getFloat("RF/MJ Ratio")
|
||||
|
||||
def receiveEnergy(from: ForgeDirection, maxReceive: Int, simulate: Boolean) =
|
||||
(power.inject(maxReceive / ratio, simulate) * ratio).floor.toInt
|
||||
|
||||
def extractEnergy(from: ForgeDirection, maxExtract: Int, simulate: Boolean) = 0
|
||||
def canInterface(from: ForgeDirection) = true
|
||||
def getEnergyStored(from: ForgeDirection) = (power.stored * ratio).floor.toInt
|
||||
def getMaxEnergyStored(from: ForgeDirection) = (power.capacity * ratio).floor.toInt
|
||||
}
|
||||
Reference in new issue
Block a user