Jump to content

[SOLVED] Mana game mechanic in 1.14.4 help


cinsiian

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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() ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

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