Jump to content

Recommended Posts

Posted

I am trying to implement Mana.
If I can add it to the Player after creating the Manadata, I think I can create it
Is there a way to solve this or a class I can refer to?

Posted (edited)

I have read the documentation and run the example once, but attach is not executed.

When the subscribed Entity is called, attach is called, and then MyCapabilityImplementation is called. fill in the code in the place corresponding to MyCapabilityImplementation.
This is how I understand it, am I wrong

And I'm not sure what the need for the ResourceLocation string is.
It says there are no restrictions, so does that mean it is an ID for identification purposes?

Main

    public void registerCapabilities(RegisterCapabilitiesEvent event)
    {
        MyCapability.register(event);

    }

 

 

The problem with not running has been resolved.
I had misinterpreted it.

MinecraftForge.EVENT_BUS.register(MyCapabilityAttacher.class);

So the only thing I'm concerned about is the correctness of future development procedures.

 

Edited by ocome
Posted
  On 1/28/2022 at 11:53 PM, ocome said:

When the subscribed Entity is called, attach is called, and then MyCapabilityImplementation is called. fill in the code in the place corresponding to MyCapabilityImplementation.

Expand  

in AttachCapabilitiesEvent you need a ICapabilityProvider which holds your Capability

  • Like 1
Posted

uhh...
Mycapabilityattacher has MyCapabilityProvider and implements ICapabilityProvide, which I thought was sufficient, but I guess not.
I'll check again.
 

public class MyCapabilityAttacher {
	private static class MyCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> {

        public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial");

        private final MyCapabilityInterface backend = new MyCapabilityImplementation();
        private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend);

        @NotNull
        @Override
        public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
            return MyCapability.INSTANCE.orEmpty(cap, this.optionalData);
        }

        void invalidate() {
            this.optionalData.invalidate();
        }

        @Override
        public CompoundTag serializeNBT() {
            return this.backend.serializeNBT();
        }

        @Override
        public void deserializeNBT(CompoundTag nbt) {
            this.backend.deserializeNBT(nbt);
        }
    }
...
Posted (edited)
  Quote

Why not?

Expand  

 

Oh, I think my English is wrong again.

Mx Luis taught me what I needed to know?

I think it is enough. 

sorry. I'll study English.

 

Back to the topic at hand, after writing the code to implement the mana.
 If you change it to only call it if the Entity is a player, I think it will work

Thank you, all of you. I'll try.

Edited by ocome
Posted

I'm trying to add some functionality to the Player.

    private static class MyCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> {

        public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial");
        Level level = Minecraft.getInstance().level;

        private final MyCapabilityInterface backend = new MyCapabilityImplementation(level,BlockPos.ZERO,0,new GameProfile(null,null));
      
      
        private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend);

        @NotNull
          .........

Is this how the call should be made?

public class MyCapabilityImplementation extends Player implements MyCapabilityInterface {

    private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt";

    private String Value = "";

    public MyCapabilityImplementation(Level p_36114_, BlockPos p_36115_, float p_36116_, GameProfile p_36117_) {
        super(p_36114_, p_36115_, p_36116_, p_36117_);
    }

    @Override
    public String getValue() {
        return this.Value;
    }
  .......

    @Override
    public void setValue(String Value) {
        this.Value = Value;
    }

And fill in the code to be added from here?

I wonder how to get a gameplofile...

Posted
  On 1/30/2022 at 8:40 AM, ocome said:

I'm trying to add some functionality to the Player.

Expand  

the first way is the correct one, just create a constructor with the required parameters (so in your case with the player),
when you attach the CapabilityProvider to the player, you need to pass in the player as parameter

btw you can get the Level from the Player (also note there are more than 1 Level),
the GameProfile is bind so you can also get it from the Player

Posted (edited)

I appreciate again .

  On 1/30/2022 at 11:21 AM, Luis_ST said:

when you attach the CapabilityProvider to the player, you need to pass in the player as parameter

Expand  
    @SubscribeEvent
    public static void onAttachingCapabilities(final AttachCapabilitiesEvent<Entity> event) {
        final MyCapabilityProvider provider = new MyCapabilityProvider();
       String string =  event.getObject().getType().toShortString();
    if (string == "player") {
        event.addCapability(MyCapabilityProvider.IDENTIFIER, provider);
    }

    }

I filled it out like this from the answer, but it doesn't seem to work

 

I tried to check it after getting the player element from AttachCapabilitiesEvent<Entity>.
Am I wrong?

