Testing What Entity Is Hit and NBT Values

Started by DeBeast591 on

Topic category: Help with modding (Java Edition)

Last seen on 14:23, 3. Sep 2020
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Testing What Entity Is Hit and NBT Values

I am making a Genetics mod and one item called the "Syringe" will be used in the mod, when you hit a mob/animal I want the Syringe to be consumed and the player get a new "Used Syringe." To do this, I'll need to test what Entity the player hit, ie: Player hits pig, player gets "Used Syringe - Pig"

I also want to make only one Used Syringe item, using NBT or some other way to make one item that functions as multiple, I would like the sprite to change depending on the NBT value too.

 

Thanks in advance.

Last seen on 21:12, 25. Jul 2022
Joined Jul 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I made up an example…
Thu, 07/30/2020 - 19:36

I made up an example procedure that might help you:

You need a full syringe item and an empty syringe item.

In the empty syringe item, find the procedure trigger "WHEN LIVING ENTITY IS HIT WITH ITEM" and make a new procedure for it.

In the new procedure, put:

Set item in main-hand of <Source entity> to <1> <full syringe item>

IF is <envent/taget entity> (sub)type of <EntityPig>

DO Set NBT tag <"syringetype"> of <Provided itemstack> to <"pig">

ELSE IF is <envent/taget entity> (sub)type of <EntityCow>

DO Set NBT tag <"syringetype"> of <Provided itemstack> to <"cow">

ELSE IF is <envent/taget entity> (sub)type of <EntityChicken>

DO Set NBT tag <"syringetype"> of <Provided itemstack> to <"chicken">

ELSE Set item in main-hand of <Source entity> to <1> <empty syringe item>

If you need to use the NBT tag, do something along these lines (probably right-click on air/block in this example case):

IF Get NBT text tag <"syringetype"> of <Item in main-hand of Event/target entity> = <"pig">

DO Add potion with level <1> and duration <60> to <Event/target entity> type <HUNGER> & Set item in main-hand of <Source entity> to <1> <empty syringe item>

IF Get NBT text tag <"syringetype"> of <Item in main-hand of Event/target entity> = <"cow">

DO Add potion with level <1> and duration <60> to <Event/target entity> type <ABSORPTION> & Set item in main-hand of <Source entity> to <1> <empty syringe item>

IF Get NBT text tag <"syringetype"> of <Item in main-hand of Event/target entity> = <"chicken">

DO Add potion with level <1> and duration <60> to <Event/target entity> type <SLOW-FALLING> & Set item in main-hand of <Source entity> to <1> <empty syringe item>

What are the reasons you want every type of syringe in one item? If you can tell me why, I might be able to come up with a work-around.

 

For using several textures for the same item, I looked into whether you can use a variable in a JSON file, but couldn't find anything conclusive, however if you can find out how, that might be the easiest way to change the item texture, as the texture's path is sitting right there.

Otherwise, you might be able to make a JSON file for each texture and use IF statements in the item's JAVA file to vary which JSON file is called for the texture.

If either of these are done you wouldn't even need a separate empty and full syringe, however, unless you REALLY want to have different textures without multiple items or know how to use JAVA, it would be best to either only use one used-syringe texture (so empty version of item and full version, which I used for the example procedures), or make one item for each used-syringe.