The Meaning of Life, the Universe, and Everything.
Join Date:
5/26/2012
Posts:
117
Member Details
Hello! I have problem. I'm working on cookie clicker mod. For test I setup keyhandler and if you press "C" its give one cookie to ExtendedEntity. Working great, but all players in world have same amount of cookies. Please help!
Hello! I have problem. I'm working on cookie clicker mod. For test I setup keyhandler and if you press "C" its give one cookie to ExtendedEntity. Working great, but all players in world have same amount of cookies. Please help!
Sounds like you're not differentiating between players when you press 'c'. Could you post your keyhandler code?
1. Packet Handling - you may have read this already, but some key points are you need to send a packet to a specific player.
2. Key Handling - It looks like you've read this one, but check out my post on the topic as it goes into how to use packets from your key handler. There are some specific examples you should find very pertinent to your situation.
To summarize, when you send a packet you should specify to which player you are sending it, otherwise I believe it gets sent to all players. That would explain why everyone is getting the same amount of cookies.
You could check all of that in LivingUpdateEvent, but a better place since you want to add damage would be AttackEntityEvent. Using that you could add damage directly without bothering with the potion.
If adding a potion effect to get the extra damage, you could check in the armor tick update method:
// This goes in your armor class
@Override
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemstack)
{
if (itemstack.itemID == YourMod.YourArmor.itemID)
{
// now check player is wearing the rest of your armor
// if so, add potion effect
}
else // only want to add your effect once, so only check for a single piece worn first, then check rest of slots
return;
}
You could just as easily check if player.getCurrentEquippedItem(1) (2) (3) (4) match your armor ID here as well as check player's health. Then add your potion effect.
For player's current health, use "func_110143_aJ()" from EntityLivingBase. DataWatcher value 6 keeps track of health.
For adding extra damage without using potion effects, use the event "AttackEntityEvent"; it gives you access to both the player and the target, so you can just check if the player is wearing all your gear and then deal the damage directly to the target from there using the method "attackEntityFrom(DamageSource par1DamageSource, float par2)"
Check out the DamageSource class for more handy methods and presets. Most of them are static and return a DamageSource object appropriate to your needs, such as DamageSource.magic (a preset), DamageSource.causeIndirectMagicDamage(Entity attacker, Entity attacked), etc.
do you know how to use events?
if you do you first want to update your forge because then you'll have getHealth instead of some function name
Then you can do
You shouldn't be getting the entity / player's health in your sword class - that's for the event. Do you have an EventHandler set up? If not, check out the first post.
Then, add this event:
@ForgeSubscribe
public void onAttackEntity(AttackEntityEvent event)
{
// I always do this, just easier to type for me
EntityPlayer player = event.entityPlayer;
// if the player's health is less than 5 (2.5 hearts) and holding your item; you'll also need to check for all the other items, but I didn't feel like typing that all out...
if (player.func_110143_aJ() < 5.0F && player.getHeldItem() != null && player.getHeldItem().itemID == YourMod.yourItem.itemID)
{
// this will cause 10 damage to the target
event.target.attackEntityFrom(DamageSource.causePlayerDamage(player), 10.0F);
}
}
That will do some extra damage every time the conditions are met. You could have the method retrieve some damage variable from your sword, too, if you don't want to hard-code it like this.
And yes, you could update forge and use the easier method name, but that's beside the point
Ok, well you are editing a base Forge class ModEventHandler... why? Make your own class and name it anything other than 'EventHandler', such as '999EventHandler' or whatever.
If that doesn't fix the problem, then there is something wrong in your main class before you call the load method.
Oh, well why is it in 'package net.minecraft.src;'? And you have a lot of imports that shouldn't be needed, suggesting to me that you've done something out of the ordinary.
Interesting. You shouldn't need "cpw.mods.fml.common.Mod.EventHandler" - in fact, I can't even find that. Does that not give you an error? And if not, what is that class? There is an 'fml.common.Mod' class, but it's just a java file not a package.
Glad you got it working. Didn't realize you were specifically making a base mod; any particular reason you can't accomplish your goals without that? @EventHandler is used by Forge when you set up a new main mod instance, the way most mods tend to be set up, so that the methods 'load' and such are called automatically when the game loads.
An example of a typical main mod class:
package coolalias.structuregen;
// imports here
@Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.VERSION)
@NetworkMod(clientSideRequired=true, serverSideRequired=false,
channels = {ModInfo.CHANNEL}, packetHandler = SGTPacketHandler.class)
public class StructureGenMain
{
@Instance(ModInfo.MOD_ID)
public static StructureGenMain instance = new StructureGenMain();
@SidedProxy(clientSide = ModInfo.CLIENT_PROXY, serverSide = ModInfo.COMMON_PROXY)
public static CommonProxy proxy;
public static final int MOD_ITEM_INDEX_DEFAULT = 8888;
private int modItemIndex;
public static Item structureSpawner;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
LogHelper.init();
Configuration config = new Configuration(new File(event.getModConfigurationDirectory().getAbsolutePath() + "/StructureGenMod.cfg"));
config.load();
modItemIndex = config.getItem("modItemIndex", MOD_ITEM_INDEX_DEFAULT).getInt() - 256;
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
SGTKeyBindings.init(config);
config.save();
}
@EventHandler
public void load(FMLInitializationEvent event)
{
structureSpawner = new ItemStructureSpawner(modItemIndex++).setUnlocalizedName("structureSpawner");
GameRegistry.addShapelessRecipe(new ItemStack(structureSpawner), Item.stick, Block.dirt);
LanguageRegistry.addName(structureSpawner, "Structure Spawner");
proxy.registerRenderers();
GameRegistry.registerWorldGenerator(new WorldStructureGenerator());
// EVENT_BUS registration would go here, too
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
}
}
Does your registered event handler still work for you in your base mod? I've never tried that.
I haven't personally done what you're asking with the model, but check GotoLink's github - he also rewrites abandoned mods, one of which is Battlegear2. Should cover what you need, I would think.
As for the custom Item slot, I've done that. The way I did it was to bind a key to open a custom inventory screen containing all the information of the basic inventory plus my added slots. I cover how to do it in another tutorial. The key bind there is linked to the item, which you won't want to do (I need to rewrite that part), so you'll need to put all the code for opening the gui in your KeyHandler class (or even PacketHandler). Check my post here for an example of what I mean.
Anyway, that will get you your custom inventory screen with your custom slot. Just make the new container class you use separate from the Item you want to store there, unlike in my tutorial where it's linked together.
You should do one on custom tile entities, like a leveling table for your mana bar
Not a bad idea I'm thinking of adding a section first on adding custom slots to the player's inventory, like mentioned a few posts up.
Regarding that, I forgot to mention your custom inventory would be stored in IExtendedEntityProperties for EntityPlayer, similar to how the EnderChest is handled.
I didn't make a shield, I made extra slots that you could use to add a shield if that was the kind of item you have. It's just a tutorial on extending Player Inventory, not making Items.
If you didn't notice, I use 'ItemUseMana' as the Item... no armor there!
Sounds like you're not differentiating between players when you press 'c'. Could you post your keyhandler code?
PacketHandler:
1. Packet Handling - you may have read this already, but some key points are you need to send a packet to a specific player.
2. Key Handling - It looks like you've read this one, but check out my post on the topic as it goes into how to use packets from your key handler. There are some specific examples you should find very pertinent to your situation.
To summarize, when you send a packet you should specify to which player you are sending it, otherwise I believe it gets sent to all players. That would explain why everyone is getting the same amount of cookies.
If adding a potion effect to get the extra damage, you could check in the armor tick update method:
You could just as easily check if player.getCurrentEquippedItem(1) (2) (3) (4) match your armor ID here as well as check player's health. Then add your potion effect.
From EntityLivingBase:
But yes, getCurrentArmor() from EntityPlayer will also work (note it's the American spelling, so no 'u').
For adding extra damage without using potion effects, use the event "AttackEntityEvent"; it gives you access to both the player and the target, so you can just check if the player is wearing all your gear and then deal the damage directly to the target from there using the method "attackEntityFrom(DamageSource par1DamageSource, float par2)"
Check out the DamageSource class for more handy methods and presets. Most of them are static and return a DamageSource object appropriate to your needs, such as DamageSource.magic (a preset), DamageSource.causeIndirectMagicDamage(Entity attacker, Entity attacked), etc.
if you do you first want to update your forge because then you'll have getHealth instead of some function name
Then you can do
if(getHealth <= 15.0F && player.getHeldItem == insertyourswordnamehere)
insertyourswordnamehere.weaponDamge *= 1.5;
or something like that
also hereis some code that might help with your learnings
https://github.com/darkhax/MoreSwordsMod
Have fun.
Then, add this event:
That will do some extra damage every time the conditions are met. You could have the method retrieve some damage variable from your sword, too, if you don't want to hard-code it like this.
And yes, you could update forge and use the easier method name, but that's beside the point
If that doesn't fix the problem, then there is something wrong in your main class before you call the load method.
An example of a typical main mod class:
I haven't personally done what you're asking with the model, but check GotoLink's github - he also rewrites abandoned mods, one of which is Battlegear2. Should cover what you need, I would think.
As for the custom Item slot, I've done that. The way I did it was to bind a key to open a custom inventory screen containing all the information of the basic inventory plus my added slots. I cover how to do it in another tutorial. The key bind there is linked to the item, which you won't want to do (I need to rewrite that part), so you'll need to put all the code for opening the gui in your KeyHandler class (or even PacketHandler). Check my post here for an example of what I mean.
Anyway, that will get you your custom inventory screen with your custom slot. Just make the new container class you use separate from the Item you want to store there, unlike in my tutorial where it's linked together.
Not a bad idea I'm thinking of adding a section first on adding custom slots to the player's inventory, like mentioned a few posts up.
Regarding that, I forgot to mention your custom inventory would be stored in IExtendedEntityProperties for EntityPlayer, similar to how the EnderChest is handled.
If you didn't notice, I use 'ItemUseMana' as the Item... no armor there!