Jump to content

Capability Issues


sarkozi

Recommended Posts

I'm new to Forge and am trying to figure out how to block player access to a particular inventory slot. I know that with inventory stuff I'm supposed to use capabilities as much as I possibly can, but I'm still struggling to wrap my head around it. The way I approached this at first was to create a custom Slot class and use player.container.inventorySlots.set() to insert it into my desired spot. From there I overrode the slot's canTakeStack() method to make it always return false. It sort of works but exhibits a lot of the syncing issues that make me think I should've implemented it using handlers and capabilities. I'm trying to wrap my head around how I would do that properly but I think I need someone to point me in the right direction. I think if I can override PlayerContainer.slotClick() I'd be able to make it work without capabilities but I can't figure out how to do that either.

Link to comment
Share on other sites

16 hours ago, diesieben07 said:

Assuming you are talking about the vanilla inventory here... You will need to indeed override the Slot instance for that particular slot. IItemHandler is not really of use here (neither are capabilities), because this is vanilla code - which knows of neither of those things. So really you are on the right track, you just need to make sure to do it on both client and server.

Show what you have attempted so far.

Thank you!!! I think I'm confused about how to do it on both sides then. Here's what I've got that's relevant:

MyFirstMod.java (init code):

    @SubscribeEvent
    public void onPlayerLogin(final PlayerEvent.PlayerLoggedInEvent event) {
        /*
            CONTAINER INDEX ORDER:
                0: CRAFTING RESULTS SLOT
                1-4: CRAFTING MATRIX
                5-8: ARMOR SLOTS
        */
        PlayerEntity player = event.getPlayer();
        List<Slot> slots = player.container.inventorySlots;

        slots.set(5, new LockableSlot(player.inventory, 39, 8, 8 * 18));
    }

LockableSlot.java:

public class LockableSlot extends Slot {
    public LockableSlot(IInventory inventoryIn, int index, int xPosition, int yPosition) {
        super(inventoryIn, index, xPosition, yPosition);
    }

    @Override
    public boolean canTakeStack(PlayerEntity playerIn) {
        return false;
    }
}

I've messed around with a ton of other functions but canTakeStack is the only one that I can get to actually do anything. If you could help me fix the syncing it would be incredible thank you!!! Idk if I have to block PlayerContainer.slotClick() somehow?

 

EDIT: I should clarify that even though the class is called LockableSlot, I'm just trying to make something that's permanently locked right now, and am planning on implementing that functionality once I've got that sorted out

EDIT #2: also, yes I am using the vanilla inventory, not sure which non-vanilla inventories you're referring to but I assume you mean from another mod

Edited by sarkozi
Link to comment
Share on other sites

7 hours ago, diesieben07 said:

You should probably write a Slot class that takes in the original Slot and delegates all method calls to it instead of making an entirely new slot.

 

Your issue here is that you are using PlayerLoggedInEvent, which fires on the server only. Even if you needed something on the server only, this would not be enough, because the player entity may be re-created (if you change dimension or respawn). So you either need to use PlayerLoggedInEvent, PlayerRespawnEvent and  PlayerChangedDimensionEvent for the server plus ClientPlayerNetworkEvent.LoggedInEvent and ClientPlayerNetworkEvent.RespawnEvent for the client or you could just use EntityJoinWorldEvent and check for players, as this fires on server and client and fires every time the player joins the world. 

I tried using instanceof to check EntityJoinWorldEvent and casting it to a PlayerEntity, and it works! Can't say I entirely understand how the networking works, but thank you so much for your help! One more question: how would I have known that this particular event is common rather than client- or server-side? Should I know based on the directory structure in the API?

Link to comment
Share on other sites

Sorry to revive a dead thread but I've been playing around with this over the last few days and am having trouble getting it to work the way I hoped it would. When I tried to alter my code so I can toggle the slot's availability, I realized that something is going seriously wrong. None of the new slot's methods are being called on click for some reason, even though hovering and server ticks cause some of them to be called (namely getStack(), isEnabled(), and getHasStack()). My hunch is that in the following code:

    @SubscribeEvent
    public void onEntityJoinWorld(final EntityJoinWorldEvent event) {
        if (event.getEntity() instanceof PlayerEntity) {
            /*
            CONTAINER INDEX ORDER:
                0: CRAFTING RESULTS SLOT
                1-4: CRAFTING MATRIX
                5-8: ARMOR SLOTS
            */
            final int HELMET_INDEX = 5;
            PlayerEntity player = (PlayerEntity) event.getEntity();
            List<Slot> slots = player.container.inventorySlots;
            Slot vanillaHelmetSlot = slots.get(HELMET_INDEX);
            slots.set(HELMET_INDEX, new LockableSlot(player.inventory,
                                                     vanillaHelmetSlot.getSlotIndex(),
                                                     vanillaHelmetSlot.xPos+5, vanillaHelmetSlot.yPos));
        }
    }

