Created
February 5, 2017 08:50
-
-
Save Crypnotic/555ecf77b039dcc29fe535ff4e283988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TileEnergyCondenser extends TileEntity implements ITeslaHolder, ITeslaConsumer, ITeslaProducer { | |
private long stored; | |
private final long capacity; | |
private final long rate; | |
public TileEnergyCondenser() { | |
this.stored = 0L; | |
this.capacity = 50000000L; | |
this.rate = 5000L; | |
} | |
@Override | |
public boolean hasCapability(Capability<?> capability, EnumFacing facing) { | |
return (capability == TeslaCapabilities.CAPABILITY_CONSUMER || capability == TeslaCapabilities.CAPABILITY_HOLDER | |
|| capability == TeslaCapabilities.CAPABILITY_PRODUCER || super.hasCapability(capability, facing)); | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public <T> T getCapability(Capability<T> capability, EnumFacing facing) { | |
if (capability == TeslaCapabilities.CAPABILITY_HOLDER || capability == TeslaCapabilities.CAPABILITY_CONSUMER | |
|| capability == TeslaCapabilities.CAPABILITY_PRODUCER) { | |
return (T) this; | |
} | |
return super.getCapability(capability, facing); | |
} | |
@Override | |
public long getStoredPower() { | |
return this.stored; | |
} | |
@Override | |
public long getCapacity() { | |
return this.capacity; | |
} | |
@Override | |
public long takePower(long power, boolean simulated) { | |
long taken = Math.min(stored, Math.min(rate, power)); | |
if (!simulated) { | |
stored -= taken; | |
} | |
return taken; | |
} | |
@Override | |
public long givePower(long power, boolean simulated) { | |
final long given = Math.min(capacity - stored, Math.min(rate, power)); | |
if (!simulated) { | |
stored += given; | |
} | |
return given; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment