So I have been following your Extended Entity Properties Tutorial to the letter. (I'm in 1.7.2)I have currently set everything up as requested, and I am trying to get it to work correctly WITHOUT using datawatchers.But from the way your updated tutorial is working, I have to use datawatchers for currentMana to work, correct?
edit: and by work, I am referring to the guiManaBar
edit: are all 26 free values of DataWatcher shared by everyone, or is it 26 per mod?
So I have been following your Extended Entity Properties Tutorial to the letter. (I'm in 1.7.2)I have currently set everything up as requested, and I am trying to get it to work correctly WITHOUT using datawatchers.But from the way your updated tutorial is working, I have to use datawatchers for currentMana to work, correct?
edit: and by work, I am referring to the guiManaBar
edit: are all 26 free values of DataWatcher shared by everyone, or is it 26 per mod?
DataWatcher indices are shared by ALL mods, so it's 32 total for everyone, less the ones used by vanilla. You don't have to use DataWatcher at all, it's just convenient. DW uses packets to synchronize anyway, so no reason not to use packets yourself.
Whoa... NEVER compare ItemStacks using ==, that compares identity (i.e. memory location), so when you do this:
@SubscribeEvent
public void onCrafting(ItemCraftedEvent event) {
ItemStack CobaltBlock = new ItemStack(CMStuff.cobaltblock);
// I highly doubt this if statement ever evaluates to true:
if (event.crafting == CobaltBlock)
You've just created a NEW memory location with an ItemStack, and are comparing it to the memory location of a different ItemStack in event.crafting/smelting/whatever.
You can use Block.getItemFromBlock(Block) to get an Item instance of a Block:
if (event.crafting.getItem() == Block.getItemFromBlock(CMStuff.cobaltblock)) {
Keep in mind this is also comparing memory locations, but it is safe because Items and Blocks are static, meaning there is only a single instance of it (one memory location) across the entire mod, but ItemStacks each have unique instances.
Oddly enough, out of all your code there, only the ItemSmeltedEvent looks like it should actually 100% work, but you say it doesn't. Try putting a println in there to see if it is called when you smelt an item , and print out what item was smelted. It may be that you are checking for the wrong item.
if (event.pickedUp.getEntityItem().getItem() == Item.getItemFromBlock(CMStuff.cobaltore))
{
event.player.addStat(mod_cobalt.cobaltachiev1, 1);
}
doesn't work either
No? I just tried it and it worked perfectly well:
// double-check your import:
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
@SubscribeEvent
public void onPickup(ItemPickupEvent event) {
if (event.pickedUp.getEntityItem().getItem() == ZSSItems.bomb) {
System.out.println("Picked up a bomb!");
} else if (event.pickedUp.getEntityItem().getItem() == Item.getItemFromBlock(ZSSBlocks.chestLocked)) {
System.out.println("Picked up a locked chest!");
}
}
Both printed to the console when I picked up the appropriate item / block.
// double-check your import:
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
@SubscribeEvent
public void onPickup(ItemPickupEvent event) {
if (event.pickedUp.getEntityItem().getItem() == ZSSItems.bomb) {
System.out.println("Picked up a bomb!");
} else if (event.pickedUp.getEntityItem().getItem() == Item.getItemFromBlock(ZSSBlocks.chestLocked)) {
System.out.println("Picked up a locked chest!");
}
}
Both printed to the console when I picked up the appropriate item / block.
I read the whole TH, but i cant find (or maybe im blind) the method to save ExtendedPlayer info through logout/login or server down/up.
I wnat my current mana to be save even after you log out, so when you log in, you should have the same amount of mana, you had when you left.
Can you please help me with this?
If you followed the tutorial exactly, that should already be happening. The current mana is saved to NBT whenever the game saves, and loads whenever the game loads; make sure your custom data is being synchronized on the client when you load your game. I do this when the properties load from the proxy, which I call from EntityJoinWorldEvent.
If you followed the tutorial exactly, that should already be happening. The current mana is saved to NBT whenever the game saves, and loads whenever the game loads; make sure your custom data is being synchronized on the client when you load your game. I do this when the properties load from the proxy, which I call from EntityJoinWorldEvent.
Now its working, it was a mistake I made in the proxy part.
I really appreciate your guides
how would you using your tutorial as an example would you gain mana upon breaking a custom block (if at all possible)
Replenish some mana when the block breaks If it's a custom block, you can override Block#onBlockDestroyedByPlayer and do it from there, otherwise you will need to use the BreakEvent located in net.minecraftforge.event.world.BlockEvent.
Could you provide an example ? I've already tried that and it does in fact work increasing my unit total (in your example mana but crashes at the same Time I'm trying to figure out a way that won't crash
Edit it's not the code itself cause I can do it through forge events (holding shift increases mana)
So it's the way I'm ring to add it to a block break method
The way I'm implementing it requires the perimeter "player" which block break event doesn't have
Could you provide an example ? I've already tried that and it does in fact work increasing my unit total (in your example mana but crashes at the same Time I'm trying to figure out a way that won't crash
Edit it's not the code itself cause I can do it through forge events (holding shift increases mana)
So it's the way I'm ring to add it to a block break method
The way I'm implementing it requires the perimeter "player" which block break event doesn't have
Did you not read my post? I did not say use Block#breakBlock method. I said you can use the Forge EVENT for BreakBlock, OR you can use the Block#onBlockDestroyedByPlayer method from within your custom Block class.
LevelStorage.get(player).AddLevel(1); is what I'm trying to achieve but I cannot find the method your talking about I'm obviously looking in the wrong place I've scanned the blocks class over twice and can't seem to find it :(its worked in this scenario
@SubscribeEvent
public void PlayerTick(TickEvent.PlayerTickEvent event){
if(event.type == TickEvent.Type.PLAYER){
if(!event.player.worldObj.isRemote)
if(event.player.isSneaking()){
LevelStorage.get(event.player).AddLevel(500);
}
i just cant seem to find a way to make it work in the event of a block breaking
You said you had a custom Block, right? In the Block class, there is this method:
/**
* Called when the block is attempted to be harvested
*/
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {}
Turns out the onBlockDestroyedByPlayer didn't actually have an EntityPlayer argument, but onBlockHarvested does.
If you need it to work for ANY block, then like I already mentioned, you need to subscribe to the net.minecraftforge.event.world.BlockEvent.BreakEvent event.
edit: and by work, I am referring to the guiManaBar
edit: are all 26 free values of DataWatcher shared by everyone, or is it 26 per mod?
-
View User Profile
-
View Posts
-
Send Message
Curse Premium//Achievement
FMLCommonHandler.instance().bus().register(new AchievementHandler());
http://pastebin.com/X2wA6ipf
Dragonisser
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDataWatcher indices are shared by ALL mods, so it's 32 total for everyone, less the ones used by vanilla. You don't have to use DataWatcher at all, it's just convenient. DW uses packets to synchronize anyway, so no reason not to use packets yourself.
Whoa... NEVER compare ItemStacks using ==, that compares identity (i.e. memory location), so when you do this:
@SubscribeEvent public void onCrafting(ItemCraftedEvent event) { ItemStack CobaltBlock = new ItemStack(CMStuff.cobaltblock); // I highly doubt this if statement ever evaluates to true: if (event.crafting == CobaltBlock)You've just created a NEW memory location with an ItemStack, and are comparing it to the memory location of a different ItemStack in event.crafting/smelting/whatever.
You can use Block.getItemFromBlock(Block) to get an Item instance of a Block:
if (event.crafting.getItem() == Block.getItemFromBlock(CMStuff.cobaltblock)) {Keep in mind this is also comparing memory locations, but it is safe because Items and Blocks are static, meaning there is only a single instance of it (one memory location) across the entire mod, but ItemStacks each have unique instances.
Oddly enough, out of all your code there, only the ItemSmeltedEvent looks like it should actually 100% work, but you say it doesn't. Try putting a println in there to see if it is called when you smelt an item , and print out what item was smelted. It may be that you are checking for the wrong item.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDo you know why the PickupEvent dont work?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumYes, for the exact same reason I just posted above.
-
View User Profile
-
View Posts
-
Send Message
Curse Premiumif (event.pickedUp.getEntityItem().getItem() == Item.getItemFromBlock(CMStuff.cobaltore))
{
event.player.addStat(mod_cobalt.cobaltachiev1, 1);
}
doesn't work either
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNo? I just tried it and it worked perfectly well:
// double-check your import: import cpw.mods.fml.common.gameevent.PlayerEvent.ItemPickupEvent; @SubscribeEvent public void onPickup(ItemPickupEvent event) { if (event.pickedUp.getEntityItem().getItem() == ZSSItems.bomb) { System.out.println("Picked up a bomb!"); } else if (event.pickedUp.getEntityItem().getItem() == Item.getItemFromBlock(ZSSBlocks.chestLocked)) { System.out.println("Picked up a locked chest!"); } }Both printed to the console when I picked up the appropriate item / block.
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWorks now ^^ thx
I wnat my current mana to be save even after you log out, so when you log in, you should have the same amount of mana, you had when you left.
Can you please help me with this?
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you followed the tutorial exactly, that should already be happening. The current mana is saved to NBT whenever the game saves, and loads whenever the game loads; make sure your custom data is being synchronized on the client when you load your game. I do this when the properties load from the proxy, which I call from EntityJoinWorldEvent.
Now its working, it was a mistake I made in the proxy part.
I really appreciate your guides
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumReplenish some mana when the block breaks
Great xD
Edit it's not the code itself cause I can do it through forge events (holding shift increases mana)
So it's the way I'm ring to add it to a block break method
The way I'm implementing it requires the perimeter "player" which block break event doesn't have
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumDid you not read my post? I did not say use Block#breakBlock method. I said you can use the Forge EVENT for BreakBlock, OR you can use the Block#onBlockDestroyedByPlayer method from within your custom Block class.
I'm obviously doing something wrong :/ I'll recheck the code
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you post your code I can help you figure out what's wrong; it's likely just a null pointer or something that you forgot to check for.
LevelStorage.get(player).AddLevel(1); is what I'm trying to achieve but I cannot find the method your talking about I'm obviously looking in the wrong place I've scanned the blocks class over twice and can't seem to find it :(its worked in this scenario
@SubscribeEvent
public void PlayerTick(TickEvent.PlayerTickEvent event){
if(event.type == TickEvent.Type.PLAYER){
if(!event.player.worldObj.isRemote)
if(event.player.isSneaking()){
LevelStorage.get(event.player).AddLevel(500);
}
i just cant seem to find a way to make it work in the event of a block breaking
-
View User Profile
-
View Posts
-
Send Message
Curse Premium/** * Called when the block is attempted to be harvested */ public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {}Turns out the onBlockDestroyedByPlayer didn't actually have an EntityPlayer argument, but onBlockHarvested does.
If you need it to work for ANY block, then like I already mentioned, you need to subscribe to the net.minecraftforge.event.world.BlockEvent.BreakEvent event.