my instantiation of a new LockableSlot is basically causing two separate instances, one on the client side and one on the server side. Does that make sense? And if so, how do I fix it? I was considering using a public field like in Forge's Items class, but it would need to be static and final, and it can't be static because I need to feed it an IInventory for its constructor. Hopefully this makes sense, I'm pretty confused about what's going wrong.

Edited by sarkozi
Link to comment
Share on other sites

Okay, so how do I approach making it work? Because as it stands, if I leave the entire class blank:

public class LockableSlot extends Slot {
    public LockableSlot(IInventory inventoryIn, int index, int xPosition, int yPosition) {
        super(inventoryIn, index, xPosition, yPosition);
    }
}

I get a totally unusable slot, when presumably I should be getting a normal, functioning one until I override LockableSlot.canTakeStack(). One idea I had is that maybe the player's inventory is not registering my slot change since I only changed it in my container? I think it's a client-side issue because I didn't run into this back when I was using PlayerLoggedInEvent

Edited by sarkozi
Link to comment
Share on other sites

On 12/26/2020 at 4:38 AM, diesieben07 said:

You should probably write a Slot class that takes in the original Slot and delegates all method calls to it instead of making an entirely new slot.

Trying to figure out what you mean by this -- in order to make this work, I have to replace the existing slot with something new, right? And in order to do that, the new thing has to extend Slot because it needs to be present in the PlayerContainer's inventoryslots array. So I'm not totally clear on how to "wrap" a new class around Slot without just extending and replacing it. Sorry if I'm missing something super obvious.

 

I haven't really looked into debugging Forge yet, I really ought to figure that out. I'll get a git repo up though! Thank you so much for all your help by the way, I really appreciate it.

 

EDIT: here's a repo https://github.com/gsarkozi/headlock

