Jump to content

Item Not Doing what it should [Unsolved]


StrangeOne101
 Share

Recommended Posts

I have two main things I want to get done today, but I need help with them. I have changed the question, too.

 

Edit: Scroll down to the bottom of the page. I have a problem with my item.

 

 

As I've said before, I'm new to forge. So I have no idea.

 

Thanks :)

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

For the save-related stuff, I'm just getting into it myself. I'll sort of move it up higher on my queue of crap to program and see if I learn anything worth telling you. Hopefully somebody with more (or just some) experience with NBT stuff replies, for both our sakes.

 

How often do you want to check for this? And what are you checking it from?

 

Also,here's probably plenty of non-Minercraft related Java that could do this, too.

 

I'll reply later tonight if I can, if not I'll try some time tomorrow.

Link to comment
Share on other sites

I've messed with NBT data, but only from within a TileEntity, I have no idea how to go about applying that information to the world.

 

NBT reading/writing is pretty easy though.

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.

Link to comment
Share on other sites

I just want to check if the date (within month) is equal to a value, so then I can run some code, and only allow it to be repeated the year after. Kind of like a one day a year thing. To do that, I need it to record if the event has been run and stuff. Do I need to elaborate more?

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

I've done a lot of googling and searching but all I can find is tutorials for Tile Entities. It would work, but it's not what I want considering that there will be no way of tracking where it is.

 

So to elaborate, a TileEntity would be good but it uses coords, not a global variable.

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

You can use the WorldSavedData class. It allows you to attach data to a world based on a key.

world.loadItemData(YourWorldData.class, "INDENTIFIER") will give you your data back if its already loaded, or load it from disk.

If you want to create a new data instance, just create it with the constructor, and then use world.setItemData("INDENTIFIER", instanceOfYourData);

hth :)

Link to comment
Share on other sites

I have my new class, extending WorldSavedData and with the data I want to keep in the NBT tag read/write methods. What now?
Think of a unique Identifier for your storage, possibly your Mod-Id. Now whenever you need your data use:

server.worldServers[0].loadItemData(YourData.class, "MyAmazingModData");

But be careful: That will return null if you never used the data before. In that case you need to create it first, and then tell the world that it exists:

WorldSavedData data = new YourData("MyAmazingModData");
server.worldServers[0].setItemData("MyAmazingModData", data);

Link to comment
Share on other sites

I don't know about NBT, but about players logging in, there is a IPlayerTracker interface.

Just create a class like so:

 

public class PlayerTracker implements IPlayerTracker {
@Override
public void onPlayerLogin(EntityPlayer player) {
        //Your code
}
public void onPlayerLogout(EntityPlayer player) {	}
public void onPlayerChangedDimension(EntityPlayer player) {}
public void onPlayerRespawn(EntityPlayer player) {}
}

onLogin method gets called every time a player joins a server (in Single Player too).

 

You register player trackers in Your main mod class, preferably in load method.

GameRegistry.registerPlayerTracker(new PlayerTracker());

 

Link to comment
Share on other sites

I don't know about NBT, but about players logging in, there is a IPlayerTracker interface.

Just create a class like so:

 

public class PlayerTracker implements IPlayerTracker {
@Override
public void onPlayerLogin(EntityPlayer player) {
        //Your code
}
public void onPlayerLogout(EntityPlayer player) {	}
public void onPlayerChangedDimension(EntityPlayer player) {}
public void onPlayerRespawn(EntityPlayer player) {}
}

onLogin method gets called every time a player joins a server (in Single Player too).

 

You register player trackers in Your main mod class, preferably in load method.

GameRegistry.registerPlayerTracker(new PlayerTracker());

Thank you. That's exactly what I need. However, for my event, I need the world instance. I don't know how to get it.

Ok. Now to change my data, what do I do? I actually don't have a clue. Sorry.

Once you created it (note: you must only do this once per world!) you use loadItemData() to get your data back. Then modify it and use markDirty() to notify minecraft it has changed.

What do you mean by "get your data back"?

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

Thank you all for your help! I've got the player joining event sorted, just not the data thing sorted.

 

I've registered the data class in my load method and I've tried loading it in my event class but I don't know how to access the specific variables in the data class. So how do I do this?

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

I've also had some other small problems over the last day or so with my mod.

 

I've been spawning in items with different damage values, but some damage values aren't spawned. It will make no sense, so here:

int randomChange = rand.nextInt(50);
			int damageValue;
			if (randomChange < 3)
			{
				damageValue = 4; //rare item damage value
			}
			else if (randomChange < 20)
			{
				damageValue2 = 2 + rand.nextInt(1); //uncommon items, either damage value of 2 or 3. only difference is texture
			}
			else
			{
				damageValue2 = 0 + rand.nextInt(1); //same as above, but for common items.
			}
			EntityItem item = new EntityItem(world, x, y, z, new ItemStack(Main.CustomItem, 1, damageValue));
			world.spawnEntityInWorld(item);

