mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Introducing a new standardized energy capability system.
Heavily inspired by the old RedstoneFlux API developed by King Lemming and Team CoFH.
This commit is contained in:
1 parent
5964bf8cb2
commit
45097fed0c
4 files changed
+183
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package net.minecraftforge.energy;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.*;
|
||||
import net.minecraftforge.common.capabilities.Capability.IStorage;
|
||||
|
||||
public class CapabilityEnergy
|
||||
{
|
||||
@CapabilityInject(IEnergyStorage.class)
|
||||
public static Capability<IEnergyStorage> ENERGY = null;
|
||||
|
||||
public static void register()
|
||||
{
|
||||
CapabilityManager.INSTANCE.register(IEnergyStorage.class, new IStorage<IEnergyStorage>()
|
||||
{
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, EnumFacing side)
|
||||
{
|
||||
return new NBTTagInt(instance.getEnergyStored());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<IEnergyStorage> capability, IEnergyStorage instance, EnumFacing side, NBTBase nbt)
|
||||
{
|
||||
if (!(instance instanceof EnergyStorage))
|
||||
throw new IllegalArgumentException("Can not deserialize to an instance that isn't the default implementation");
|
||||
((EnergyStorage)instance).energy = ((NBTTagInt)nbt).getInt();
|
||||
}
|
||||
},
|
||||
new Callable<IEnergyStorage>()
|
||||
{
|
||||
@Override
|
||||
public IEnergyStorage call() throws Exception
|
||||
{
|
||||
return new EnergyStorage(1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user