• Recently Browsing

    No registered users viewing this page.

  • Posts

    • oh, sry for the long wait. I'm no longer responding to this forum as my question has been answered. thanks for helping. 
    • I have created a custom Capability in order to store ItemStack specific information on a particular item. The Capability functionality works in that each itemstack has its own information. However, the NBT does not appear to be saving and loading correctly, as the values reset upon exiting and reopening the world. After doing some debugging, I determined that the writeNBT function in the storage class is being called, but the readNBT function is not. Is there something I need to do to my Item class to make the Capability Storage work properly? Or is something in my Capability implementation incorrect?   Interface: public interface GunInfo { public void setClip(int clip); public void setReload(int reload); public void setRecoil(float recoil, float yaw, float antiyaw, float antirec); public void setReloading(boolean reload); public void setCooldown(int cd); public int getClip(); public int getReload(); public float getRecoil(); public float getYaw(); public float getAntiYaw(); public float getAntiRecoil(); public boolean isReloading(); public int getCooldown(); }   Storage class: public class GunInfoStorage implements IStorage<GunInfo> { @Override public INBT writeNBT(Capability<GunInfo> capability, GunInfo instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.putInt("clip", instance.getClip()); tag.putInt("reload", instance.getReload()); tag.putBoolean("reload", instance.isReloading()); return tag; } @Override public void readNBT(Capability<GunInfo> capability, GunInfo instance, Direction side, INBT nbt) { CompoundNBT tag = (CompoundNBT) nbt; instance.setClip(tag.getInt("clip")); instance.setReload(tag.getInt("reload")); instance.setReloading(tag.getBoolean("reload")); } }   Provider Class:   public class GunInfoProvider implements GunInfo, ICapabilitySerializable<INBT> { @CapabilityInject(GunInfo.class) public static Capability<GunInfo> guninfo = null; private LazyOptional<GunInfo> instance = LazyOptional.of(guninfo::getDefaultInstance); @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return cap == guninfo ? instance.cast() : LazyOptional.empty(); } @Override public INBT serializeNBT() { return guninfo.getStorage().writeNBT(guninfo, this.instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null); } @Override public void deserializeNBT(INBT nbt) { guninfo.getStorage().readNBT(guninfo, this.instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt); } public int currentClip; public int currentReload; public float recoil, yawRecoil, antiYaw, antiRecoil; public boolean reloading; public int cooldown; public void setClip(int clip) { currentClip = clip; } public void setReload(int reload) { currentReload = reload; } public void setRecoil(float rec, float yaw, float antiyaw, float antirec) { recoil = rec; yawRecoil = yaw; antiYaw = antiyaw; antiRecoil = antirec; } @Override public void setReloading(boolean reload) { reloading = reload; } @Override public void setCooldown(int cd) { cooldown = cd; } @Override public int getClip() { return currentClip; } @Override public int getReload() { return currentReload; } @Override public float getRecoil() { return recoil; } @Override public float getYaw() { return yawRecoil; } @Override public float getAntiYaw() { return antiYaw; } @Override public float getAntiRecoil() { return antiRecoil; } @Override public boolean isReloading() { return reloading; } @Override public int getCooldown() { return cooldown; } }   AttachCapabilities event function:   @Mod.EventBusSubscriber public class FmlEvents { static int capid = 0; @CapabilityInject(GunInfo.class) public static Capability<GunInfo> guninfo = null; @SubscribeEvent public static void onAttachCapabilities(AttachCapabilitiesEvent<ItemStack> event) { if (event.getObject().getItem() instanceof ItemGun) { event.addCapability(new ResourceLocation("gunmod", "guninfo" + capid++), new GunInfoProvider()); } } }   And here is where I register the capability: private void setup(final FMLCommonSetupEvent event) { CapabilityManager.INSTANCE.register(GunInfo.class, new GunInfoStorage(), GunInfoProvider::new); }  
    • simply, how do I add an itemstack to a horses saddle/horsearmor slot?
    • That part there. The server has considered himself as to be crashed and conducted a forced shutdown. I don't get why because its totally out of the blue.
    • Anyone have an idea on why this is happening?  
  • Topics

  • Who's Online (See full list)