Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Give Player an Item
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
vin0m

[1.12.2] Give Player an Item

By vin0m, July 10, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

vin0m    0

vin0m

vin0m    0

  • Tree Puncher
  • vin0m
  • Members
  • 0
  • 36 posts
Posted July 10, 2018

I am trying to give an item to a player and for some reason this code that was working in 1.10.2 will not work in 1.12.2.  I can't figure out what I need to do differently.  Code:

 

ItemStack stack = new ItemStack(ModItems.goldSatchel);
Item item = stack.getItem();
int newItemValue = maxItemDamage - value;
item.setDamage(stack, newItemValue);
player.inventory.addItemStackToInventory(stack);

 

The new item is not placed in the players inventory.  Did something change in 1.12?

  • Quote

Share this post


Link to post
Share on other sites

cubicoder    2

cubicoder

cubicoder    2

  • Tree Puncher
  • cubicoder
  • Members
  • 2
  • 13 posts
Posted July 10, 2018

Where are you running this code?

  • Quote

Check out my tutorials at https://cubicoder.github.io/.

Share this post


Link to post
Share on other sites

aw_wolfe    14

aw_wolfe

aw_wolfe    14

  • Stone Miner
  • aw_wolfe
  • Members
  • 14
  • 94 posts
Posted July 10, 2018

you can set the damage directly to the stack

 

stack.setItemDamage();

 

Are you getting an item in inventory, or just not a damaged item?

  • Quote

Share this post


Link to post
Share on other sites

vin0m    0

vin0m

vin0m    0

  • Tree Puncher
  • vin0m
  • Members
  • 0
  • 36 posts
Posted July 10, 2018
4 minutes ago, cubicoder said:

Where are you running this code?

I am running it in my class "CommandGoldCoins implements ICommand {" in the section "public void execute(MinecraftServer server, ICommandSender sender, String[] input) throws CommandException".

 

5 minutes ago, aw_wolfe said:

you can set the damage directly to the stack

 

stack.setItemDamage();

 

Are you getting an item in inventory, or just not a damaged item?

A part of this command modifies the current item damage.  That works fine. It is also supposed to make a new item (code above) with a set damage amount.  The new item does not appear in the inventory.  It worked fine in 1.10.2 so I'm confused on what has changed.

  • Quote

Share this post


Link to post
Share on other sites

cubicoder    2

cubicoder

cubicoder    2

  • Tree Puncher
  • cubicoder
  • Members
  • 2
  • 13 posts
Posted July 10, 2018 (edited)

Looking at the code for the /give command, it looks like you have to have the player drop the item stack using player.dropItem(itemstack, false). Then make the resulting EntityItem have no pickup delay and set the owner to the player (entityitem.setNoPickupDelay() and entityitem.setOwner(entityplayer.getName()), respectively). I've never messed with commands before, though, so I may be wrong.

Edited July 10, 2018 by cubicoder
  • Quote

Check out my tutorials at https://cubicoder.github.io/.

Share this post


Link to post
Share on other sites

vin0m    0

vin0m

vin0m    0

  • Tree Puncher
  • vin0m
  • Members
  • 0
  • 36 posts
Posted July 10, 2018

Apparently you can only set the item damage up to 4 digits.  Anything over that and it fails to create the item.  That was the issue.  

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    741

Animefan8888

Animefan8888    741

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 741
  • 6157 posts
Posted July 10, 2018 (edited)
22 hours ago, vin0m said:

Apparently you can only set the item damage up to 4 digits.  Anything over that and it fails to create the item.  That was the issue.  

ItemStack#itemDamage is truncated to a short value aka the max is 32767(thank you Draco18s). ItemStacks are considered empty if their itemDamage is greater than 65535 or less than -32767.

Edited July 11, 2018 by Animefan8888
Error
  • Quote

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Share this post


Link to post
Share on other sites

diesieben07    7582

diesieben07

diesieben07    7582

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7582
  • 54896 posts
Posted July 10, 2018
8 hours ago, vin0m said:

CommandGoldCoins implements ICommand

Do not implement ICommand directly. I have never seen anyone doing that do it correctly. Extend CommandBase instead (and make sure to only implement the necessary methods).

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2401

Draco18s

Draco18s    2401

  • Reality Controller
  • Draco18s
  • Members
  • 2401
  • 15918 posts
Posted July 10, 2018
12 hours ago, Animefan8888 said:

ItemStack#itemDamage is truncated to a short value aka the max is 65535.

*cough*

32766.

32767 is the Wildcard Value ("match any").

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • kiou.23
      [1.16] Custom Sign won't render

      By kiou.23 · Posted 2 minutes ago

      Alright, where can I learn about the ObsfuscationReflectionHelper and SRG names? (and by register, you mean registering to the VALUES field from the WoodType class?) doesn't this do it? Atlases.SIGN_MATERIALS.put(ModWoodType.EFFETE, new RenderMaterial(Atlases.SIGN_ATLAS, new ResourceLocation("effetewood:entity/signs/effete"))); if it doesn't, can you point me towards how I would write my own renderer?
    • diesieben07
      [1.16] Custom Sign won't render

      By diesieben07 · Posted 14 minutes ago

      You still need reflection to register it.   I don't know. It might be better to just make your own renderer and not use this vanilla stuff.
    • kiou.23
      [1.16] Custom Sign won't render

      By kiou.23 · Posted 22 minutes ago

      I had asked on discord and someone suggested using reflection. but yeah, a subclass is way better This is correct? public class ModWoodType extends WoodType { public static final WoodType EFFETE = new ModWoodType("effete"); protected ModWoodType(String name) { super(name); } } Yeah, you told me that in another thread. But since I don't need to use reflection, I'm going to postpone studying error handling to another week And how should I go about doing that? I tried: @SubscribeEvent public static void modelRegistryEvent(ModelRegistryEvent e) { Atlases.SIGN_MATERIALS.put(ModWoodType.EFFETE, new RenderMaterial(Atlases.SIGN_ATLAS, new ResourceLocation("effetewood:entity/signs/effete"))); } It still doesn't work (The edit screen pops up for less than a second, and appear to have the missing pink/black texture), and the actual block just is invisible (dumb question: I don't need to specify "textures/entity/..." in the resouce location, right?)
    • diesieben07
      Failure message: Missing License Information in file Mod File

      By diesieben07 · Posted 35 minutes ago

      I am locking this thread now, because too many irrelevant replies are coming in. If you have an issue, make your own thread and post logs.
    • diesieben07
      Failure message: Missing License Information in file Mod File

      By diesieben07 · Posted 35 minutes ago

      It is impossible for you to get this message on 1.14.4. Make your own thread and post logs.
  • Topics

    • kiou.23
      4
      [1.16] Custom Sign won't render

      By kiou.23
      Started 7 hours ago

    • arkeN
      50
      Failure message: Missing License Information in file Mod File

      By arkeN
      Started October 11, 2020

    • Ronshark
      2
      Bug logs Minecraft Code sortie 0

      By Ronshark
      Started 17 hours ago

    • Sr_endi
      2
      [1.16.4]How to set the light value of an block

      By Sr_endi
      Started 20 hours ago

    • e2rifia
      1
      (1.16.2) How do I use onPlayerTick?

      By e2rifia
      Started 2 hours ago

  • Who's Online (See full list)

    • Bailym
    • Choonster
    • Terence O'Meally
    • kinno
    • Veo
    • Danebi
    • Thorius
    • diesieben07
    • vemerion
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Give Player an Item
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community