Posted August 13, 20214 yr I'm trying to make a event that will give new player custom sword that I made and other event that is you have other sword that you can't have anything in your other hand. I was trying to do it but it isn't going very well. Here is a screenshot.
August 13, 20214 yr Author Quote other event that is you have other sword that you can't have anything in your other hand. I said it wrong. Is there a way to make more custom tool materials do this.
August 13, 20214 yr Author doesn't == mean equal? and for SaveToFile I don't really know That was the last thing I tried so it stayed there for now. I am new to programming and modding and I don't know much
August 13, 20214 yr 24 minutes ago, marinz said: and for SaveToFile I don't really know That was the last thing I tried so it stayed there for now. what do you want to achieve 25 minutes ago, marinz said: I am new to programming and modding and I don't know much do you know basic java?
August 13, 20214 yr Author I have a few greatswords that are supposed to be two handed swords. I wanted to make it that when you hold it in your hand u can't equip anything in your other hand. And for the main reason i'm here is that I want to make that when a new player joins the world he gets an item from mod
August 13, 20214 yr Author I removed almost everything I will just do the first time join to get the sword Screenscot shows code for giving it if you don't have it in inventory but I would like it appear when player joins for the first time
August 13, 20214 yr first of all, inventory modifications are server side, so test if the Player you get from the event is a ServerPlayerEntity next player.inventory is client side you should use the Capability IItemHandler (CapabilityItemHandler#ITEM_HANDLER_CAPABILITY) in addition you can't check if the player inventory contains an ItemStack because ItemStack doesn't overwrite the equals method, you only can do this with items (then you can use ==)
August 13, 20214 yr Author Quote next player.inventory is client side you should use the Capability IItemHandler (CapabilityItemHandler#ITEM_HANDLER_CAPABILITY) in addition you can't check if the player inventory contains an ItemStack because ItemStack doesn't overwrite the equals method, you only can do this with items (then you can use ==) I don't know what this part means and thats almost everything
August 13, 20214 yr 14 minutes ago, Luis_ST said: next player.inventory is client side you should use the Capability IItemHandler (CapabilityItemHandler#ITEM_HANDLER_CAPABILITY) https://mcforge.readthedocs.io/en/latest/concepts/sides/ https://mcforge.readthedocs.io/en/latest/datastorage/capabilities/ 14 minutes ago, Luis_ST said: in addition you can't check if the player inventory contains an ItemStack because ItemStack doesn't overwrite the equals method, you only can do this with items (then you can use ==) should be clear if you know basic java (superclass methods form java.lang.Object and OOP)
August 13, 20214 yr Author Not really I read all of that but how do I use that, where to put it how to put it I don't understand that. By the way is there any good website or something where I can learn more because I didn't find that much of explaining in yt videos and some website.
August 13, 20214 yr this is the forge Community Wiki: https://forge.gemwire.uk/wiki/Main_Page and this is the official doc: https://mcforge.readthedocs.io/en/latest/
August 13, 20214 yr Author Thank you for that I will definitly check that out, but can you tell me how to fix this for now.
August 14, 20214 yr 14 hours ago, Luis_ST said: first of all, inventory modifications are server side, so test if the Player you get from the event is a ServerPlayerEntity next player.inventory is client side you should use the Capability IItemHandler (CapabilityItemHandler#ITEM_HANDLER_CAPABILITY) in addition you can't check if the player inventory contains an ItemStack because ItemStack doesn't overwrite the equals method, you only can do this with items (then you can use ==) use PlayerEntity#getCapability use CapabilityItemHandler#ITEM_HANDLER_CAPABILITY and null as parameter then use orElseThrow to get an IItemHandler use a for loop to loop through the slot san check if they contains your item if it dosen't contain your item add it to the IItemHandler
August 14, 20214 yr Author 1 hour ago, marinz said: wouldn't this just give player that item if he doesn't have it? I am not sure is that this. I want it to give a sword to player that joined for the first time on server/singleplayer world.
August 14, 20214 yr is is an example how to check, if the player has or has not an item in his inventory
August 14, 20214 yr Author 2 hours ago, marinz said: That still means it will give it to any player that doesn't have that item
August 14, 20214 yr then you need to store a value for each player you have given the sword, using a Capability Edited August 14, 20214 yr by Luis_ST
August 15, 20214 yr Author and how should I do that. I am sorry I don't really understand how to put that together
August 15, 20214 yr okay first of all you need to create a Capability which contains a value (a boolean), then you need an interface with two methods a get and a set method for the value, register the Capability as described in the forge doc and Attach the Capability to the player via AttachCapabilitiesEvent<Entity>. use the PlayerEvent.PlayerLoggedInEvent and check inside the if your Capability is present (you get it via PlayerEntity#getCapability), then get the value from the Capability and check if its false, if its the case give the player the sword and set the value to true
August 15, 20214 yr Author I did this but I still don't know how to attach capability here are some screenshots of what I've done. I've looked on forge doc and forge community wiki and still don't understand how that would be done. Edited August 15, 20214 yr by marinz
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.