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

So I am making an Entity(Monster) and when I try to change his damage automatically it doesn't work to well. I go into my mob file MonsterName.java and above the attributes code protected void applyEntityAttributes(){} I put some automatic damage changer using if statements but when I run it with no errors my entity stops working and doesn,t show up in game. is there another area I am suppose to put it?

  • Author

Here is the code

 

package com.opitems.mob;

 

import com.opitems.main.ArmorRegistry;

import com.opitems.main.ItemRegistry;

import com.opitems.main.ToolRegistry;

import com.sun.javafx.scene.text.HitInfo;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIMoveThroughVillage;

import net.minecraft.entity.ai.EntityAISwimming;

import net.minecraft.entity.boss.IBossDisplayData;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.init.Items;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.EnumDifficulty;

import net.minecraft.world.World;

import net.minecraftforge.common.ForgeModContainer;

 

public class opWarriorBoss extends EntityMob{

 

public opWarriorBoss(World world) {

super(world);

 

this.tasks.addTask(0, new EntityAISwimming(this));

        this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));

}

public static double damage = 160.0;

public void changeDamage(){

if(damage < 300.0D && hitByEntity(getLastAttacker())){

damage++;

}

}

 

 

protected void applyEntityAttributes(){

super.applyEntityAttributes();

this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(3000.0D);

this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);

this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(damage);

this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(64.0D);

this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.5D);

}

protected void dropFewItems(boolean p_70628_1_, int p_70628_2_)

    {

switch(this.rand.nextInt(3)){

case 0:

this.dropItem(ToolRegistry.opSword, 1);

break;

case 1:

this.dropItem(ToolRegistry.opSword2, 1);

break;

case 2:

this.dropItem(ToolRegistry.opSword2, 1);

}

       

    }

protected void dropRareDrop(int p_70600_1_)

    {

        switch (this.rand.nextInt(3))

        {

            case 0:

                this.dropItem(Items.nether_star, 5);

                break;

            case 1:

                this.dropItem(ArmorRegistry.opChestplate, 1);

                break;

            case 2:

                this.dropItem(ItemRegistry.opGem, 10);

        }

    }

protected void addRandomArmor()

    {

        super.addRandomArmor();

 

        if (this.rand.nextFloat() < (this.worldObj.difficultySetting == EnumDifficulty.HARD ? 0.05F : 0.01F))

        {

            int i = this.rand.nextInt(3);

 

            if (i == 0)

            {

                this.setCurrentItemOrArmor(0, new ItemStack(ToolRegistry.opSword));

            }

            else

            {

                this.setCurrentItemOrArmor(0, new ItemStack(ToolRegistry.opShovel));

            }

        }

    }

}

 

Some logical help here:

SharedMonsterAttributes - BASIC value of attribute shared between ALL entities using this class.

AttributeModifier - a modifier saved in map that is actually assigned to entity, there you can edint this basic attribute and that's what you should use for you damage editing.

write/readNBT() methods - here you will need to save/load entitie's NBT data to make it be custom.

Static - after you read what it is, I will just add - in MC you should almost NEVER use static fields (unless they are actually static), so basically never in Item, Block, Entity, some other.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Hey thanks for the tip but I've never used a NBT, heard of it though. Would it be OK if I got a skeleton of the method? Thanks if not anyway though.  Also to you and shield thanks for informing me on static variables.

 

The NBT classes are just a unified way for Minecraft objects to serialize data. Serialized means that it can be written to disk. You can store all of the simple data types (integers, floats, strings) as well as NBT objects.

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.

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.