Posted March 9, 20169 yr Capability not getting saved/loaded on world save/load. Using the same writeNBT and loadNBT methods for updating the client with changes works, so the methods themselves are writing to nbt and reading from it fine. public class DefaultDrafter implements IDrafter{ public static class DrafterStorage implements IStorage<IDrafter>{ public static final DrafterStorage drafterStorage = new DrafterStorage(); @Override public NBTBase writeNBT(Capability<IDrafter> capability, IDrafter instance, EnumFacing side) { NBTTagCompound nbtDrafterCapabilities = new NBTTagCompound(); NBTTagCompound nbtLuxinLevel = new NBTTagCompound(); NBTTagCompound nbtLuxinCap = new NBTTagCompound(); NBTTagCompound nbtLuxinAvailable = new NBTTagCompound(); NBTTagCompound nbtDraftables = new NBTTagCompound(); nbtDrafterCapabilities.setFloat("draft_cap", ((DefaultDrafter)instance).draftCap); nbtDrafterCapabilities.setFloat("draft_used", ((DefaultDrafter)instance).draftUsed); nbtDrafterCapabilities.setInteger("sick_ticks", ((DefaultDrafter)instance).sickTicks); nbtDrafterCapabilities.setString("drafting_selection", ((DefaultDrafter)instance).draftingSelection); for(String luxin : ((DefaultDrafter)instance).luxinLevel.keySet()) { nbtLuxinLevel.setFloat(luxin, ((DefaultDrafter)instance).luxinLevel.get(luxin)); nbtLuxinCap.setFloat(luxin, ((DefaultDrafter)instance).luxinCap.get(luxin)); nbtLuxinAvailable.setFloat(luxin, ((DefaultDrafter)instance).luxinAvailable.get(luxin)); } for(String draft : ((DefaultDrafter)instance).draftables.keySet()) nbtDraftables.setTag(draft, CoreFactory.saveNBT(((DefaultDrafter)instance).draftables.get(draft))); nbtDrafterCapabilities.setTag(CAP, nbtLuxinCap); nbtDrafterCapabilities.setTag(LEVEL, nbtLuxinLevel); nbtDrafterCapabilities.setTag(AVAILABLE, nbtLuxinAvailable); nbtDrafterCapabilities.setTag(DRAFTABLE, nbtDraftables); return nbtDrafterCapabilities; } @Override public void readNBT(Capability<IDrafter> capability, IDrafter instance, EnumFacing side, NBTBase nbt) { NBTTagCompound nbtExtendedProperties = (NBTTagCompound) nbt; NBTTagCompound nbtLuxinLevel = nbtExtendedProperties.getCompoundTag(LEVEL); NBTTagCompound nbtLuxinCap = nbtExtendedProperties.getCompoundTag(CAP); NBTTagCompound nbtLuxinAvailable = nbtExtendedProperties.getCompoundTag(AVAILABLE); NBTTagCompound nbtDraftables = nbtExtendedProperties.getCompoundTag(DRAFTABLE); ((DefaultDrafter)instance).draftCap = nbtExtendedProperties.getFloat("draft_cap"); ((DefaultDrafter)instance).draftUsed = nbtExtendedProperties.getFloat("draft_used"); ((DefaultDrafter)instance).sickTicks = nbtExtendedProperties.getInteger("sick_ticks"); ((DefaultDrafter)instance).draftingSelection = nbtExtendedProperties.getString("drafting_selection"); for(String luxin : nbtLuxinLevel.getKeySet()) { ((DefaultDrafter)instance).luxinLevel.put(luxin, nbtLuxinLevel.getFloat(luxin)); ((DefaultDrafter)instance).luxinCap.put(luxin, nbtLuxinCap.getFloat(luxin)); ((DefaultDrafter)instance).luxinAvailable.put(luxin, nbtLuxinAvailable.getFloat(luxin)); } for(String draft : ((DefaultDrafter)instance).draftables.keySet()) ((DefaultDrafter)instance).draftables.put(draft, CoreFactory.loadNBT((NBTTagCompound) nbtDraftables.getTag(draft))); } } } public class DraftingProvider implements ICapabilityProvider{ @CapabilityInject(IDrafter.class) public static Capability<IDrafter> CHROMATPLAYER = null; private IDrafter drafter = null; public DraftingProvider(){} public DraftingProvider(IDrafter drafter){ this.drafter = drafter; } @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return CHROMATPLAYER != null && capability == CHROMATPLAYER; } @SuppressWarnings("unchecked") @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (CHROMATPLAYER != null && capability == CHROMATPLAYER) return (T)drafter; return null; } CommonProxy{ public void preInit(){ CapabilityManager.INSTANCE.register(IDrafter.class, DrafterStorage.drafterStorage, DefaultDrafter.class); } } and this in my EventHandler @SubscribeEvent public void AttachCapability(AttachCapabilitiesEvent.Entity e) { if(!e.getEntity().hasCapability(DraftingProvider.CHROMATPLAYER, null) && e.getEntity() instanceof EntityPlayer) e.addCapability(Refs.DRAFTER, new DraftingProvider(new DefaultDrafter())); } is there something I am missing? ------------------------ Solution: Implement INBTSerializable in your provider. Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
March 9, 20169 yr public class DraftingProvider implements ICapabilityProvider{ https://github.com/MinecraftForge/MinecraftForge/blob/master/src/main/java/net/minecraftforge/common/capabilities/CapabilityDispatcher.java#L52-L61 I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
March 9, 20169 yr Author Thanks, I didn't see that in any of the examples I came across. Now I just need to convert my EntityJoinWorldEvent and I should be back up to where I was with IEEP. Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.