Jump to content

[1.12] "Mana" Capability


The_SlayerMC

Recommended Posts

So my mod has a mana type of use called "Essence"

Whats happening is its nulling out when getting the value somewhere and i cant for the life of me figure it out

 

I know where it nulls out and i dont see why when its just trying the get the value of the mana bar

 

	[22:35:48] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Player665 joined the game
[22:35:48] [Server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.fml.common.gameevent.TickEvent$PlayerTickEvent@2eed9875:
java.lang.NullPointerException: null
    at net.journey.client.BarTickHandler.tickEnd(BarTickHandler.java:79) ~[BarTickHandler.class:?]
    at net.journey.client.BarTickHandler.onTick(BarTickHandler.java:30) ~[BarTickHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_27_BarTickHandler_onTick_PlayerTickEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?]
    at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPostTick(FMLCommonHandler.java:369) [FMLCommonHandler.class:?]
    at net.minecraft.entity.player.EntityPlayer.updateSize(EntityPlayer.java:416) [EntityPlayer.class:?]
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:326) [EntityPlayer.class:?]
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423) [EntityPlayerMP.class:?]
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185) [NetHandlerPlayServer.class:?]
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212) [NetworkDispatcher$1.class:?]
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307) [NetworkManager.class:?]
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197) [NetworkSystem.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
[22:35:48] [Server thread/ERROR] [FML]: Index: 3 Listeners:
[22:35:48] [Server thread/ERROR] [FML]: 0: NORMAL
[22:35:48] [Server thread/ERROR] [FML]: 1: ASM: net.journey.event.ArmorAbilityEvent@2d980ff2 playerTick(Lnet/minecraftforge/fml/common/gameevent/TickEvent$PlayerTickEvent;)V
[22:35:48] [Server thread/ERROR] [FML]: 2: ASM: net.journey.event.PlayerEvent@14f13587 onTick(Lnet/minecraftforge/fml/common/gameevent/TickEvent$PlayerTickEvent;)V
[22:35:48] [Server thread/ERROR] [FML]: 3: ASM: net.journey.client.BarTickHandler@45c95343 onTick(Lnet/minecraftforge/fml/common/gameevent/TickEvent$PlayerTickEvent;)V
[22:35:49] [Server thread/ERROR] [FML]: 4: ASM: net.journey.event.PlayerEvent@290df0bf onTick(Lnet/minecraftforge/fml/common/gameevent/TickEvent$PlayerTickEvent;)V
[22:35:49] [Server thread/ERROR] [FML]: 5: ASM: net.journey.event.ClientTickEvent@7a843a7a clientTickEvent(Lnet/minecraftforge/fml/common/gameevent/TickEvent$PlayerTickEvent;)V
[22:35:49] [Server thread/ERROR] [net.minecraft.server.MinecraftServer]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:212) ~[NetworkSystem.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865) ~[MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) ~[MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) ~[IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
Caused by: java.lang.NullPointerException
    at net.journey.client.BarTickHandler.tickEnd(BarTickHandler.java:79) ~[BarTickHandler.class:?]
    at net.journey.client.BarTickHandler.onTick(BarTickHandler.java:30) ~[BarTickHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_27_BarTickHandler_onTick_PlayerTickEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) ~[EventBus.class:?]
    at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPostTick(FMLCommonHandler.java:369) ~[FMLCommonHandler.class:?]
    at net.minecraft.entity.player.EntityPlayer.updateSize(EntityPlayer.java:416) ~[EntityPlayer.class:?]
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:326) ~[EntityPlayer.class:?]
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423) ~[EntityPlayerMP.class:?]
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185) ~[NetHandlerPlayServer.class:?]
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212) ~[NetworkDispatcher$1.class:?]
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307) ~[NetworkManager.class:?]
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197) ~[NetworkSystem.class:?]
    ... 5 more
[22:35:49] [Server thread/ERROR] [net.minecraft.server.MinecraftServer]: This crash report has been saved to: D:\Development\Minecraft\Forge\1.12\.\crash-reports\crash-2018-07-31_22.35.49-server.txt
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Stopping server
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving players
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving worlds
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/overworld
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Boiling Point
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Depths
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Euca
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Senterian
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Golden Grains
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Terrania
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Cloudia
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Corba
[22:35:49] [Server thread/INFO] [net.minecraft.server.MinecraftServer]: Saving chunks for level 'New World'/Frozen
[22:35:50] [main/INFO] [STDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:629]: ---- Minecraft Crash Report ----
// I just don't know what went wrong :(
	Time: 7/31/18 10:35 PM
