Posted May 19, 20205 yr I have been trying to implement new capabilities into my mod, and I thought I had it working but I have encountered an error, with Crash report attached. Main Class @Mod(FantasyOres.MOD_ID) @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class FantasyOres { public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "fantasyores"; public FantasyOres() { final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); EffectInit.EFFECTS.register(modEventBus); EffectInit.POTIONS.register(modEventBus); ItemInit.ITEMS.register(modEventBus); BlockInit.BLOCKS.register(modEventBus); BiomeInit.BIOMES.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public static void onRegisterItems(final RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); BlockInit.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(block -> { final Item.Properties properties = new Item.Properties().group(FantasyOres.TAB); final BlockItem blockItem = new BlockItem(block, properties); blockItem.setRegistryName(block.getRegistryName()); registry.register(blockItem); }); } @SubscribeEvent public static void onRegisterBiomes(final RegistryEvent.Register<Biome> event) { BiomeInit.registerBiomes(); } private void setup(final FMLCommonSetupEvent event) { CapabilityManager.INSTANCE.register(IArmorSet.class, new ArmorSetInstance.Storage(), ArmorSetInstance::new); } private void doClientStuff(final FMLClientSetupEvent event) { } @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { } @SubscribeEvent public static void LoadCompleteEVent(FMLLoadCompleteEvent event) { ModOreGen.GenerateOre(); } public static final ItemGroup TAB = new ItemGroup("fantasyores_tab") { @Override public ItemStack createIcon() { return new ItemStack(BlockInit.UMBRIUM_ORE.get()); } }; } IArmorSet interface public interface IArmorSet { int getCount(); void setCount(int amt); } ArmorSetInstance public class ArmorSetInstance implements IArmorSet { private int setCount = 0; @Override public int getCount() { FantasyOres.LOGGER.info("GetCountCapability: " + setCount); return setCount; } @Override public void setCount(int amt) { setCount = amt; FantasyOres.LOGGER.info("SetCountCapability: " + setCount);} public static class Storage implements Capability.IStorage<IArmorSet> { @Nullable @Override public INBT writeNBT(Capability<IArmorSet> capability, IArmorSet instance, Direction side) { return IntNBT.valueOf(instance.getCount()); } @Override public void readNBT(Capability<IArmorSet> capability, IArmorSet instance, Direction side, INBT nbt) { instance.setCount(((IntNBT) nbt).getInt()); } } } ArmorSetCapability public class ArmorSetCapability implements ICapabilitySerializable<IntNBT> { @CapabilityInject(IArmorSet.class) public static final Capability<IArmorSet> ARMOR_SET_CAPABILITY = null; private LazyOptional<IArmorSet> instance = LazyOptional.of(ARMOR_SET_CAPABILITY::getDefaultInstance); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return ARMOR_SET_CAPABILITY.orEmpty(cap, instance); } @Override public IntNBT serializeNBT() { return (IntNBT) ARMOR_SET_CAPABILITY.getStorage().writeNBT(ARMOR_SET_CAPABILITY, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null); } @Override public void deserializeNBT(IntNBT nbt) { ARMOR_SET_CAPABILITY.getStorage().readNBT(ARMOR_SET_CAPABILITY, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null, nbt); } } SetArmorItem @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class SetArmorItem extends ArmorItem { private static int setCount = 0; private static int tick = 0; private static String set; public SetArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder, String set) { super(materialIn, slot, builder); this.set = set; } public static void onEquipChange(LivingEquipmentChangeEvent e) { LivingEntity actor = e.getEntityLiving(); if(!actor.world.isRemote()) { if ( actor instanceof PlayerEntity ) { setCount = getItemsInSet(); //trimmed out the logic here to save space, //does nothing with capabilities and is known good code. //I just total the number of items equipped that belong to the set and store actor.getCapability(ArmorSetCapability.ARMOR_SET_CAPABILITY).ifPresent(cap -> cap.setCount(setCount)); } } } private void armorCount(int i) { setCount = i; FantasyOres.LOGGER.info(i); } //Just here for debugging, not needed @Override public void onArmorTick(ItemStack stack, World world, PlayerEntity player) { if (tick % 100 == 0) { //player.getCapability(ArmorSetCapability.ARMOR_SET_CAPABILITY).ifPresent(cap -> armorCount(cap.getCount())); } } CapabilitesEvent @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class CapabilitiesEvent { private static int tick = 0; @SubscribeEvent public static void addCapability(AttachCapabilitiesEvent<Entity> e) { if (e.getObject() instanceof PlayerEntity){ FantasyOres.LOGGER.info("addCapability fired for entity: " + e.getObject().getName()); e.addCapability(new ResourceLocation(FantasyOres.MOD_ID, "umbriumsetcount"), new ArmorSetCapability()); } } } I know its an error with the addCapability, but I cant tell what it is or how to correct it. I attempted to look at existing examples of code that implement custom capabilities, and that is partially what my code is based on, so it is possible I just missed a bit of code somewhere that is critical. And pointers would be helpful, thanks. crash-2020-05-19_17.14.16-server.txt
May 19, 20205 yr 50 minutes ago, kykaro said: FantasyOres.LOGGER.info("addCapability fired for entity: " + e.getObject().getName()); You have a null pointer on this line. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.