Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello everyone,

how can i implement a mana mechanic in the game?

I understood that I need capabilities to make the mana mechanic itself, I tried but seems that the current capabilities documentation is outdated, some voids, classes dont event exist in my directory.

I also need to make a "HUD" like the hearts with a custom texture. I managed to learn that I can do that in the event RenderGameOverlayEvent. I tried but i cannot understand how to print the texture in the overlay.

I've seen many tutorials but unfortunately, they are all outdated.

Thanks for reading.

- cinsiian

Edited by cinsiian

  • Replies 54
  • Views 17.1k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • Animefan8888
    Animefan8888

    I think Gui#blit expects the texture to be 256x256

  • Animefan8888
    Animefan8888

    Use PlayerEntity#areEyesInFluid(FluidTags.WATER)

  • you can get the player from the context Supplier<NetworkEvent.Context> ctx https://github.com/MinecraftForge/MinecraftForge/blob/1.14.x/src/main/java/net/minecraftforge/fml/network/Networ

27 minutes ago, cinsiian said:

but seems that the current capabilities documentation is outdated

They haven't changed. As in, they don't need to change. The documentation remains accurate despite Minecraft having updated because Capabilities are a Forge feature and simply moved forward. There might be some tiny differences here and there where a function name gets changed, but its all stuff easily resolvable just by looking at the classes involved.

29 minutes ago, cinsiian said:

I managed to learn that I can do that in the event RenderGameOverlayEvent. I tried but i cannot understand how to print the texture in the overlay.

The event hook hasn't really changed, you just need to find the new method name for rendering a texture on screen. You can figure this out by looking at other classes that render textures on screen.

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.

  • Author

My problem right now is the capability, I've wrote the majoriti of the classes/interfaces needed. I dont know if they will work, hopefully. 

Right now I have some issues related to the capability factory.

Are there any references/examples of capabilities? 

Thank you.

I've got one from 1.12:

https://github.com/Draco18s/ReasonableRealism/tree/1.12.1/src/main/java/com/draco18s/farming/entities/capabilities

I haven't migrated that code to 1.14 yet, but it should be 99% functional.

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.

  • Author

I do get an error when I try to get the Capability of the mana:

[11set2019 21:20:03.439] [Server thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: Exception caught during firing event: cinsiian.urtima.common.capability.mana.PlayerMana cannot be cast to net.minecraftforge.common.util.LazyOptional
	Index: 2
	Listeners:
		0: NORMAL
		1: net.minecraftforge.eventbus.EventBus$$Lambda$2050/614462502@67307e64
		2: ASM: cinsiian.urtima.common.CommonHandler@4023efd4 onPlayerLogsIn(Lnet/minecraftforge/event/entity/player/PlayerEvent$PlayerLoggedInEvent;)V
java.lang.ClassCastException: cinsiian.urtima.common.capability.mana.PlayerMana cannot be cast to net.minecraftforge.common.util.LazyOptional
	at cinsiian.urtima.common.capability.mana.ManaProvider.getCapability(ManaProvider.java:20)
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.getCapability(CapabilityDispatcher.java:102)
	at net.minecraftforge.common.capabilities.CapabilityProvider.getCapability(CapabilityProvider.java:118)
	at net.minecraft.entity.LivingEntity.getCapability(LivingEntity.java:3110)
	at net.minecraft.entity.player.PlayerEntity.getCapability(PlayerEntity.java:2277)
	at cinsiian.urtima.common.CommonHandler.onPlayerLogsIn(CommonHandler.java:89)
	at net.minecraftforge.eventbus.ASMEventHandler_7_CommonHandler_onPlayerLogsIn_PlayerLoggedInEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:43)
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:203)
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:119)
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:63)
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:241)
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:882)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646)
	at java.lang.Thread.run(Unknown Source)
IMana mana = (IMana) player.getCapability(ManaProvider.MANA, null);

 

10 minutes ago, cinsiian said:

I do get an error when I try to get the Capability of the mana:


[11set2019 21:20:03.439] [Server thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]: Exception caught during firing event: cinsiian.urtima.common.capability.mana.PlayerMana cannot be cast to net.minecraftforge.common.util.LazyOptional
	Index: 2
	Listeners:
		0: NORMAL
		1: net.minecraftforge.eventbus.EventBus$$Lambda$2050/614462502@67307e64
		2: ASM: cinsiian.urtima.common.CommonHandler@4023efd4 onPlayerLogsIn(Lnet/minecraftforge/event/entity/player/PlayerEvent$PlayerLoggedInEvent;)V
java.lang.ClassCastException: cinsiian.urtima.common.capability.mana.PlayerMana cannot be cast to net.minecraftforge.common.util.LazyOptional
	at cinsiian.urtima.common.capability.mana.ManaProvider.getCapability(ManaProvider.java:20)
	at net.minecraftforge.common.capabilities.CapabilityDispatcher.getCapability(CapabilityDispatcher.java:102)
	at net.minecraftforge.common.capabilities.CapabilityProvider.getCapability(CapabilityProvider.java:118)
	at net.minecraft.entity.LivingEntity.getCapability(LivingEntity.java:3110)
	at net.minecraft.entity.player.PlayerEntity.getCapability(PlayerEntity.java:2277)
	at cinsiian.urtima.common.CommonHandler.onPlayerLogsIn(CommonHandler.java:89)
	at net.minecraftforge.eventbus.ASMEventHandler_7_CommonHandler_onPlayerLogsIn_PlayerLoggedInEvent.invoke(.dynamic)
	at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:43)
	at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:203)
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:119)
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:63)
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:241)
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:882)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:800)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:646)
	at java.lang.Thread.run(Unknown Source)