Description: Ticking player
	java.lang.NullPointerException: Ticking player
    at net.journey.client.BarTickHandler.tickEnd(BarTickHandler.java:79)
    at net.journey.client.BarTickHandler.onTick(BarTickHandler.java:30)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_27_BarTickHandler_onTick_PlayerTickEvent.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
    at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPostTick(FMLCommonHandler.java:369)
    at net.minecraft.entity.player.EntityPlayer.updateSize(EntityPlayer.java:416)
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:326)
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Unknown Source)
	
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
	-- Head --
Thread: Client thread
Stacktrace:
    at net.journey.client.BarTickHandler.tickEnd(BarTickHandler.java:79)
    at net.journey.client.BarTickHandler.onTick(BarTickHandler.java:30)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_27_BarTickHandler_onTick_PlayerTickEvent.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
    at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPostTick(FMLCommonHandler.java:369)
    at net.minecraft.entity.player.EntityPlayer.updateSize(EntityPlayer.java:416)
    at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:326)
	-- Player being ticked --
Details:
    Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
    Entity ID: 206
    Entity Name: Player665
    Entity's Exact location: 203.50, 69.00, 250.50
    Entity's Block location: World: (203,69,250), Chunk: (at 11,4,10 in 12,15; contains blocks 192,0,240 to 207,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
    Entity's Momentum: 0.00, -0.08, 0.00
    Entity's Passengers: []
    Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
    at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
    at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
    at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
    at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)
	-- Ticking connection --
Details:
    Connection: net.minecraft.network.NetworkManager@2b9ac5e
Stacktrace:
    at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:865)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Unknown Source)
	

 

	public interface IEssence {
	    public boolean useEssence(int points);
    public void addEssence(int points);
    public void setEssence(int essence);
    public int getEssenceValue();
    public void update();
    public void regen();
}
	

 

	public class EssenceBar implements IEssence {
	    private int essenceValue = 10;
    
    @Override
    public boolean useEssence(int points) {
        if(essenceValue < points) 
            return false;
        essenceValue -= points;
        return true;
    }
	    @Override
    public void addEssence(int points) {
        essenceValue += points;
        if(essenceValue > 10) essenceValue = 10;
    }
	    @Override
    public void setEssence(int essence) {
        essenceValue = essence;
    }
	    @Override
    public int getEssenceValue() {
        return essenceValue;
    }
	    @Override
    public void update() {
        if(essenceValue > 10) essenceValue = 10;        
    }
    
    @Override
    public void regen() {
        essenceValue += 1;
    }
}
	

 

	public class EssenceProvider implements ICapabilitySerializable<NBTBase> {
	    @CapabilityInject(IEssence.class)
    public static final Capability<IEssence> ESSENCE_CAP = null;
    
    private IEssence INSTANCE = ESSENCE_CAP.getDefaultInstance();
    
    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
        return capability == ESSENCE_CAP;
    }
	    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
        return capability == ESSENCE_CAP ? ESSENCE_CAP.<T>cast(this.INSTANCE) : null;
    }
	    @Override
    public NBTBase serializeNBT() {
        return ESSENCE_CAP.getStorage().writeNBT(ESSENCE_CAP, INSTANCE, null);
    }
	    @Override
    public void deserializeNBT(NBTBase nbt) {
        ESSENCE_CAP.getStorage().readNBT(ESSENCE_CAP, INSTANCE, null, nbt);
    }
	}
	

 

	public class EssenceStorage implements IStorage<IEssence> {
	    @Override
    public NBTBase writeNBT(Capability<IEssence> capability, IEssence instance, EnumFacing side) {
        return new NBTTagInt(instance.getEssenceValue());
    }
	    @Override
    public void readNBT(Capability<IEssence> capability, IEssence instance, EnumFacing side, NBTBase nbt) {
        instance.setEssence(((NBTTagInt)nbt).getInt());
    }
}
	

 

	COMMON PROXY PRE INIT:
	 
	MinecraftForge.EVENT_BUS.register(JourneyCapabilityHandler.class);
        CapabilityManager.INSTANCE.register(IEssence.class, new EssenceStorage(), EssenceBar.class);
        SlayerAPI.registerEvent(new BarTickHandler());
	

 

	BAR RENDERING CODE
	public class BarTickHandler {
    
    private int ticks = 10;
	    @SubscribeEvent
    public void onTick(PlayerTickEvent event) {
        if(event.phase == Phase.END) tickEnd(event.player);
    }
    
    @SideOnly(Side.CLIENT)
    @SubscribeEvent
    public void renderEvent(RenderTickEvent event) {
        onTickRender(Minecraft.getMinecraft().player);
    }
	    @SideOnly(Side.CLIENT)
    private void onTickRender(EntityPlayer player) {
        Minecraft mc = Minecraft.getMinecraft();
        if(mc.currentScreen == null) {
            if(!player.capabilities.isCreativeMode) {
                IEssence mana = player.getCapability(EssenceProvider.ESSENCE_CAP, null);
                GL11.glPushMatrix();
                GlStateManager.enableBlend();
                GlStateManager.enableAlpha();
                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
                GuiIngame gig = mc.ingameGUI;
                ScaledResolution scaledresolution = new ScaledResolution(mc);
                mc.getTextureManager().bindTexture(new ResourceLocation(SlayerAPI.MOD_ID, "textures/gui/misc.png"));
                //int sw = scaledresolution.getScaledWidth(), sh = scaledresolution.getScaledHeight();
                int y = scaledresolution.getScaledHeight() - 30, x = 10, x1 = 10, x2 = 10;
                gig.drawTexturedModalRect(x - 10, y + 10, 0, 177, 117, 19);
                gig.drawTexturedModalRect(x - 10, y - 5, 0, 177, 117, 19);
                gig.drawTexturedModalRect(x - 10, y - 20, 0, 177, 117, 19);
	                gig.drawTexturedModalRect(x - 6, y - 13, 0, 23, 109, 5);
                for(int i = 0; i < mana.getEssenceValue(); i++) {
                    if(!(i >= 10)) {
                        x += 11;
                        gig.drawTexturedModalRect(x - 17, y - 13, 0, 0, 10, 5);
                    }
                }
                GlStateManager.disableAlpha();
                GlStateManager.disableBlend();
                GL11.glPopMatrix();
            }
        }
    }
	    private void tickEnd(EntityPlayer player) {
        IEssence mana = player.getCapability(EssenceProvider.ESSENCE_CAP, null);
        if(ticks-- <= 0) ticks = 10;
        
        if(ticks >= 10) 
            mana.regen(); // THIS ONE IS NULLING OUT
        
        mana.update();
    }
}
	

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Link to comment
Share on other sites

