Use WorldStorage, but it still doesn't save :/
This commit is contained in:
parent
f90bb45351
commit
44817f1a03
5 changed files with 46 additions and 118 deletions
|
@ -58,7 +58,6 @@ import techreborn.packets.PacketAesu;
|
||||||
import techreborn.packets.PacketIdsu;
|
import techreborn.packets.PacketIdsu;
|
||||||
import techreborn.packets.PacketSyncSideConfig;
|
import techreborn.packets.PacketSyncSideConfig;
|
||||||
import techreborn.proxies.CommonProxy;
|
import techreborn.proxies.CommonProxy;
|
||||||
import techreborn.tiles.idsu.IDSUManager;
|
|
||||||
import techreborn.utils.StackWIPHandler;
|
import techreborn.utils.StackWIPHandler;
|
||||||
import techreborn.world.TechRebornWorldGen;
|
import techreborn.world.TechRebornWorldGen;
|
||||||
|
|
||||||
|
@ -112,8 +111,6 @@ public class Core {
|
||||||
compatModule.preInit(event);
|
compatModule.preInit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
IDSUManager.init();
|
|
||||||
|
|
||||||
//Ore Dictionary
|
//Ore Dictionary
|
||||||
OreDict.init();
|
OreDict.init();
|
||||||
proxy.preInit(event);
|
proxy.preInit(event);
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
package techreborn.tiles.idsu;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTBase;
|
|
||||||
import net.minecraft.nbt.NBTTagDouble;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class CapabilityIDSUStorage implements Capability.IStorage<IDataIDSU> {
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public NBTBase writeNBT(Capability<IDataIDSU> capability, IDataIDSU instance, EnumFacing side) {
|
|
||||||
return new NBTTagDouble(instance.getStoredPower());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readNBT(Capability<IDataIDSU> capability, IDataIDSU instance, EnumFacing side, NBTBase nbt) {
|
|
||||||
instance.setStoredPower(((NBTTagDouble)nbt).getDouble());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package techreborn.tiles.idsu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by modmuss50 on 13/06/2017.
|
|
||||||
*/
|
|
||||||
public class IDSUEnergyStore implements IDataIDSU {
|
|
||||||
|
|
||||||
double power;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getStoredPower() {
|
|
||||||
return power;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setStoredPower(double storedPower) {
|
|
||||||
power = storedPower;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,86 +24,20 @@
|
||||||
|
|
||||||
package techreborn.tiles.idsu;
|
package techreborn.tiles.idsu;
|
||||||
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraft.world.storage.MapStorage;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import techreborn.lib.ModInfo;
|
||||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
|
||||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
|
||||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
public class IDSUManager {
|
public class IDSUManager {
|
||||||
|
|
||||||
|
|
||||||
@CapabilityInject(IDataIDSU.class)
|
|
||||||
public static Capability<IDataIDSU> CAPABILITY_IDSU = null;
|
|
||||||
|
|
||||||
public static void init(){
|
|
||||||
CapabilityManager.INSTANCE.register(IDataIDSU.class, new CapabilityIDSUStorage(), new Factory());
|
|
||||||
MinecraftForge.EVENT_BUS.register(IDSUManager.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void Attach(AttachCapabilitiesEvent<World> event){
|
|
||||||
event.addCapability(new ResourceLocation("techreborn","idsuManager"), new CapProvider(event.getObject()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class CapProvider implements ICapabilityProvider {
|
|
||||||
|
|
||||||
World world;
|
|
||||||
IDSUEnergyStore store;
|
|
||||||
|
|
||||||
public CapProvider(World world) {
|
|
||||||
this.world = world;
|
|
||||||
this.store = new IDSUEnergyStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCapability(
|
|
||||||
@Nonnull
|
|
||||||
Capability<?> capability,
|
|
||||||
@Nullable
|
|
||||||
EnumFacing facing) {
|
|
||||||
if(capability == CAPABILITY_IDSU){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public <T> T getCapability(
|
|
||||||
@Nonnull
|
|
||||||
Capability<T> capability,
|
|
||||||
@Nullable
|
|
||||||
EnumFacing facing) {
|
|
||||||
if(capability == CAPABILITY_IDSU){
|
|
||||||
return (T) store;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Factory implements Callable<IDataIDSU> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IDataIDSU call() throws Exception {
|
|
||||||
return new IDSUEnergyStore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IDataIDSU getData(World world){
|
public static IDataIDSU getData(World world){
|
||||||
if(world.hasCapability(CAPABILITY_IDSU, null)){
|
MapStorage storage = world.getPerWorldStorage();
|
||||||
return world.getCapability(CAPABILITY_IDSU, null);
|
IDSUSaveManger instance = (IDSUSaveManger) storage.getOrLoadData(IDSUSaveManger.class, ModInfo.MOD_ID + "_IDSU");
|
||||||
|
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new IDSUSaveManger(ModInfo.MOD_ID + "_IDSU");
|
||||||
|
storage.setData(ModInfo.MOD_ID + "_IDSU", instance);
|
||||||
}
|
}
|
||||||
return null;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
37
src/main/java/techreborn/tiles/idsu/IDSUSaveManger.java
Normal file
37
src/main/java/techreborn/tiles/idsu/IDSUSaveManger.java
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package techreborn.tiles.idsu;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.storage.WorldSavedData;
|
||||||
|
import techreborn.lib.ModInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by modmuss50 on 13/06/2017.
|
||||||
|
*/
|
||||||
|
public class IDSUSaveManger extends WorldSavedData implements IDataIDSU {
|
||||||
|
public IDSUSaveManger(String name) {
|
||||||
|
super(ModInfo.MOD_ID + "_IDSU");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
|
power = nbt.getDouble("power");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||||
|
compound.setDouble("power", power);
|
||||||
|
return compound;
|
||||||
|
}
|
||||||
|
|
||||||
|
double power;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getStoredPower() {
|
||||||
|
return power;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStoredPower(double storedPower) {
|
||||||
|
power = storedPower;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue