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



×
×
  • Create New...

Important Information

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