Edited by sarkozi
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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Click Here -- Official Website -- Order Now ➡️● For Order Official Website - https://sale365day.com/get-restore-cbd-gummies ➡️● Item Name: — Restore CBD Gummies ➡️● Ingredients: — All Natural ➡️● Incidental Effects: — NA ➡️● Accessibility: — Online ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅   Restore CBD Gummies is a strong contender for the top gummy of the year. Due to its strong concentration of CBD and purity, you will achieve excellent results while using it if you stick with this solution. Most people who suffer from constant pain, anxiety, depression, and insomnia are currently solving these problems, and you can be the next one. All you need to do is give Restore CBD Gummies a chance and let this fantastic product change your life. Visit the official website to order your Restore CBD Gummies today! After reading Restore CBD Gummies reviews, we now know that knee replacement surgeries are not the only option to treat knee pain, inflammation, joint discomfort, and stiffness. These CBD gummies can heal your joints and provide you relief from pain and stress so that you can lead a happy life. Prosper Wellness Restore CBD Gummies can improve joint mobility and improve knee health so that you can remain healthy. Exclusive Details: *Restore CBD Gummies* Read More Details on Official Website #USA! https://www.facebook.com/claritox.pro.unitedstates https://www.facebook.com/illudermaUCAAU https://www.facebook.com/awakenxtusa https://groups.google.com/a/chromium.org/g/chromium-reviews/c/8NMUVKgd-FA https://groups.google.com/g/microsoft.public.project/c/0UZQQKOZF58 https://groups.google.com/g/comp.editors/c/r_BcRRrvGhs https://medium.com/@illuderma/illuderma-reviews-fda-approved-breakthrough-or-clever-skincare-scam-36088ae82c3e https://medium.com/@claritoxpros/claritox-pro-reviews-legitimate-or-deceptive-dr-warns-of-potential-dangers-d5ff3867b34d https://medium.com/@thedetoxall17/detoxall-17-reviews-scam-alert-or-legit-detox-solution-customer-report-inside-1fd4c6920c9e https://groups.google.com/a/chromium.org/g/chromium-reviews/c/RONgLAl6vwM https://groups.google.com/g/microsoft.public.project/c/TgtOMRFt6nQ https://groups.google.com/g/comp.editors/c/fUfg0L2YfzU https://crediblehealths.blogspot.com/2023/12/revitalize-with-restore-cbd-gummies.html https://community.weddingwire.in/forum/restore-cbd-gummies-uncovered-fda-approved-breakthrough-or-deceptive-wellness-scam--t206896 https://restorecbdgummies.bandcamp.com/album/restore-cbd-gummies-uncovered-fda-approved https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-customer-alert-drs-warning-genuine-or-wellness-hoax.html https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-scam-alert-or-legit-relief-solution-customer-report-inside.html https://medium.com/@restorecbdgum/restore-cbd-gummies-reviews-warning-2023-update-real-or-a-powerful-relief-hoax-caution-350b61472a3f https://devfolio.co/@restorecbdgum https://restore-cbd-gummies-9.jimdosite.com/ https://devfolio.co/project/new/restore-cbd-gummies-reviews-scam-or-legit-custo-7bd6 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/R0enUCvfs8s https://groups.google.com/g/microsoft.public.project/c/miJma2yOMDQ https://groups.google.com/g/comp.os.vms/c/S_HG94aaKFo https://groups.google.com/g/mozilla.dev.platform/c/qb6WpMUYLu0 https://hellobiz.in/restore-cbd-gummies-reviews-warning-2023-update-genuine-wellness-or-another-hoax-caution-211948390 https://pdfhost.io/v/ir5l.cseV_Restore_CBD_Gummies_Reviews_WARNING_2023_Update_Genuine_Wellness_or_Another_Hoax_Caution https://odoe.powerappsportals.us/en-US/forums/general-discussion/7c8b3f62-6d96-ee11-a81c-001dd8066f2b https://gamma.app/public/Restore-CBD-Gummies-ssh57nprs2l6xgq https://restorecbdgummies.quora.com/ https://www.facebook.com/RestoreCBDGummiesUS https://groups.google.com/g/restorecbdgum/c/9KHVNp3oy3E https://sites.google.com/view/restorecbdgummiesreviewsfdaapp/home https://experiment.com/projects/pjyhtzvpcvllopsglcph/methods https://lookerstudio.google.com/reporting/e5e9f52d-ae52-4c84-96c6-96b97932215f/page/XtkkD https://restore-cbd-gummies-reviews-is-it-a-sca.webflow.io/ https://colab.research.google.com/drive/1xZoc6E2H-jliBSZRVl0vnVqrkc3ix4YU https://soundcloud.com/restore-cbd-gummies-821066674/restore-cbd-gummies https://www.eventcreate.com/e/restore-cbd-gummies-reviews https://restorecbdgummies.godaddysites.com/ https://sketchfab.com/3d-models/restore-cbd-gummies-reviews-fda-approved-7cfe1fb8b003481c81689dd9489d2812 https://www.scoop.it/topic/restore-cbd-gummies-by-restore-cbd-gummies-9 https://events.humanitix.com/restore-cbd-gummies https://communityforums.atmeta.com/t5/General-Development/Restore-CBD-Gummies/m-p/1113602
    • Click Here -- Official Website -- Order Now ➡️● For Order Official Website - https://sale365day.com/get-restore-cbd-gummies ➡️● Item Name: — Restore CBD Gummies ➡️● Ingredients: — All Natural ➡️● Incidental Effects: — NA ➡️● Accessibility: — Online ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅   Restore CBD Gummies is a strong contender for the top gummy of the year. Due to its strong concentration of CBD and purity, you will achieve excellent results while using it if you stick with this solution. Most people who suffer from constant pain, anxiety, depression, and insomnia are currently solving these problems, and you can be the next one. All you need to do is give Restore CBD Gummies a chance and let this fantastic product change your life. Visit the official website to order your Restore CBD Gummies today! After reading Restore CBD Gummies reviews, we now know that knee replacement surgeries are not the only option to treat knee pain, inflammation, joint discomfort, and stiffness. These CBD gummies can heal your joints and provide you relief from pain and stress so that you can lead a happy life. Prosper Wellness Restore CBD Gummies can improve joint mobility and improve knee health so that you can remain healthy. Exclusive Details: *Restore CBD Gummies* Read More Details on Official Website #USA! https://www.facebook.com/claritox.pro.unitedstates https://www.facebook.com/illudermaUCAAU https://www.facebook.com/awakenxtusa https://groups.google.com/a/chromium.org/g/chromium-reviews/c/8NMUVKgd-FA https://groups.google.com/g/microsoft.public.project/c/0UZQQKOZF58 https://groups.google.com/g/comp.editors/c/r_BcRRrvGhs https://medium.com/@illuderma/illuderma-reviews-fda-approved-breakthrough-or-clever-skincare-scam-36088ae82c3e https://medium.com/@claritoxpros/claritox-pro-reviews-legitimate-or-deceptive-dr-warns-of-potential-dangers-d5ff3867b34d https://medium.com/@thedetoxall17/detoxall-17-reviews-scam-alert-or-legit-detox-solution-customer-report-inside-1fd4c6920c9e https://groups.google.com/a/chromium.org/g/chromium-reviews/c/RONgLAl6vwM https://groups.google.com/g/microsoft.public.project/c/TgtOMRFt6nQ https://groups.google.com/g/comp.editors/c/fUfg0L2YfzU https://crediblehealths.blogspot.com/2023/12/revitalize-with-restore-cbd-gummies.html https://community.weddingwire.in/forum/restore-cbd-gummies-uncovered-fda-approved-breakthrough-or-deceptive-wellness-scam--t206896 https://restorecbdgummies.bandcamp.com/album/restore-cbd-gummies-uncovered-fda-approved https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-customer-alert-drs-warning-genuine-or-wellness-hoax.html https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-scam-alert-or-legit-relief-solution-customer-report-inside.html https://medium.com/@restorecbdgum/restore-cbd-gummies-reviews-warning-2023-update-real-or-a-powerful-relief-hoax-caution-350b61472a3f https://devfolio.co/@restorecbdgum https://restore-cbd-gummies-9.jimdosite.com/ https://devfolio.co/project/new/restore-cbd-gummies-reviews-scam-or-legit-custo-7bd6 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/R0enUCvfs8s https://groups.google.com/g/microsoft.public.project/c/miJma2yOMDQ https://groups.google.com/g/comp.os.vms/c/S_HG94aaKFo https://groups.google.com/g/mozilla.dev.platform/c/qb6WpMUYLu0 https://hellobiz.in/restore-cbd-gummies-reviews-warning-2023-update-genuine-wellness-or-another-hoax-caution-211948390 https://pdfhost.io/v/ir5l.cseV_Restore_CBD_Gummies_Reviews_WARNING_2023_Update_Genuine_Wellness_or_Another_Hoax_Caution https://odoe.powerappsportals.us/en-US/forums/general-discussion/7c8b3f62-6d96-ee11-a81c-001dd8066f2b https://gamma.app/public/Restore-CBD-Gummies-ssh57nprs2l6xgq https://restorecbdgummies.quora.com/ https://www.facebook.com/RestoreCBDGummiesUS https://groups.google.com/g/restorecbdgum/c/9KHVNp3oy3E https://sites.google.com/view/restorecbdgummiesreviewsfdaapp/home https://experiment.com/projects/pjyhtzvpcvllopsglcph/methods https://lookerstudio.google.com/reporting/e5e9f52d-ae52-4c84-96c6-96b97932215f/page/XtkkD https://restore-cbd-gummies-reviews-is-it-a-sca.webflow.io/ https://colab.research.google.com/drive/1xZoc6E2H-jliBSZRVl0vnVqrkc3ix4YU https://soundcloud.com/restore-cbd-gummies-821066674/restore-cbd-gummies https://www.eventcreate.com/e/restore-cbd-gummies-reviews https://restorecbdgummies.godaddysites.com/ https://sketchfab.com/3d-models/restore-cbd-gummies-reviews-fda-approved-7cfe1fb8b003481c81689dd9489d2812 https://www.scoop.it/topic/restore-cbd-gummies-by-restore-cbd-gummies-9 https://events.humanitix.com/restore-cbd-gummies https://communityforums.atmeta.com/t5/General-Development/Restore-CBD-Gummies/m-p/1113602
    • i use fabric 1.20.1 i used alot of mods like all the trims, bobby, better stats, and more but i encounter a problem when i try to enter my world it force me to be in safe mode and when i click on safe mode it just crash minecraft
    • Dr Oz Bites CBD Gummies: As the manufacturer isn't certain about the end result of the supplement, they are going at the back of faux paid promotions to growth the call for for the product. I felt that it's miles because of this motive, Dr Oz Bites CBD Gummies is earning a variety of popularity among the populace.   ➥ ✅Official Website: https://gummiestoday.com/Dr-Oz-Bites-CBD-Gummies/ ➥ Product Name: Dr Oz Bites CBD Gummies ➥ Benefits: Dr Oz Bites CBD Gummies Helps you to get Pain Relief ➥ Healthy Benefits :Control your hormone levels ➥ Category:Pain Relief Supplement ➥ Rating: ★★★★☆ (4.5/5.0) ➥ Side Effects: No Major Side Effects ➥ Availability: In Stock Voted #1 Product in the United States   📞📞 ✔Hurry Up🤑CLICK HERE TO BUY – “OFFICIAL WEBSITE”🎊👇〽💝💞❣️ 📞📞 ✔Hurry Up🤑CLICK HERE TO BUY – “OFFICIAL WEBSITE”🎊👇〽💝💞❣️ 📞📞 ✔Hurry Up🤑CLICK HERE TO BUY – “OFFICIAL WEBSITE”🎊👇〽💝💞❣️     FOR MORE INFO VISIT OUR OTHER LINKS :- https://www.onlymyhealth.com/dr-oz-cbd-gummies-reviews-care-cbd-shark-tank-gummies-exposed-benefits-1701579520 https://www.deccanherald.com/brandspot/featured/cbd-dr-oz-gummies-reviews-care-cbd-gummies-2023-dr-oz-gummies-is-it-worth-buying-2-2797780 https://www.onlymyhealth.com/cbd-dr-oz-gummies-diabetes-reviews-dr-oz-shark-tank-cbd-gummies-1702083884   Official Facebook Page:- https://www.facebook.com/GreenVibeCBDGummiesForDiabetes https://www.facebook.com/DrOzBitesCBDGummiesSupplement   FOR MORE INFO VISIT OUR OFFICIAL SITE :- https://groups.google.com/g/drone-dev-platform/c/X-xNP-OefLg https://groups.google.com/g/mozilla.dev.platform/c/i9X2WfOmkUs https://groups.google.com/g/mozilla.dev.platform/c/DP8vaQGqayk https://groups.google.com/g/comp.os.vms/c/V9XrF_T5u08 https://groups.google.com/g/comp.mobile.android/c/XuYes3irk9w https://groups.google.com/a/chromium.org/g/chromium-reviews/c/xCJCm9yhigE https://groups.google.com/g/comp.protocols.time.ntp/c/yErPa0A9uw0 https://groups.google.com/g/mozilla.dev.platform/c/dzcLb8COWts   Other Reference Pages JIMDO@ https://dr-oz-b-i-t-e-s-cbd-gummies.jimdosite.com/ GROUP GOOGLE@ https://groups.google.com/g/dr-oz-bites-cbd-gummies-lifestyle/c/MTpEvLDAPb0 GOOGLE SITE@ https://sites.google.com/view/drozbitescbdgummiesingredients/ GAMMA APP@ https://gamma.app/docs/Dr-Oz-Bites-CBD-GummiesIS-FAKE-or-REAL-Read-About-100-Natural-Pro-z7obrrpiq9agw3v Company sites@ https://dr-oz-bites-cbd-gummies-side-effects.company.site/   Recent Searches:- #DrOzBitesCBDGummiesReviews #DrOzBitesCBDGummiesLifestyle #DrOzBitesCBDGummiesBenefits #DrOzBitesCBDGummiesBuy #DrOzBitesCBDGummiesCost #DrOzBitesCBDGummiesIngredients #DrOzBitesCBDGummiesOrder #DrOzBitesCBDGummiesPrice #DrOzBitesCBDGummiesWebsite #DrOzBitesCBDGummiesResults #DrOzBitesCBDGummiesSideEffects #DrOzBitesCBDGummiesAdvantage #DrOzBitesCBDGummiesOffers #DrOzBitesCBDGummiesSupplement #DrOzBitesCBDGummiesBuyNow #DrOzBitesCBDGummiesFormula #DrOzBitesCBDGummiesHowToUse Our Official Blog Link Below:- BLOGSPOT==>>https://dr-oz-bites-cbd-gummies-advantage.blogspot.com/2023/12/Dr-Oz-Bites-CBD-Gummies.html Sunflower==>>https://www.sunflower-cissp.com/glossary/cissp/7068/dr-oz-bites-cbd-gummies-reviews-dr-oz-bites-cbd-gummies-where-to-buy Lawfully ==>>https://www.lawfully.com/community/posts/dr-oz-bites-cbd-gummies-navigating-the-wellness-landscape-BYTaVtWKNIUrHsIxGaivMA%3D%3D DIBIZ==>>https://www.dibiz.com/morrislymorales   Medium==>>https://medium.com/@elizabekennedy/is-dr-oz-bites-cbd-gummies-brand-legit-34cfcab397be   Devfolio==>>https://devfolio.co/projects/how-many-dr-oz-bites-cbd-gummies-need-to-i-take-cdf6        
  • Topics

×
×
  • Create New...

Important Information

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