    public static void onAttachingCapabilities(final AttachCapabilitiesEvent<Player> event) {
        final MyCapabilityProvider provider = new MyCapabilityProvider();

Reading the documentation, you can't do this, right?

 

  On 1/30/2022 at 11:21 AM, Luis_ST said:

btw you can get the Level from the Player (also note there are more than 1 Level),
the GameProfile is bind so you can also get it from the Player

Expand  

Oh, sure, I checked the Player and it's there. So does that mean I can use AT to get it
Thank you very much.

Edited by ocome
Posted
  On 1/31/2022 at 3:30 AM, ocome said:

I filled it out like this from the answer, but it doesn't seem to work

Expand  

AttachCapabilitiesEvent#grtObject retunrns in your case a Entity so why did you not use a instanceof check 

  On 1/30/2022 at 11:21 AM, Luis_ST said:

just create a constructor with the required parameters (so in your case with the player)

Expand  

you haven't done this

  On 1/31/2022 at 3:30 AM, ocome said:

Oh, sure, I checked the Player and it's there. So does that mean I can use AT to get it

Expand  

There is Player#getCommandSenderWorld, you don't need a AT

Posted
  On 1/31/2022 at 5:40 AM, Luis_ST said:

AttachCapabilitiesEvent#grtObject retunrns in your case a Entity so why did you not use a instanceof check 

Expand  
    @SubscribeEvent
    public static void onAttachingCapabilities(final AttachCapabilitiesEvent<Entity> event) {
        final MyCapabilityProvider provider = new MyCapabilityProvider();

       boolean iof =  event.getObject()  instanceof Player;
       if (iof ==true) {
           event.addCapability(MyCapabilityProvider.IDENTIFIER, provider);
       }


    }

We have implemented it this way.
I think works fine in  tests.

  On 1/31/2022 at 5:40 AM, Luis_ST said:

you haven't done this

Expand  

 MyCapabilityProvider

    private static class MyCapabilityProvider implements ICapabilityProvider, INBTSerializable<CompoundTag> {

        public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial");


        public Player player ;
        public Level level = player.getCommandSenderWorld();
        public BlockPos blockPos = player.blockPosition();
        public GameProfile gameProfile =player.getGameProfile();


        private final MyCapabilityInterface backend = new MyCapabilityImplementation(level,blockPos,0.0F, gameProfile);
      

MyCapabilityImplementation

public class MyCapabilityImplementation extends Player implements MyCapabilityInterface {
    protected ManaData manaData = new ManaData();
    private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt";

    private String Value = "";

    public MyCapabilityImplementation(Level p_36114_, BlockPos p_36115_, float p_36116_, GameProfile p_36117_) {
        super(p_36114_, p_36115_, p_36116_, p_36117_);
    }

I think I understand what I can get.

But I don't know where to get the Player itself.

 

Posted (edited)
public class MyCapabilityAttacher {
  private class MyCapabilityProviderEntity implements ICapabilityProvider, INBTSerializable<CompoundTag> {
          public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial");
          private final MyCapabilityInterface backend = new MyCapabilityImplementation();
          private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend);

public class MyCapabilityImplementation  implements MyCapabilityInterface {
    protected ManaData manaData = new ManaData();
    private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt";
    public Level level;
    private String Value = "";

    public static ManaData getManaData() {
        return new ManaData();
    }

    @Override
    public void tick() {
        if (!this.level.isClientSide) {
            this.manaData.tick(this);
        }
    }

ManaOverlay

    public static final ManaOverlay INSTANCE = new ManaOverlay(Minecraft.getInstance());

    public ManaOverlay(Minecraft p_93005_) {
        super(p_93005_);

        this.mc = Minecraft.getInstance();
        this.font = mc.font;
        OverlayRegistry.registerOverlayTop("Mana ", (gui, mStack, partialTicks, screenWidth, screenHeight) -> {
            boolean isMounted = gui.minecraft.player.getVehicle() instanceof LivingEntity;
            if (!isMounted && !gui.minecraft.options.hideGui && gui.shouldDrawSurvivalElements())
            {
                setupOverlayRenderState(true, false);
                renderMana(screenWidth, screenHeight, mStack);
            }
        });
    }

    public static void init()
    {
        MinecraftForge.EVENT_BUS.register(INSTANCE);
    }

    public void renderMana(int width, int height, PoseStack mStack)
    {
        minecraft.getProfiler().push("mana");

        Player player = (Player)this.minecraft.getCameraEntity();
        RenderSystem.enableBlend();
        int left = width / 2 + 91;
        int top = height - right_height ;

        boolean unused = false;

        ManaData stats = MyCapabilityImplementation.getManaData();
        int level = stats.getManaLevel();

        for (int i = 0; i < 10; ++i)
        {
            int idx = i * 2 + 1;
            int x = left - i * 8 - 9;
            int y = top;
            int icon = 16;
            byte background = 0;

            if (minecraft.player.hasEffect(MobEffects.HUNGER))
            {
                icon += 36;
                background = 13;
            }
            if (unused) background = 1; //Probably should be a += 1 but vanilla never uses this
            blit(mStack, x, y, 16 + background * 9, 27, 9, 9);

            if (idx < level)
                blit(mStack, x, y, icon + 9, 27, 9, 9);
            else if (idx == level)
                blit(mStack, x, y, icon + 18, 27, 9, 9);
        }
        RenderSystem.disableBlend();
        minecraft.getProfiler().pop();
    }

I created it this way, but there is no change in the overlay.

I think the tick is not being called, but before that, I can't seem to fix the static mismatch between Capability and overlay.
Is there a way to fix this?

 

 

No, something wrong with the way I make the overlay side ?
I'll look at it some more.

Edited by ocome
Fill in the middle of the process
Posted (edited)
        LazyOptional<MyCapabilityInterface> stats = minecraft.player.getCapability(MyCapability.INSTANCE);
        int level = ManaData.getManaLevel();

Is this what it looks like?
To be honest, I don't really understand it.

 

 

I feel like I don't have enough skills yet.
I'm still going to continue creating it, but I'm thinking I should understand it a little better before I start working on it.

Edited by ocome
Posted
  On 2/1/2022 at 2:46 PM, ocome said:
LazyOptional<MyCapabilityInterface> stats = minecraft.player.getCapability(MyCapability.INSTANCE);
Expand  

yeah that's correct if your Capability is client side only, but at the moment you never use the Capability

Posted
  On 2/1/2022 at 6:38 PM, Luis_ST said:

yeah that's correct if your Capability is client side only, but at the moment you never use the Capability

Expand  

Yes, I understand that.
But I don't know how to utilize this.
Do I have to get the values related to Manadata from stats?

Posted (edited)
        FoodData statsas = minecraft.player.getFoodData();
        ManaData statsa1s = MyCapabilityImplementation.getManaData();
        int level =statsas.getFoodLevel();

By the way, if this is a java thing, I hope you don't mind, but why do I get a static context error with getManaData while no error occurs with getFoodData?

This error requires a lot of time and effort to fix.

 

Or is there no need to write this kind of code in the first place?

--> This problem was solved by my mistake.

 

Edited by ocome
Posted

Attach

public class MyCapabilityAttacher {


    public class MyCapabilityProviderEntity implements ICapabilityProvider, INBTSerializable<CompoundTag> {
        public static final ResourceLocation IDENTIFIER = new ResourceLocation(ExampleMod.MOD_ID, "tutorial");
        private final MyCapabilityInterface backend = new MyCapabilityImplementation() ;
        private final LazyOptional<MyCapabilityInterface> optionalData = LazyOptional.of(() -> backend);

        @NotNull
        @Override
        public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
            return MyCapability.INSTANCE.orEmpty(cap, this.optionalData);
        }

        void invalidate() {
            this.optionalData.invalidate();
        }

        @Override
        public CompoundTag serializeNBT() {
            return this.backend.serializeNBT();
        }

        @Override
        public void deserializeNBT(CompoundTag nbt) {
            this.backend.deserializeNBT(nbt);
        }
    }

    @SubscribeEvent
    public void  onAttachingCapabilitiesEntity(final AttachCapabilitiesEvent<Entity> event) {
        final MyCapabilityProviderEntity provider = new MyCapabilityProviderEntity();

       boolean iof =  event.getObject()  instanceof Player;
       if (iof ==true) {
           Player eventObject = (Player) event.getObject();
           event.addCapability(MyCapabilityProviderEntity.IDENTIFIER, provider);
           new MyCapabilityImplementation().tick(eventObject);
       }
    }

    public MyCapabilityAttacher() {
    }
}

Implementation


public  class MyCapabilityImplementation implements MyCapabilityInterface {
    protected   ManaData manaData = new ManaData();
    private static final String NBT_KEY_DAMAGE_DEALT = "damageDealt";

    public Level level;
    private String Value = "";

     public ManaData getManaData() {
        return this.manaData;
    }

    @Override
    public MyCapabilityInterface tick(Player player) {
           this.manaData.tick(player);
        return null;
    }
  .....

I think it is close to completion.
I thought I needed a tick, so I implemented it, but it comes up as an invalid player.
Is there a way to fix this?

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




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • ⚠️ DON'T CLICK THIS LINK OR ANYTHING RELATED TO THIS, IT HAS MALWARE IN THE LINK AND IT'S LIKELY A SCAM. ⚠️
    • ⚠️ DON'T CLICK THIS LINK OR ANYTHING RELATED TO THIS, IT HAS MALWARE IN THE LINK AND IT'S LIKELY A SCAM. ⚠️
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Whats...App : +.1 .4 7.4.3 5.3.7 7..1.9 Website : https://       digitalhackrecovery.com     Mail:            digitalhackrecovery         @techie.       com 
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Wh.ats.Ap.p : +1 .4 .7  4 3. 5  3  .7 7.1.9 Website : https://     digitalhackrecovery.   com Mail:       digitalhackrecovery     @         techie.                     com  
    • Ran it one more time just to check, and there's no errors this time on the log??? Log : https://mclo.gs/LnuaAiu I tried allocating more memory to the modpack, around 8000MB and it's still the same; stopping at "LOAD_REGISTRIES". Are some of the mods clashing, maybe? I have no clue what to do LOL
  • Topics

×
×
  • Create New...

Important Information

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