Posted April 1, 201510 yr Guys, my english is very bad but whatever... Here's the thing, i want to make a new sword(done) that will do more damage against endermans, i tought to do that with EVENTS, when the player hits a mob it will check if the player is holding the correct item and if the target's a enderman... Until here everything is fine but how do I do damage to an entity and the damage must be like the player's hitting!! Here's my code: MotherClass package com.enderutilities.mainpackage; import java.net.Proxy; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.util.DamageSource; import net.minecraftforge.common.MinecraftForge; import com.enderutilities.EnderBlocks.BlockRegistry; import com.enderutilities.EnderBlocks.PlatinumOre; import com.enderutilities.EnderItems.ItemRegistry; import com.enderutilities.EnderTab.EnderTabs; import com.enderutilities.OreSpawn.WGeneration; import com.enderutilities.library.EnderStrings; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = EnderStrings.MODID, version = EnderStrings.VERSION, name = EnderStrings.NAME) public class MotherClass { @SidedProxy(clientSide = "com.enderutilities.mainpackage.ClientProxy", serverSide = "com.enderutilities.mainpackage.CommonProxy") public static CommonProxy proxy; //Pre-inicialiçao @EventHandler public static void preLoad(FMLPreInitializationEvent event) { ItemRegistry.itemMain(); BlockRegistry.blockMain(); MinecraftForge.EVENT_BUS.register(new EventControl()); GameRegistry.registerWorldGenerator(new WGeneration(), 0); proxy.registerRender(); } //Inicialiçao @EventHandler public static void load(FMLInitializationEvent event) { } //Pós-inicialiçao @EventHandler public static void postLoad(FMLPostInitializationEvent event) { } EventClass( I don't think the others classes will be necessary for now) package com.enderutilities.mainpackage; import javax.xml.transform.Source; import api.player.client.ClientPlayerAPI; import api.player.client.ClientPlayerConstructorVisitor; import api.player.client.IClientPlayerAPI; import com.enderutilities.EnderItems.ItemRegistry; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class EventControl{ @SubscribeEvent public void hitEndermanWithDagger(AttackEntityEvent event) { EntityPlayer player = event.entityPlayer; if(event.target instanceof EntityEnderman) { if(player.getCurrentEquippedItem().getItem() == ItemRegistry.platinumDagger) { //DONT KNOW HOW TO DEAL DAMAGE TO THE ENDERMAN, TRIED A LOT :'( } } } }
April 1, 201510 yr I didn't read your code, BUT: You don't need events for CUSTOM things, events are to change vanilla behaviour. If you have your own sword class (which I assume you do) you can override a method hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker). Oh, and since that doesn't answer your main question, here it is: target.attackEntityFrom(source, amount) 1.7.10 is no longer supported by forge, you are on your own.
April 1, 201510 yr Author Thx for answer me, but there's the problem.. the "target.attackEntityFrom(source, amount)"... it asks for the source, i dont imagine what i've to put there since there's no Damagesource in the method hit entity
April 1, 201510 yr Damagesource is damagesource: target.attackEntityFrom(DamageSource.fall, 10.0F); This will deal 10 fall damage. You can use vanilla damagesources or make your own. 1.7.10 is no longer supported by forge, you are on your own.
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.