So basicly it only spawns the items with damage values of 0, 2 and 4. I want 1 and 3 also in there. This used to work though! I don't know what has changed since it did.

 

And second basic problem:

@Override
public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) 
{
//stuff here
}

This isn't getting called, even though it recognizes the method (it has a javadoc).

 

Other big problem: I still can't get the WorldData thingy to work. I need help on this. A PM would be great.

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

damageValue = 4; //rare item damage value

}

else if (randomChange < 20)

{

damageValue2 =

 

damageValue, damageValue2  - it's not working because of a typo, I believe.

 

 

 

As For onPlayerStoppedUsing, You may need to specify getMaxItemUseDuration or getItemUseAction.

 

Also, do You call

par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));

in onItemRightClick?

Link to comment
Share on other sites

damageValue = 4; //rare item damage value

}

else if (randomChange < 20)

{

damageValue2 =

 

damageValue, damageValue2  - it's not working because of a typo, I believe.

 

 

 

As For onPlayerStoppedUsing, You may need to specify getMaxItemUseDuration or getItemUseAction.

 

Also, do You call

par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));

in onItemRightClick?

That is a typo, just not in my code. I tried to clear up my variables, sorry.

 

As for the second thing, I'll try it.

 

Edit: That didn't seem to do what I want. I want the item to spawn smoke while the tight mouse button is held down but run an event once released.

The enders are everywhere. You can't escape...

Link to comment
Share on other sites

From oracle docs:

 

int nextInt(int n)

          Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

 

 

So, You need to have

rand.nextInt(2).

.

 

I think it may have changed with the last version of Java.

 

As for smoke, use:

 

onUsingItemTick(ItemStack stack, EntityPlayer player, int count)

To spawn smoke, and

onPlayerStoppedUsing

to run the event.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ok, I found this site while searching for the missing version .jar file, which didn't show up in a net query through DuckDuckGo.  The thread on this site was closed after a comment from someone listed as a coder who stated that it was meant to work in this way, without a .jar file which is no longer necessary.  From earlier posts it seems that this person believed the OP had issues due to use of non vanilla launcher, which to me means he thinks they use a client or something like this.  The OP immediately said that they use vanilla, but doesn't seem like the coder believed them.  They began asking for logs, OP did not provide them.  No need to go further into details. I just reinstalled Windows on an SSD and just installed Minecraft Java, Optifine, Shader, Forge.  That is all that exists on my pc right now, and I had the same issue with 1.19.2 Forge versions not creating .jar file. Now I admit that I am likely missing something here and there is a technicality that isn't being fulfilled, but I have to say that it is not due to using a modified launcher.  All i have done is install optifine, put a shader into the shader folder, installed forge.  No mods yet, nothing.  What is interesting, and is the only reason I felt the need to post here, is that when I went into minecraft library folder and copied forge-1.19.2-43.1.65-client.jar, (I renamed it without the -client,) the Forge version starts up just fine with no further issues. From my point of view it seems that coders are dismissing some valid issues out of hand.  I mean, there are lots of really stupid and lazy people using computers and playing games, but not all of them are really stupid and lazy.  We all have bias, I know that I do as well, and I think it's helpful to be aware of our bias as far as we have the ability to be aware of it. Again, it could be that my assumption that there is a problem with the installer not creating a version .jar file, but I couldn't get it to work, always failed with the same message and then put the .jar file in the version folder and worked without a hitch. Oh, almost forgot, I also went into each installation and changed from 2 to 20GB RAM for the game.  In the past I had issues crashing with many mods installed due to lower RAM allocations and I have 48GB, so felt that was safe enough either way.  Maybe that caused the issue, for all I know.   Just saying, would have been nice if the coder had said go to (generic/vanilla path) and copy (version I used as example) forge-1.19.2-43.1.65-client, paste into forge version folder, rename to forge-1.19.2-43.1.65 and see if that does it.
    • What would make my mod incompatible? I'm very afraid of this. I was making some changes to the game using events. but they would only change items created in my own mod. What is the chance of incompatibility?
    • Hello, Im playing on 1.16.5 and Its keep crashing whenever I try to join a world and I get an error message saying "The game crashed whilst ticking memory connection Error: java.lang.NullPointerException: Ticking memory connection". Heres the crash log https://pastebin.com/rqZtSBms
    • Hello, I'm trying to start an instance, ATM8 on PolyMC in Ubuntu and getting this error: https://pastebin.com/zpXtW6yL I've successfully done this in the past by copying the instance files from Curseforge with no problems. Thanks
    • go into the level.dat file with NBTexplorer and delete everything related to forge, and change WasModded to 0
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.