Jump to content

Recommended Posts

Posted

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.

Screenshot 2021-08-13 140606.png

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

 

Posted

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

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

Posted

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

Posted

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

Screenshot 2021-08-13 211508.png

Posted

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

Posted
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

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

 

Posted

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.

Posted
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

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

Posted

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

Posted (edited)

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.

 

Screenshot 2021-08-15 163950.png

Screenshot 2021-08-15 164013.png

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

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.