Jump to content

Recommended Posts

Posted

Good place to start, but it is out of date.  I'm want to click on a  block and save position , 2nd click use new position and  first position  to change some blocks.  I have it working but using a hard coded 2nd position.

Posted

my first problem is onItemUse  seems to fire twice , maybe click, and release click? 

	public ActionResultType onItemUse(ItemUseContext context) {
		   World world = context.getWorld();
		   Direction facing = context.getFace().getOpposite();
		   BlockPos newPos = context.getPos();
		   BlockPos pos = newPos;
		   
		   
		   // first use
		   ItemStack iStack = context.getItem();
		   CompoundNBT nbtTagCompound = iStack.getTag();
		   if (nbtTagCompound == null) {
			   nbtTagCompound = new CompoundNBT();
		       iStack.setTag(nbtTagCompound);

		       nbtTagCompound.putBoolean("first", true);
		       nbtTagCompound.putInt("x", pos.getX());
		       nbtTagCompound.putInt("y", pos.getY());
		       nbtTagCompound.putInt("z", pos.getZ());
		       nbtTagCompound.putInt("face", facing.getHorizontalIndex());
		       return ActionResultType.SUCCESS;
		  	}

		   // second use
		   pos = new BlockPos(nbtTagCompound.getInt("x"), nbtTagCompound.getInt("y"), nbtTagCompound.getInt("z") );

 

 

Posted
20 minutes ago, blinky000 said:

my first problem is onItemUse  seems to fire twice , maybe click, and release click? 

It's fired on the logical client and logical server. Most likely you'll only need to execute the logic on the server.

Posted (edited)

If i understand correctly , the tag data is saved in the game data.  How to i make sure at the start of a new game the tag is nulled out  or deleted?

or  after i finish using the item?

 

Edited by blinky000
Posted

bad phrasing ,  when i reload the world, the data from the tag is still there from the last session.  Is the a way when a new session is started to have the tag deleted

Posted

That makes no sense. Why would you want to clear the data just because the player logged out and logged back in again?

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.

Posted
53 minutes ago, blinky000 said:

bad phrasing ,  when i reload the world, the data from the tag is still there from the last session.  Is the a way when a new session is started to have the tag deleted

you could simply not store the data in the first place? then there will be no data when the world loads

Posted

im having an issue  , where the sequence of things is out of order.  where im expecting the first click, it's on the 2nd.  Maybe on need better logic.  just thinking if i new on reload make it easier to know im in the correct order

 

d.

Posted

Sorry, I'm telepathetic, not telepathic. You're going to explain this to your local rubber duck.

  • Haha 1

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.

Posted
2 hours ago, blinky000 said:

kiou.23   how could i  have the data from the first click if i don't save it?

I have absolutely no clue what it is that you're trying to accomplish

Posted
57 minutes ago, blinky000 said:

Its at the top of the post

this is the top of the post:

On 4/15/2021 at 10:01 PM, blinky000 said:

anybody know of some good nbt examples for 1.16

please be clearer

also, if your issue with "nbt examples" has been solved, and now you're facing a different issue, you should make new thread

Posted

this post has gone strange.

you sent me to https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe12_item_nbt_animate

I have been working off of that.

 

what i want to do is:  item first click save position && facing  , send click get the new position ,  execute code using those positions.

I'm starting over from the top trying to understand TheGreyGhost code.

 

Ty for you patience.

 

 

 

Posted
54 minutes ago, blinky000 said:

this post has gone strange.

you sent me to https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe12_item_nbt_animate

I have been working off of that.

what i want to do is:  item first click save position && facing  , send click get the new position ,  execute code using those positions.

I'm starting over from the top trying to understand TheGreyGhost code.

Ty for you patience

I think I understand now what you're trying to do, but correct me if I'm mistaken:

you want to store a position in a nbt on an ItemStack when that Item is used, andafterwards, use of the stored values?

you could store a boolean that holds the "state" of the nbt in it, in one state you would store a position, and in the other you would execute something now that you have a position.

I don't know what you can do to clear the nbt when the world is reloaded however, as that's not a common behaviour to expect

Posted

thats pretty much it.  the problem i was running into,  if the sequence is broken (game crash, switching to a new item or block, re-logging in) that the next use would start over  to the first state.

TheGreyGhost code, after the gem was used it was destroyed , so no issues about starting over

Posted
On 4/19/2021 at 9:51 PM, blinky000 said:

thats pretty much it.  the problem i was running into,  if the sequence is broken (game crash, switching to a new item or block, re-logging in) that the next use would start over  to the first state.

TheGreyGhost code, after the gem was used it was destroyed , so no issues about starting over

perhaps the method you're going after is all wrong...  like thinking a mechanically aligned & operated laser is the right tool for the job when a pair of scissors is better adjusted for opening your packages.

I'm not the sharpest of a bunch.... but it sounds like you're after some world edit functionality, or extending the native commands in minecraft.

perhaps rethinking what you're really doing with the tool, and exactly how ya using it might help you a bit.

 

I'm sorta confused myself...  if it's a wand tool that works as world edit.. and if it's purpose is to select two points & you call a command to be ran...   Why don't you just store/modify the tooltip with a string of numbers? 

--  eh, far as I can know I would consider rethinking how an item is used,  and limiting it to one item only (that otherwise isn't used for clicking on things.

You know that you can separate the 'clicks' right?
- a click, can 'delete' the prior data & store a new set of cords,
- a 'Shift' click, could get 2nd cords, do it's thing... and delete the data as well. >.>

On 4/19/2021 at 9:51 PM, blinky000 said:

thats pretty much it.  the problem i was running into,  if the sequence is broken (game crash, switching to a new item or block, re-logging in) that the next use would start over  to the first state.

TheGreyGhost code, after the gem was used it was destroyed , so no issues about starting over

if that's the thing,  maybe consider setting up clear conditions 'after' it has done it's thing, & on each 'first' click before it stores new info.

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.