The mana capability is null. 

Your code is full of issues that you must fix:

  • You are reaching across logical sides in a lot of places like here(PlayerTickEvent is common, Minecraft is client only).
  • Why is this class named ClientTickEvent? There is nothing client about it, it's common code. Also it is probably a bad idea to create a new Random object twice each tick per player.
  • You are using numerical IDs which is a really bad idea since they can and will unpredictably change.
  • Forge already has a built-in update checker. This is just extra work you don't have to do. It also does the check on the main thread which means that if the page is unavailable for some reason or takes a really long time to respond the client will stall potentially forever(or at least untill the timeout happens).
  • Why is this in your client package? Presumably the mana regeneration is server-only or at the very least common code, is it not?
  • You are using GL11 directly and by doing that corrupting the state of the GlStateManager. You must use GlStateManager, not GL11.
  • As far as I know RenderTickEvent is fired every frame regardless of whether there is a player or not. You must be checking for the player in your event handler. The only reason it doesn't crash now is because of this line and that is not the propper check. If some mod nullifies the currentScreen before the world is started your code will crash.
  • Why on earth are you only adding your capability on the client? This is the root cause of your problem. Presumably you need this capability on the server aswell yes? Otherwise it serves no purpose. Or are you going to send packets based on trusting the client?
  • Oh it is also worth pointing out that currently every entity in the game apart from the only one that needs it has your mana capability. I don't think that this is whay you wanted.
  • Especially considering that right in the same file on the next few lines you are copying the capability disregarding whether it's the client asking you to clone it or the server.
  • Code-style issues #1 and #3

And those are just the issues I found at a quick glance at the repo. I'm sure there are many more.

 

Link to comment
Share on other sites

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Link to comment
Share on other sites

  • What is this package? What does it even mean?
  • Why are you now registering your capabilities in init? Capabilities should be available as soon as possible, not delayed untill init.
  • You are still using direct calls to GL11.
  • The more players on the server the faster this will tick down and thereby the faster the mana will regen... for one player out of them all. Store this value in the capability.
  • Why did you just straight up delete your clone event? You need that to persist capability data.

Apart from that your capability registration seems correct. Does the issue still persist?

Link to comment
Share on other sites

9 hours ago, V0idWa1k3r said:
  • What is this package? What does it even mean?
  • Why are you now registering your capabilities in init? Capabilities should be available as soon as possible, not delayed untill init.
  • You are still using direct calls to GL11.
  • The more players on the server the faster this will tick down and thereby the faster the mana will regen... for one player out of them all. Store this value in the capability.
  • Why did you just straight up delete your clone event? You need that to persist capability data.

Apart from that your capability registration seems correct. Does the issue still persist?

Yes the issue still happens

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

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.

Announcements



×
×
  • Create New...

Important Information

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