Give item when player spawns

Started by Araa2000 on

Topic category: Advanced modding

Active 9 years ago
Joined Oct 2014
Points:
722

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 0
Give item when player spawns
Fri, 04/24/2020 - 11:52 (edited)

Im planning to make a mod that has an help/guidebook which tells crafting recipes and other information about the stuff of my mod. Is there any way to give the book to player when player spawns. Hopefully you understood  im not english :).

Edited by Araa2000 on Fri, 04/24/2020 - 11:52
Active 6 years ago
Joined Jan 2015
Points:
769

User statistics:

  • Modifications: 3
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 47
I dont think this is possible
Sat, 10/10/2015 - 16:26

I dont think this is possible without coding,but maybe you should try to make a "Keybind" that when you press for a example the letter H in your keyboard it do the "Add item to inventory" event,then you just set it to add the guidebook!P.S. I hope you understood im not english too xD

Active 5 years ago
Joined Nov 2014
Points:
717

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1
i think GH127 is right
Sat, 10/10/2015 - 19:25

i think GH127 is right

Active 7 years ago
Joined Mar 2016
Points:
736

User statistics:

  • Modifications: 0
  • Forum topics: 4
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 21
Have you looked into world
Wed, 04/06/2016 - 20:26

Have you looked into world events? I want to do the same just have not got to it yet still working on world gen first

Active 3 years ago
Joined Nov 2015
Points:
726

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 25
First of all Make a variable.
Wed, 04/06/2016 - 23:03

First of all Make a variable.  NewPlayer, make this variabe logic, and set it to true.  This way whenever anyone first joins the world or server they will be defined as a NewPlayer.

1: Make a block that will at every tick give all new players the book.

2: keybind that gives everyone who is NewPlayer the book

3: When ever a NewPlayer Chats (Global Event) he/she gets the book

Now Create a GUI that

 

 

Active 4 years ago
Joined Mar 2018
Points:
681

User statistics:

  • Modifications: 0
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 4
Make A Custom Variable…
Mon, 03/12/2018 - 05:42

Make A Custom Variable. Every tick, check if variable = 1. If it does not, give item and set variable to 2. If variable = 2, do nothing.

Active 4 years ago
Joined Oct 2014
Points:
750

User statistics:

  • Modifications: 1
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 47
Go into the code editor and…
Wed, 06/27/2018 - 00:40

Go into the code editor and find: 'ClientProxytestenvironmentmod.java' should look like below.

package mod.mcreator;

public class ClientProxytestenvironmentmod extends CommonProxytestenvironmentmod {

	@Override
	public void registerRenderers(testenvironmentmod ins) {
		ins.mcreator_0.registerRenderers();

	}
}

Now paste the following into it on line 10:
 

	@SubscribeEvent
	//@SideOnly(Side.CLIENT)
	   public void JoinWorld(PlayerLoggedInEvent event) {
	      EntityPlayer player = event.player;
	      NBTTagCompound entityData = player.getEntityData();

	        	 		player.inventory.addItemStackToInventory(new ItemStack(###ITEM_GOES_HERE###));
						
		}

Like this:

 

package mod.mcreator;

public class ClientProxytestenvironmentmod extends CommonProxytestenvironmentmod {

	@Override
	public void registerRenderers(testenvironmentmod ins) {
		ins.mcreator_0.registerRenderers();

	}
    
     @SubscribeEvent
     //@SideOnly(Side.CLIENT)
        public void JoinWorld(PlayerLoggedInEvent event) {
           EntityPlayer player = event.player;
           NBTTagCompound entityData = player.getEntityData();

                         player.inventory.addItemStackToInventory(new ItemStack(###ITEM_GOES_HERE###));
                              
          }
}

Just put the Item in the ###ITEM_GOES_HERE### Like this but use your item. 

 

package mod.mcreator;

public class ClientProxytestenvironmentmod extends CommonProxytestenvironmentmod {

	@Override
	public void registerRenderers(testenvironmentmod ins) {
		ins.mcreator_0.registerRenderers();

	}
    
     @SubscribeEvent
     //@SideOnly(Side.CLIENT)
        public void JoinWorld(PlayerLoggedInEvent event) {
           EntityPlayer player = event.player;
           NBTTagCompound entityData = player.getEntityData();

                         player.inventory.addItemStackToInventory(new ItemStack(mcreator_testItem));
                              
          }
}

 

Active 4 years ago
Joined Mar 2018
Points:
725

User statistics:

  • Modifications: 0
  • Forum topics: 4
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 53
How would you make it send a…
Wed, 06/27/2018 - 00:47

How would you make it send a specific thing into the chat instead?

Active 1 year ago
Joined Aug 2013
Points:
1162

User statistics:

  • Modifications: 4
  • Forum topics: 6
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 737
All right, there are quite a…
Wed, 06/27/2018 - 11:09

All right, there are quite a few wrong things about this.
First of all, I have to ask why do you add the code to CLIENT proxy and also why do you even add it to proxy class at all??

That is not how are proxies intended to work. They are used to split client and server side code, and that is not what do you want, especially if you need to do the detection on the server/common side.

Now, I can not see where do you register the class as an event handler, as I do not see the registration to the EVENT_BUS and it is not a static event handler.

Now, you can see that your variable entityData of type NBTTagCompound are not used at all.

  • A) Why do you keep unused variable? If you do not need it, remove it. It is waste of resources.
  • B) You should actually use it for detecting if the player has joined for the first time or not unless you want to give him/her the item every time he/she joins and to be honest, that sounds really annoying.

To be honest, I do not really believe that this code will do anything in the game. Sure, it will recompile and it will not crash the game, but almost certainly, unless there is some code you did not show, it won't do anything.

I guess you picked up the code from some forum and edited until it recompiled successfully to you, judging by previously mentioned and the fact, that there is commented out SideOnly annotation in the tutorial.

Also to the question by NaiduBoys about sending a chat message to the player:
You can use EntityPlayer#sendMessage(ITextComponent).
As ITextComponent parse TextComponentString that takes as a parameter just the text as a string.

Active 4 years ago
Joined Mar 2018
Points:
725

User statistics:

  • Modifications: 0
  • Forum topics: 4
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 53
thanks  
Thu, 06/28/2018 - 07:30

thanks

 

Active 4 years ago
Joined Oct 2014
Points:
750

User statistics:

  • Modifications: 1
  • Forum topics: 0
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 47
To be honest I don't even…
Thu, 06/28/2018 - 22:29

To be honest I don't even use Mcreator, I sometimes download it to see if I can help with some things.

Active 3 years ago
Joined Sep 2020
Points:
590

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
Sorry, I'm a completely…
Thu, 09/10/2020 - 15:25

Sorry, I'm a completely newbie, I can't find the Internet how to check a global variable, well, true or false, can you tell me how to do this?

I hope google translator did its job well, I'm in the ranks of not English!