I'm also trying to implement cooldown on the mana item. Item.onUpdate() is "Called each tick as long the item is on a player inventory" . From what i know 20 game ticks are 1 second but setting the cooldown to 100 secs and decreasing it every onUpdate takes 2.4 secs accoarding to my stopwatch. What am I doing wrong?
Edit: So I realised that onUpdate is being called 40 times per second but I don't know why.
Try this:
Under your "public class ExtendedPlayer" put:
private int delayTimer;
Next, create two new methods as shown:
public int setDelayTimer(int timer) {
if(this.delayTimer != timer) {
this.delayTimer = timer;
this.sync;
}
return this.delayTimer
}
public int getDelayTimer() {
return this.delayTimer;
}
Now, in your item class, under the "onItemRightClick" method put:
if(!world.isRemote) {
EntityPlayer ent = (EntityPlayer)event.entityLiving;
ExtendedPlayer props = ExtendedPlayer.get(ent);
int mana = props.getCurrentMana();
int maxmana = props.getMaxMana();
if(mana < maxmana) {
int timer = props.getDelayTimer();
timer++
if(timer >= 200) { //10 Seconds
props.comsumeMana(the amount you want to comsume);
//And whatever else, like spawn an entity or something.
}
props.setDelayTimer(timer);
if(timer == 200) { //Or how ever many ticks you set up above.
props.setDelayTimer(0);
}
}else {
return; //You have to have an else, this just returns nothing.
}
}
This timer method simply counts from 1 to 10 and when it is higher then 10 let's you fire. I haven't tried this so forgive me if something is messed up.
I'm also trying to implement cooldown on the mana item. Item.onUpdate() is "Called each tick as long the item is on a player inventory" . From what i know 20 game ticks are 1 second but setting the cooldown to 100 secs and decreasing it every onUpdate takes 2.4 secs accoarding to my stopwatch. What am I doing wrong?
Edit: So I realised that onUpdate is being called 40 times per second but I don't know why.
It is called on both the client and the server side, but each of those counts separately so shouldn't affect the overall time. You can run the code only on the server by nesting your code in an if world is not remote statement "if (!world.isRemote)", but without seeing your entire Item class it's hard to say why there would be such a huge discrepancy in the time.
If you are using a local integer field in your Item class as the timer, don't. Either store the timer in NBT (preferred, as it keeps the timer in the Item, with one timer per unique stack), or try something like HappyKiller101 suggested (not the best in this type of situation - what if you had two items that needed timers?).
One more slight question that, I know, is quite stupid. But, do I put it in the Server or Client tick handler? And, how exactly would I get my InventoryExtended from ExtendedPlayer? Again, I'm sorry if I sound like I don't seem to know much. I just, want to get everything right the first time or, at least, semi-right. XD
And, I am coding in 1.6.4 XD Maybe I should put "I AM CODING IN 1.6.4" as my signature. XD
Honestly it's been a long time since I've messed with tick handlers, but ideally it will run on both sides; if you have to choose, then go with Server side, but you want the Player tick (which is called on both sides), not server or client tick.
How do you get the custom inventory? The same way you get any object in Java, by either making it public or using a getter. If your problem is that you can't seem to find an EntityPlayer variable in the TickHandler, I believe that the method parameter tickData[0] is an EntityPlayer. To check, simply "println("Is tickData[0] a player? " + (tickData[0] instanceof EntityPlayer))", run the game, and you'll find out. If the player isn't at tickData[0], then it's tickData[1]. Again, you need to look and check for yourself, as I'm just going off my vague memory here.
EDIT: Saw your code for adding the potion effects, looks about right. You could have it check less frequently, even every other tick rather than every single tick (I typically check every 4, 8, 16, or some other power of 2 so I can use bitwise operators >> instead of modulus %), and give your potion effects a sufficient duration to cover that period of time.
For flying, please search "flying armor" or some such in the Modification Development section - there are TONS of threads about flying.
For custom slot background, you need to create a custom Slot class and override whichever slot background method there is - it's what the Armor slots use to get the empty armor icon in the background.
It is called on both the client and the server side, but each of those counts separately so shouldn't affect the overall time. You can run the code only on the server by nesting your code in an if world is not remote statement "if (!world.isRemote)", but without seeing your entire Item class it's hard to say why there would be such a huge discrepancy in the time.
If you are using a local integer field in your Item class as the timer, don't. Either store the timer in NBT (preferred, as it keeps the timer in the Item, with one timer per unique stack), or try something like HappyKiller101 suggested (not the best in this type of situation - what if you had two items that needed timers?).
Honestly it's been a long time since I've messed with tick handlers, but ideally it will run on both sides; if you have to choose, then go with Server side, but you want the Player tick (which is called on both sides), not server or client tick.
How do you get the custom inventory? The same way you get any object in Java, by either making it public or using a getter. If your problem is that you can't seem to find an EntityPlayer variable in the TickHandler, I believe that the method parameter tickData[0] is an EntityPlayer. To check, simply "println("Is tickData[0] a player? " + (tickData[0] instanceof EntityPlayer))", run the game, and you'll find out. If the player isn't at tickData[0], then it's tickData[1]. Again, you need to look and check for yourself, as I'm just going off my vague memory here.
EDIT: Saw your code for adding the potion effects, looks about right. You could have it check less frequently, even every other tick rather than every single tick (I typically check every 4, 8, 16, or some other power of 2 so I can use bitwise operators >> instead of modulus %), and give your potion effects a sufficient duration to cover that period of time.
For flying, please search "flying armor" or some such in the Modification Development section - there are TONS of threads about flying.
For custom slot background, you need to create a custom Slot class and override whichever slot background method there is - it's what the Armor slots use to get the empty armor icon in the background.
I did look up flying armor and, I tried what I got but, it's not working XD I will figure it out in time. And for the background icon, I have tried EVERYTHING it just won't work. I might just add it to the container image for now.
I did look up flying armor and, I tried what I got but, it's not working XD I will figure it out in time. And for the background icon, I have tried EVERYTHING it just won't work. I might just add it to the container image for now.
As always, post your code and you will find many helpful folks around; no code = no help around here
You are not correctly understand my question. For example, if i write code like this:
If (itemInSlot == myitem) //do render;
In multiplayer i can't see that render on another player. It's correctly work only in CMP and SP. How can i do this stuff?
Ah, you need other players to see the item for rendering purposes - you need to send a packet to all nearby players, then, just like before. You can read about converting to the Netty packet system in the tutorial section about updating to 1.7.2.
Ah, you need other players to see the item for rendering purposes - you need to send a packet to all nearby players, then, just like before. You can read about converting to the Netty packet system in the tutorial section about updating to 1.7.2.
I found the class in which the packet is sent to synchronize. This method in class EntityLivingBase on the 1668 line. I understand a little how it works. To do something like that, I do not have enough skills.
I found the class in which the packet is sent to synchronize. This method in class EntityLivingBase on the 1668 line. I understand a little how it works. To do something like that, I do not have enough skills.
Sorry to hear that, but didn't you do it before in 1.5.2? Surely it's not that different... anyway, I know that Battlegear2 syncs custom inventory items for rendering purposes, and that mod is both open source and completely updated for 1.7.2.
The Meaning of Life, the Universe, and Everything.
Join Date:
8/9/2013
Posts:
211
Minecraft:
HappyKiller1O1
Xbox:
HappyKiller101
Member Details
Ok, now I need your help badly. XD I just can't get this "allowFlying" thing to work after it checks if my amulet is there. Here's my code for my ServerTickHandler:
NOTE: This is in my "onPlayerTick" method of my ServerTickHandler.
I know this is probably a very simple mistake I made but, I just can't figure this out. I thought maybe onPlayerTick doesn't check if space is double tapped but, I can't figure out how to check that either.
Ok, now I need your help badly. XD I just can't get this "allowFlying" thing to work after it checks if my amulet is there. Here's my code for my ServerTickHandler:
I know this is probably a very simple mistake I made but, I just can't figure this out. I thought maybe onPlayerTick doesn't check if space is double tapped but, I can't figure out how to check that either.
Contrary to many cases, your problem is probably that you are not running this code on the CLIENT side, which is where movement is handled. You should keep this code running on the server as well, but you need it to run on the client, too, or at least send a packet updating the player's capabilities (and fall distance, too, if you want).
You should still check to make sure your code is at least doing what you think it is doing on the server, by putting println statements in there and viewing the console output. Learning to debug your own code will make you a much better programmer.
I tried deleting the line and was able to start the game without crashing, but my custom inventory wouldn't open. Here is my main class:
@Mod
(modid = minecraftz.modid, version = minecraftz.version)
public class minecraftz
{
@SidedProxy(clientSide = "net.minecraftz.mod.ClientProxy", serverSide = "net.minecraftz.mod.ServerProxy")
public static CommonProxy proxy;
public static final String modid = "minecraftz";
public static final String version = "Alpha v0.1";
public static int modGuiIndex = 0;
public static final int GUI_ITEM_INV = modGuiIndex++;
public static CreativeTabs minecraftzTab;
public static final BiomeGenBase namek = new BiomeGenNamek(40, true).setBiomeName("Namek").setColor(16421912);
public static int dimensionId = 2;
@Instance(modid)
public static minecraftz instance = new minecraftz();
public static Item expItem;
public static Item kiblastItem;
public static Item bigblastItem;
public static Item kamehamehaItem;
public static Item oneStarItem;
public static Item twoStarItem;
public static Item threeStarItem;
public static Item fourStarItem;
public static Item fiveStarItem;
public static Item sixStarItem;
public static Item sevenStarItem;
public static Block blockPortalNamek;
public static final PacketPipeline packetPipeline = new PacketPipeline();
@EventHandler
public void PreInit(FMLPreInitializationEvent preEvent)
{
minecraftzTab = new CreativeTabs("minecraftz")
{
@SideOnly(Side.CLIENT)
public Item getTabIconItem()
{
return Item.getItemFromBlock(blockPortalNamek);
}
};
expItem = new expItem().setUnlocalizedName("expItem");
kiblastItem = new kiblastItem().setUnlocalizedName("KiBlast");
bigblastItem = new bigblastItem().setUnlocalizedName("BigBlast");
kamehamehaItem = new kamehamehaItem().setUnlocalizedName("Kamehameha");
oneStarItem = new oneStarItem().setUnlocalizedName("OneStar");
twoStarItem = new twoStarItem().setUnlocalizedName("TwoStar");
threeStarItem = new threeStarItem().setUnlocalizedName("ThreeStar");
fourStarItem = new fourStarItem().setUnlocalizedName("FourStar");
fiveStarItem = new fiveStarItem().setUnlocalizedName("FiveStar");
sixStarItem = new sixStarItem().setUnlocalizedName("SixStar");
sevenStarItem = new sevenStarItem().setUnlocalizedName("SevenStar");
blockPortalNamek = new BlockPortalNamek().setBlockName("Namek Portal");
In 1.7.2, it's been changed to: "NetworkRegistry.INSTANCE.registerGuiHandler".
Also, you really ought to follow naming conventions - "Minecraftz" instead of "minecraftz" for your class name, etc., and you do not need to create a "new Minecraftz()", "public static Minecraftz instance" is all that you need there.
Arghh... To synchronize my coins in my mod I decided to use Datawatcher, but it works only for data synchronization between client and server. The Datawatcher on the server is not synchronized between the players. I want to make a function which get coins sum from another player in the multiplayer. Someone can explain to me how to make it or explain the working principle?
Arghh... To synchronize my coins in my mod I decided to use Datawatcher, but it works only for data synchronization between client and server. The Datawatcher on the server is not synchronized between the players. I want to make a function which get coins sum from another player in the multiplayer. Someone can explain to me how to make it or explain the working principle?
As long as the data is correct on the server, you can get the sum of the coins from the server. You should never synchronize between players, only between player and server. By default, however, you will only have access to the players that are currently online when summing the total amount of gold in the game; if you want access to the total gold even if a player is offline, you will need to store the amount of gold each player has on the server, rather than as part of the player's data file.
As long as the data is correct on the server, you can get the sum of the coins from the server. You should never synchronize between players, only between player and server. By default, however, you will only have access to the players that are currently online when summing the total amount of gold in the game; if you want access to the total gold even if a player is offline, you will need to store the amount of gold each player has on the server, rather than as part of the player's data file.
Thank you!
But i have new broblem. I made some corrections in my mod. After that, items began to be copied and dupe. I tried to go back, but no error is gone. What it can be?
But i have new broblem. I made some corrections in my mod. After that, items began to be copied and dupe. I tried to go back, but no error is gone. What it can be?
Think about whatever 'corrections' you made, and look there for your problem. Chances are it is somewhere in the Container class, and possibly your IInventory class. Compare your code with those sections in the tutorial, and pay attention to the exact circumstances under which items are duplicated - this will lead you to the solution.
Hi! Really love the tutorial, it's very useful, especially for a first-time modder such as myself. I've followed pretty much every step to the T, but there is one that has just gotten me stumped. I've apparently managed to do the steps after this one, but nothing else.
It's lines 58 and 59 that are problematic. Eclipse keeps telling me that "player cannot be resolved to a variable."
Hope you can help! Cheers!
EDIT: I made a change a few lines up that made the error disappear, and I've managed to get everything theoretically working, but it seems that the keybindings are not getting registered despite the init method for my keyhandler being called in ClientProxy.
I attempted to create a client-side only init event in my main mod class and when I called the keyhandler init method there, the keybindings were registered. That being said, the gui is still not opening. There are no error reports whatsoever to speak of, so I have no idea what's going on. I've done everything right, as far as I can tell, and I've gone over the tutorial at least three times trying to figure out what's being stupid, so I am completely at a loss.
EDIT 2: Oh pfft. Wow. That was dumb of me. I forgot to put the registerRenderers class in the main mod class. Whoops. Gui still doesn't open as far as I can tell.
EDIT 3: Victory! I managed to figure it out... I think? Well, in any case, the gui is opening now.
Try this:
Under your "public class ExtendedPlayer" put:
Next, create two new methods as shown:
public int setDelayTimer(int timer) { if(this.delayTimer != timer) { this.delayTimer = timer; this.sync; } return this.delayTimer } public int getDelayTimer() { return this.delayTimer; }Now, in your item class, under the "onItemRightClick" method put:
if(!world.isRemote) { EntityPlayer ent = (EntityPlayer)event.entityLiving; ExtendedPlayer props = ExtendedPlayer.get(ent); int mana = props.getCurrentMana(); int maxmana = props.getMaxMana(); if(mana < maxmana) { int timer = props.getDelayTimer(); timer++ if(timer >= 200) { //10 Seconds props.comsumeMana(the amount you want to comsume); //And whatever else, like spawn an entity or something. } props.setDelayTimer(timer); if(timer == 200) { //Or how ever many ticks you set up above. props.setDelayTimer(0); } }else { return; //You have to have an else, this just returns nothing. } }This timer method simply counts from 1 to 10 and when it is higher then 10 let's you fire. I haven't tried this so forgive me if something is messed up.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIt is called on both the client and the server side, but each of those counts separately so shouldn't affect the overall time. You can run the code only on the server by nesting your code in an if world is not remote statement "if (!world.isRemote)", but without seeing your entire Item class it's hard to say why there would be such a huge discrepancy in the time.
If you are using a local integer field in your Item class as the timer, don't. Either store the timer in NBT (preferred, as it keeps the timer in the Item, with one timer per unique stack), or try something like HappyKiller101 suggested (not the best in this type of situation - what if you had two items that needed timers?).
Honestly it's been a long time since I've messed with tick handlers, but ideally it will run on both sides; if you have to choose, then go with Server side, but you want the Player tick (which is called on both sides), not server or client tick.
How do you get the custom inventory? The same way you get any object in Java, by either making it public or using a getter. If your problem is that you can't seem to find an EntityPlayer variable in the TickHandler, I believe that the method parameter tickData[0] is an EntityPlayer. To check, simply "println("Is tickData[0] a player? " + (tickData[0] instanceof EntityPlayer))", run the game, and you'll find out. If the player isn't at tickData[0], then it's tickData[1]. Again, you need to look and check for yourself, as I'm just going off my vague memory here.
EDIT: Saw your code for adding the potion effects, looks about right. You could have it check less frequently, even every other tick rather than every single tick (I typically check every 4, 8, 16, or some other power of 2 so I can use bitwise operators >> instead of modulus %), and give your potion effects a sufficient duration to cover that period of time.
For flying, please search "flying armor" or some such in the Modification Development section - there are TONS of threads about flying.
For custom slot background, you need to create a custom Slot class and override whichever slot background method there is - it's what the Armor slots use to get the empty armor icon in the background.
I did look up flying armor and, I tried what I got but, it's not working XD I will figure it out in time. And for the background icon, I have tried EVERYTHING it just won't work. I might just add it to the container image for now.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAs always, post your code and you will find many helpful folks around; no code = no help around here
If (itemInSlot == myitem) //do render;
In multiplayer i can't see that render on another player. It's correctly work only in CMP and SP. How can i do this stuff?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAh, you need other players to see the item for rendering purposes - you need to send a packet to all nearby players, then, just like before. You can read about converting to the Netty packet system in the tutorial section about updating to 1.7.2.
I found the class in which the packet is sent to synchronize. This method in class EntityLivingBase on the 1668 line. I understand a little how it works. To do something like that, I do not have enough skills.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSorry to hear that, but didn't you do it before in 1.5.2? Surely it's not that different... anyway, I know that Battlegear2 syncs custom inventory items for rendering purposes, and that mod is both open source and completely updated for 1.7.2.
if(props.inventory.getStackInSlot(props.inventory.SLOT_AMULET) != null) { if(props.inventory.getStackInSlot(props.inventory.SLOT_AMULET).itemID == HappyCraftMod.DragonSoulAmulet.itemID) { player.capabilities.allowFlying = true; if(player.fallDistance >= 1) { player.fallDistance = 0; } } }NOTE: This is in my "onPlayerTick" method of my ServerTickHandler.
I know this is probably a very simple mistake I made but, I just can't figure this out. I thought maybe onPlayerTick doesn't check if space is double tapped but, I can't figure out how to check that either.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumContrary to many cases, your problem is probably that you are not running this code on the CLIENT side, which is where movement is handled. You should keep this code running on the server as well, but you need it to run on the client, too, or at least send a packet updating the player's capabilities (and fall distance, too, if you want).
You should still check to make sure your code is at least doing what you think it is doing on the server, by putting println statements in there and viewing the console output. Learning to debug your own code will make you a much better programmer.
NetworkRegistry.instance().registerGuiHandler(this, this.proxy);
I tried deleting the line and was able to start the game without crashing, but my custom inventory wouldn't open. Here is my main class:
@Mod
(modid = minecraftz.modid, version = minecraftz.version)
public class minecraftz
{
@SidedProxy(clientSide = "net.minecraftz.mod.ClientProxy", serverSide = "net.minecraftz.mod.ServerProxy")
public static CommonProxy proxy;
public static final String modid = "minecraftz";
public static final String version = "Alpha v0.1";
public static int modGuiIndex = 0;
public static final int GUI_ITEM_INV = modGuiIndex++;
public static CreativeTabs minecraftzTab;
public static final BiomeGenBase namek = new BiomeGenNamek(40, true).setBiomeName("Namek").setColor(16421912);
public static int dimensionId = 2;
@Instance(modid)
public static minecraftz instance = new minecraftz();
public static Item expItem;
public static Item kiblastItem;
public static Item bigblastItem;
public static Item kamehamehaItem;
public static Item oneStarItem;
public static Item twoStarItem;
public static Item threeStarItem;
public static Item fourStarItem;
public static Item fiveStarItem;
public static Item sixStarItem;
public static Item sevenStarItem;
public static Block blockPortalNamek;
public static final PacketPipeline packetPipeline = new PacketPipeline();
@EventHandler
public void PreInit(FMLPreInitializationEvent preEvent)
{
minecraftzTab = new CreativeTabs("minecraftz")
{
@SideOnly(Side.CLIENT)
public Item getTabIconItem()
{
return Item.getItemFromBlock(blockPortalNamek);
}
};
expItem = new expItem().setUnlocalizedName("expItem");
kiblastItem = new kiblastItem().setUnlocalizedName("KiBlast");
bigblastItem = new bigblastItem().setUnlocalizedName("BigBlast");
kamehamehaItem = new kamehamehaItem().setUnlocalizedName("Kamehameha");
oneStarItem = new oneStarItem().setUnlocalizedName("OneStar");
twoStarItem = new twoStarItem().setUnlocalizedName("TwoStar");
threeStarItem = new threeStarItem().setUnlocalizedName("ThreeStar");
fourStarItem = new fourStarItem().setUnlocalizedName("FourStar");
fiveStarItem = new fiveStarItem().setUnlocalizedName("FiveStar");
sixStarItem = new sixStarItem().setUnlocalizedName("SixStar");
sevenStarItem = new sevenStarItem().setUnlocalizedName("SevenStar");
blockPortalNamek = new BlockPortalNamek().setBlockName("Namek Portal");
int modEntityID = 0;
BiomeDictionary.registerBiomeType(namek, Type.NETHER);
GameRegistry.registerItem(kiblastItem, "KiBlast");
GameRegistry.registerItem(bigblastItem, "BigBlast");
GameRegistry.registerItem(oneStarItem, "OneStar");
GameRegistry.registerItem(twoStarItem, "TwoStar");
GameRegistry.registerItem(threeStarItem, "ThreeStar");
GameRegistry.registerItem(fourStarItem, "FourStar");
GameRegistry.registerItem(fiveStarItem, "FiveStar");
GameRegistry.registerItem(sixStarItem, "SixStar");
GameRegistry.registerItem(sevenStarItem, "SevenStar");
GameRegistry.registerBlock(blockPortalNamek, "PortalNamek");
EntityRegistry.registerModEntity(EntityKiblast.class, "Ki Blast", ++modEntityID, this, 64, 10, true);
EntityRegistry.registerModEntity(EntityBigblast.class, "Big Blast", ++modEntityID, this, 64, 10, true);
EntityHandler.registerEntities(EntityTiger.class, "Tiger");
DimensionManager.registerProviderType(minecraftz.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIn 1.7.2, it's been changed to: "NetworkRegistry.INSTANCE.registerGuiHandler".
Also, you really ought to follow naming conventions - "Minecraftz" instead of "minecraftz" for your class name, etc., and you do not need to create a "new Minecraftz()", "public static Minecraftz instance" is all that you need there.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumAs long as the data is correct on the server, you can get the sum of the coins from the server. You should never synchronize between players, only between player and server. By default, however, you will only have access to the players that are currently online when summing the total amount of gold in the game; if you want access to the total gold even if a player is offline, you will need to store the amount of gold each player has on the server, rather than as part of the player's data file.
Thank you!
But i have new broblem. I made some corrections in my mod. After that, items began to be copied and dupe. I tried to go back, but no error is gone. What it can be?
Screenshot:
Ps I did not upload the code, as it very much and it is difficult to read.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThink about whatever 'corrections' you made, and look there for your problem. Chances are it is somewhere in the Container class, and possibly your IInventory class. Compare your code with those sections in the tutorial, and pay attention to the exact circumstances under which items are duplicated - this will lead you to the solution.
[Github Link]
It's lines 58 and 59 that are problematic. Eclipse keeps telling me that "player cannot be resolved to a variable."
Hope you can help! Cheers!
EDIT: I made a change a few lines up that made the error disappear, and I've managed to get everything theoretically working, but it seems that the keybindings are not getting registered despite the init method for my keyhandler being called in ClientProxy.
I attempted to create a client-side only init event in my main mod class and when I called the keyhandler init method there, the keybindings were registered. That being said, the gui is still not opening. There are no error reports whatsoever to speak of, so I have no idea what's going on. I've done everything right, as far as I can tell, and I've gone over the tutorial at least three times trying to figure out what's being stupid, so I am completely at a loss.
EDIT 2: Oh pfft. Wow. That was dumb of me. I forgot to put the registerRenderers class in the main mod class. Whoops. Gui still doesn't open as far as I can tell.
EDIT 3: Victory! I managed to figure it out... I think? Well, in any case, the gui is opening now.