Basically I'm trying to make a void method to call a list of Items, I go about this by creating a new void method in my main class and having hooks or w/e in my item classes that respond when the void is initialised.
Here is a breakdown of my code.
Main Class
package net.minecraft.src;
import net.minecraft.client.Minecraft;
public class mod_Example extends BaseMod
{
public static final Item Secret = new ItemSecret(2000).setItemName("Secret =D");
private static long ItemUpdateCounter;
public mod_Example()
{
ModLoader.SetInGameHook(this, true, true);
ModLoader.AddName(Secret,"Secret");
Book.iconIndex = ModLoader.addOverride("/gui/items.png","/Secret/Secret.png");
ModLoader.AddRecipe(new ItemStack(Secret,1), new Object[]{
"x", Character.valueOf('x'), Block.dirt
});
}
public boolean OnTickInGame(float tick, net.minecraft.client.Minecraft game)
{
ItemUpdateCounter -= 1;
if(ItemUpdateCounter < 1)
{
ItemUpdateCounter = 10;
onItemTick(tick, game);
}
return true;
}
public void onItemTick(float f, Minecraft game) {
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Part 1 - Working");
}
public String Version()
{
return "Version 0.1";
}
}
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import net.minecraft.src.mod_Secret;
//^ Not sure if that does anything but it's worth a shot
public class ItemSecret extends Item
{
public ItemSecret(int i)
{
super(i);
maxStackSize = 1;
setMaxDamage(1);
}
public void onItemTick(float f, Minecraft minecraft)
{
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Part 2 - SUCCESS!");
}
}
So far I do not get success messages in chat even when holding the item.
Any help will be appreciated, this mod is going to be worth it, atleast for some people.
although im not sure that would change it... but that seems to be the only thing i can see
next, change the method in your item class to be static (public static void onItemTick(float f, Minecraft minecraft))
then you need to call it from the onItemTick method in your mod_ class (if thats how you want to do it) like this:
ItemSecret.onItemTick(f, minecraft);
OMG! Thank you! First person who has given me a definitive coding solution that works =D
It works seemlessly and now my mod will almost be complete, no spoilers :tongue.gif:
good to hear!
Remeber: that little green plus sign is a great way to say thank you! :biggrin.gif:
Gah! I almost forgot :tongue.gif: You deserve it!
For extra +, do you know how to detect if the player is doing a key combination?
Eg ctrl right click?
Also, saving to a file, I need to be able to save things to a file in the player's save folder.
Gah! I almost forgot :tongue.gif: You deserve it!
For extra +, do you know how to detect if the player is doing a key combination?
Eg ctrl right click?
add this to your mod_ class
public static KeyBinding ctrl = new KeyBinding("ctrl", 17);
then wherever you want to check it just use
if(mod_YourClass.ctrl.isPressed())
should work :smile.gif:
Rollback Post to RevisionRollBack
Remeber: that little green plus sign is a great way to say thank you!
save the mana integer using the NBTTagCompound like this:
(note this is in EntityPlayer)
in the public void writeEntityToNBT(NBTTagCompound nbttagcompound) method add this:
nbttagcompound.setInteger("Mana", currentMana);
and in the public void readEntityFromNBT(NBTTagCompound nbttagcompound) method add this:
currentMana = nbttagcompound.getInteger("Mana");
Is it that easy? Don't I have to like do something really complex? :tongue.gif:
EDIT: Testing now, still think it's witchcraft.
EDIT: Wait, that's editing a base-class, is there no other way to go about this? I really don't like editing base classes.
well how are you going about adding mana to a player?
(i guess you could make an entity specifically for tracking the mana for the player, which actually wouldnt be too hard)
Rollback Post to RevisionRollBack
Remeber: that little green plus sign is a great way to say thank you!
well how are you going about adding mana to a player?
(i guess you could make an entity specifically for tracking the mana for the player, which actually wouldnt be too hard)
Kk will try. I'll give + if it works :tongue.gif:
I just thought, that's fine for SSP, but if I ever do SMP, I'll need a way to store the variables for each player.
Kk will try. I'll give + if it works :tongue.gif:
I just thought, that's fine for SSP, but if I ever do SMP, I'll need a way to store the variables for each player.
like i said, you can make an entity that basically binds itself to the player (can be invisible) and all it does is keep track of which player its attached to and keep track of the variable (then just load the variable for each one)
Rollback Post to RevisionRollBack
Remeber: that little green plus sign is a great way to say thank you!
Here is a breakdown of my code.
Main Class
So far I do not get success messages in chat even when holding the item.
Any help will be appreciated, this mod is going to be worth it, atleast for some people.
to this:
although im not sure that would change it... but that seems to be the only thing i can see
next, change the method in your item class to be static (public static void onItemTick(float f, Minecraft minecraft))
then you need to call it from the onItemTick method in your mod_ class (if thats how you want to do it) like this:
OMG! Thank you! First person who has given me a definitive coding solution that works =D
It works seemlessly and now my mod will almost be complete, no spoilers :tongue.gif:
Remeber: that little green plus sign is a great way to say thank you! :biggrin.gif:
Gah! I almost forgot :tongue.gif: You deserve it!
For extra +, do you know how to detect if the player is doing a key combination?
Eg ctrl right click?
Also, saving to a file, I need to be able to save things to a file in the player's save folder.
add this to your mod_ class
then wherever you want to check it just use
should work :smile.gif:
Now just answer second problem :tongue.gif:
what do you mean saving to a file?
like saving to a text file?
does it need to be world specific?
what is it you need to save?
-SPOILER ALERT-
Yes
Yes
Yes
The player's mana integer.
(note this is in EntityPlayer)
in the public void writeEntityToNBT(NBTTagCompound nbttagcompound) method add this:
and in the public void readEntityFromNBT(NBTTagCompound nbttagcompound) method add this:
Is it that easy? Don't I have to like do something really complex? :tongue.gif:
EDIT: Testing now, still think it's witchcraft.
EDIT: Wait, that's editing a base-class, is there no other way to go about this? I really don't like editing base classes.
it is pretty much witchcraft and wizardry :tongue.gif: tell me if you have more problems! (or if it didnt work for some reason)
Well thats the thing, see my second edit.
(i guess you could make an entity specifically for tracking the mana for the player, which actually wouldnt be too hard)
Kk will try. I'll give + if it works :tongue.gif:
I just thought, that's fine for SSP, but if I ever do SMP, I'll need a way to store the variables for each player.
like i said, you can make an entity that basically binds itself to the player (can be invisible) and all it does is keep track of which player its attached to and keep track of the variable (then just load the variable for each one)