Created
April 7, 2017 20:36
-
-
Save loordgek/e9e2de565658dc15f8990342ebadb434 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
package loordgek.teslatest; | |
import net.darkhax.tesla.capability.TeslaCapabilities; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraftforge.common.capabilities.Capability; | |
import net.minecraftforge.energy.CapabilityEnergy; | |
import net.minecraftforge.energy.EnergyStorage; | |
import javax.annotation.Nullable; | |
public class tile extends TileEntity { | |
EnergyStorage energyStorage = new EnergyStorage(20000); | |
Wrapper wrapper = new Wrapper(energyStorage); | |
@Override | |
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { | |
return capability == CapabilityEnergy.ENERGY || | |
capability == TeslaCapabilities.CAPABILITY_CONSUMER || | |
capability == TeslaCapabilities.CAPABILITY_HOLDER || | |
capability == TeslaCapabilities.CAPABILITY_PRODUCER || | |
super.hasCapability(capability, facing); | |
} | |
@Nullable | |
@Override | |
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { | |
if (capability == CapabilityEnergy.ENERGY) | |
return CapabilityEnergy.ENERGY.cast(energyStorage); | |
if (capability == TeslaCapabilities.CAPABILITY_CONSUMER) | |
return TeslaCapabilities.CAPABILITY_CONSUMER.cast(wrapper); | |
if (capability == TeslaCapabilities.CAPABILITY_HOLDER) | |
return TeslaCapabilities.CAPABILITY_HOLDER.cast(wrapper); | |
if (capability == TeslaCapabilities.CAPABILITY_PRODUCER) | |
return TeslaCapabilities.CAPABILITY_PRODUCER.cast(wrapper); | |
return super.getCapability(capability, facing); | |
} | |
} |
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
package loordgek.teslatest; | |
import net.darkhax.tesla.api.ITeslaConsumer; | |
import net.darkhax.tesla.api.ITeslaHolder; | |
import net.darkhax.tesla.api.ITeslaProducer; | |
import net.minecraftforge.energy.IEnergyStorage; | |
public class Wrapper implements ITeslaConsumer, ITeslaHolder, ITeslaProducer { | |
private final IEnergyStorage energyStorage; | |
public Wrapper(IEnergyStorage energyStorage) { | |
this.energyStorage = energyStorage; | |
} | |
/** | |
* Offers power to the Tesla Consumer. | |
* | |
* @param power The amount of power to offer. | |
* @param simulated Whether or not this is being called as part of a simulation. | |
* Simulations are used to get information without affecting the Tesla Producer. | |
* @return The amount of power that the consumer accepts. | |
*/ | |
@Override | |
public long givePower(long power, boolean simulated) { | |
return energyStorage.receiveEnergy((int) power, simulated); | |
} | |
/** | |
* Gets the amount of Tesla power stored being stored. | |
* | |
* @return The amount of Tesla power being stored. | |
*/ | |
@Override | |
public long getStoredPower() { | |
return energyStorage.getEnergyStored(); | |
} | |
/** | |
* Gets the maximum amount of Tesla power that can be held. | |
* | |
* @return The maximum amount of Tesla power that can be held. | |
*/ | |
@Override | |
public long getCapacity() { | |
return energyStorage.getMaxEnergyStored(); | |
} | |
/** | |
* Requests an amount of power from the Tesla Producer. | |
* | |
* @param power The amount of power to request. | |
* @param simulated Whether or not this is being called as part of a simulation. | |
* Simulations are used to get information without affecting the Tesla Producer. | |
* @return The amount of power that the Tesla Producer will give. | |
*/ | |
@Override | |
public long takePower(long power, boolean simulated) { | |
return energyStorage.extractEnergy((int) power, simulated); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment