Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 :'(
		}
	}
}
}

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.

  • 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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.