IMana mana = (IMana) player.getCapability(ManaProvider.MANA, null);

 

show more of your code and dont cast to IMana

  • Author
15 minutes ago, diesieben07 said:

Look at LazyOptional and use it properly.

Should I use LazyOptional.cast(); ?

 

14 minutes ago, eatthenight said:

dont cast to IMana

I need it.

1 minute ago, cinsiian said:

Should I use LazyOptional.cast(); ?

No. Does it return an IMana object?

Edited by Draco18s

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.

2 minutes ago, cinsiian said:

Should I use LazyOptional.cast(); ?

You might not understand how a LazyOptional works take a look at this thread.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
IMana mana = player.getCapability(ManaProvider.MANA, null).orElse(null);

Can that work?

  • Author

Ok, I did it but now I get another crash:

[11set2019 23:15:16.716] [modloading-worker-2/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: null
	Index: 1
	Listeners:
		0: NORMAL
		1: net.minecraftforge.eventbus.EventBus$$Lambda$2061/559879182@34f88844
java.lang.ExceptionInInitializerError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at net.minecraftforge.common.capabilities.CapabilityManager.lambda$attachCapabilityToMethod$5(CapabilityManager.java:145)
	at net.minecraftforge.common.capabilities.CapabilityManager.lambda$register$0(CapabilityManager.java:79)
	at java.util.ArrayList.forEach(Unknown Source)
	at net.minecraftforge.common.capabilities.CapabilityManager.register(CapabilityManager.java:79)
	at cinsiian.urtima.Urtima.setup(Urtima.java:44)
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212)
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
	at java.util.function.Consumer.lambda$andThen$0(Unknown Source)
	at java.util.function.Consumer.lambda$andThen$0(Unknown Source)
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112)
	at net.minecraftforge.fml.ModList.lambda$null$10(ModList.java:133)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(Unknown Source)
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.util.stream.ForEachOps$ForEachTask.compute(Unknown Source)
	at java.util.concurrent.CountedCompleter.exec(Unknown Source)
	at java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
	at java.util.concurrent.ForkJoinTask.doInvoke(Unknown Source)
	at java.util.concurrent.ForkJoinTask.invoke(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(Unknown Source)
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.util.stream.ReferencePipeline.forEach(Unknown Source)
	at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source)
	at net.minecraftforge.fml.ModList.lambda$dispatchParallelEvent$11(ModList.java:133)
	at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(Unknown Source)
	at java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)
	at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
	at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at cinsiian.urtima.common.capability.mana.ManaProvider.<clinit>(ManaProvider.java:14)
	... 34 more

Tell me if you need github for this.

ManaProvider.java:14 -- public static IMana INSTANCE = MANA.getDefaultInstance();

Urtima.java:44 -- CapabilityManager.INSTANCE.register(IMana.class, new ManaNBTStorage(), new ManaNBTStorage.Factory());

Edited by cinsiian

2 minutes ago, cinsiian said:

It's the ManaProvider class: https://github.com/cinsiian/mod

Your IMana instance in your provider can't be static if you are gonna use MANA.getDefaultInstance().
 

Quote

return (LazyOptional<T>) INSTANCE;

You can't do this either don't know if I'm looking at outdated code or not.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
11 minutes ago, Animefan8888 said:
Quote

return (LazyOptional<T>) INSTANCE;

You can't do this either don't know if I'm looking at outdated code or not.

Isn't that the thing I should return?

Just now, cinsiian said:

Isn't that the thing I should return?

LazyOptional is the type that you need to return yes. But is IMana a LazyOptional instance? No therefore you can't cast it into a LazyOptional. You need to have a LazyOptional instance in your ICapabilityProvider.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
31 minutes ago, Animefan8888 said:

LazyOptional is the type that you need to return yes. But is IMana a LazyOptional instance? No therefore you can't cast it into a LazyOptional. You need to have a LazyOptional instance in your ICapabilityProvider.

What LazyOptional ?? like the default one this.getCompatibility() ?

1 hour ago, cinsiian said:

What LazyOptional ?? like the default one this.getCompatibility() ?

LazyOptional is the Type that getCapability() returns. Whatever it is that you want to return, it must be a LazyOptional. Whatever type it is that you get from getCapability, it must be a LazyOptional. In order to handle turning something into a LazyOptional or vice versa, you can't do it with a cast, because that's not what casting does.

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.

58 minutes ago, cinsiian said:

to return in the getCapability() can i just make a new LazyOptional?

You can but you should not. For a variety of reasons.

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.

  • Author
6 minutes ago, diesieben07 said:

You need to create a LazyOptional

How can I create one?

  • Author
@CapabilityInject(IMana.class)
	public static final Capability<IMana> MANA = null;
	public IMana INSTANCE = MANA.getDefaultInstance();
	
	@SuppressWarnings("unchecked")
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		return (LazyOptional<T>) INSTANCE;
	}

How can I return an actual instance of LazyOptional?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.