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.

[1.8] [SOLVED!] Changing vanilla mob attributes (zombie, skeleton etc.)

Featured Replies

Posted

Hello, I'm making a huge mod for minecraft and I'm currently stuck at changing vanilla mob attributes, I did something like when a mob spawns, it register it to my custom entity and change the attributes from there, like this:

 

When entity spawns:

@SubscribeEvent
public void onLivingSpawn(LivingSpawnEvent e) {
	if (e.entityLiving instanceof EntityMob) {
		EntityMob entity = (EntityMob) e.entityLiving;
		String entityName = entity.getDisplayName().getFormattedText().toLowerCase().replace("§r", "");
		MepCustomEntityLiving customEntity = MepEntityEnumRegistry
		 .getEntityFromName(entityName);
		entity.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(customEntity.getMaxHealth());
		// entity.getEntityAttribute(SharedMonsterAttributes.attackDamage)
		// .setBaseValue(customEntity.getStat("strength"));
		System.out.println(customEntity.getName().toUpperCase() + " changed successfully");
	}
}

 

MepCustomEntityLiving:

package com.thelorizz.mep.customclass;

import com.thelorizz.mep.MepMain;
import com.thelorizz.mep.enumeration.MepEntityFunctions;

public class MepCustomEntityLiving {

public MepEntityFunctions entityFunctions;
public double expGiven;
public double strength;
public double defense;
public double maxHealth;
public int tier;
public String name;

public MepCustomEntityLiving(int par1, String par2) {
	this.tier = par1;
	this.name = par2;
	this.expGiven = this.setByTier(tier, "expGiven");
	this.strength = this.setByTier(tier, "strength");
	this.defense = this.setByTier(tier, "defense");
	this.maxHealth = this.setByTier(tier, "maxHealth");
}

public double getStat(String par1) {
	switch (par1) {
	case "expGiven":
		return this.expGiven;
	case "strength":
		return this.strength;
	case "defense":
		return this.defense;
	default:
		return 0;
	}
}

public String getName() {
	return this.name;
}

public double getMaxHealth() {
	return this.maxHealth;
}

public int getTier() {
	return this.tier;
}

public static double random(int mult, int plus) {
	MepCustomEntityPlayer player = MepMain.instance.getCustomEntityPlayerInstance();
	double levelModifier = player.getCurrentLevel() / 2;
	return (float) ((Math.random() * mult + plus) + levelModifier);
}

public static double set(int amount) {
	MepCustomEntityPlayer player = MepMain.instance.getCustomEntityPlayerInstance();
	double levelModifier = player.getCurrentLevel() / 2;
	return (int) (amount + levelModifier);
}

public static double setByTier(int par1, String type) {
	switch (par1) {
	case 1:
		switch (type) {
		case "expGiven":
			return random(3, 4);
		case "strength":
			return random(2, 4);
		case "defense":
			return random(1, 4);
		case "maxHealth":
			return set(250);
		}
	case 2:
		switch (type) {
		case "expGiven":
			return random(7, 4);
		case "strength":
			return random(5, 4);
		case "defense":
			return random(7, 4);
		case "maxHealth":
			return set(400);
		}
	case 3:
		switch (type) {
		case "expGiven":
			return random(14, 4);
		case "strength":
			return random(16, 4);
		case "defense":
			return random(13, 4);
		case "maxHealth":
			return set(740);
		}
	case 4:
		switch (type) {
		case "expGiven":
			return random(28, 4);
		case "strength":
			return random(24, 4);
		case "defense":
			return random(21, 4);
		case "maxHealth":
			return set(1430);
		}
	default:
		return 0;
	}
}
}

 

And the function that register the mob in the registry:

public static MepCustomEntityLiving getEntityFromName(String name) {
	for(int i = 0; i < entities.length; i++) {
		if (name.equals(entities[i].getName())) {
			return new MepCustomEntityLiving(entities[i].getTier(), entities[i].getName());
		}
	}
	return null;
}

 

But it doesn't work, it only works the exp given randomly.

You never do anything with

expGiven

after setting its value.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

You never do anything with

expGiven

after setting its value.

 

It's in another code, it works that's why I didn't post it here, I just need to change the attackDamage and maxHealth

Are you sure you are getting a matching entry based on the entity's display name? What does your 'entities' array contain, and where did you get those names from?

 

Using the display name is a bad idea anyway - what if I'm playing in Chinese? The server has no idea what language I'm using, so it's expecting 'entity.zombie.name' or something like that, but I'm sending it 殭屍? Not gonna work.

  • Author

Are you sure you are getting a matching entry based on the entity's display name? What does your 'entities' array contain, and where did you get those names from?

 

Using the display name is a bad idea anyway - what if I'm playing in Chinese? The server has no idea what language I'm using, so it's expecting 'entity.zombie.name' or something like that, but I'm sending it 殭屍? Not gonna work.

 

Actually it works, but yes you're right, I need to change it.

I cannot edit the attributes

  • Author

EDIT: I found a solution but it returns a NullPointer in the ".applyModifier(modifier);" method:

@SubscribeEvent
public void onEntityConstructing(EntityConstructing e) {
if (e.entity instanceof EntityLiving) {
	EntityLiving entity = (EntityLiving) e.entity;
	String entityName = entity.getName();
	MepCustomEntityLiving customEntity = MepEntityEnumRegistry.getEntityFromName(entityName);
	if (customEntity != null) {
		double newHealth = customEntity.getMaxHealth();
		MepAttributeList attributeList = MepMain.ATTRIBUTELIST;
		if (!attributeList.exists()) {
			EntityPlayer player = (EntityPlayer) Minecraft.getMinecraft().thePlayer;
			AttributeModifier modifier = new AttributeModifier(entity.getUniqueID(), "maxHealthModifier",
					newHealth, 0);
			if (modifier != null) {
				entity.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.maxHealth)
						.applyModifier(modifier);
			}
		}
	}
}
}

 

EDIT 2: Solved, I just changed the event to LivingSpawnEvent and added a .removeAllModifiers(); method over the .applyModifier(modifier) one.

Guest
This topic is now closed to further replies.

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.