My custom mob pushes other mobs just by turning around, making them float with their head on the ground.

Started by James Sylar on

Topic category: Advanced modding

Last seen on 05:23, 7. Jul 2021
Joined Feb 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
My custom mob pushes other mobs just by turning around, making them float with their head on the ground.

Hello there, I'm making a custom mob using a model I made in Blockbench since I couldn't open Tabula, and I managed to make it work by using parts of the biped code (I posted the tutorial already), but the other mobs starts to act weird, sliding when the one I made turns its head and being pushed when they walk, among other things. Also, when I attack/kill them, the screen tints red. Can someone check my code and see if I'm making a mistake? I don't know coding, I just frankenstein it until it worked more or less, but I don't know what else I should try. 

package mod.mcreator;

import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.World;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.EnumHand;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.monster.EntityZombieVillager;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.ai.EntityAIWanderAvoidWater;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIOpenDoor;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIMoveIndoors;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAIAvoidEntity;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.Minecraft;

import java.util.Iterator;
import java.util.HashMap;
import java.util.ArrayList;

public class mcreator_redDiamondLustrous extends lustrousmod.ModElement {

	public static int mobid = 1;
	public static int mobid2 = 2;

	@Override
	public void preInit(FMLPreInitializationEvent event) {
		EntityRegistry.registerModEntity(new ResourceLocation("lustrousmod:reddiamondlustrous"), EntityredDiamondLustrous.class,
				"reddiamondlustrous", mobid, instance, 64, 1, true, -65536, -16777216);
	}

	private Biome[] allbiomes(net.minecraft.util.registry.RegistryNamespaced<ResourceLocation, Biome> in) {
		Iterator<Biome> itr = in.iterator();
		ArrayList<Biome> ls = new ArrayList<Biome>();
		while (itr.hasNext())
			ls.add(itr.next());
		return ls.toArray(new Biome[ls.size()]);
	}

	@Override
	public void registerRenderers() {
		RenderLiving customRender = new RenderLiving(Minecraft.getMinecraft().getRenderManager(), new ModelLustrous3(), 0) {

			protected ResourceLocation getEntityTexture(Entity par1Entity) {
				return new ResourceLocation("lustrous2.png");
			}
		};
		RenderingRegistry.registerEntityRenderingHandler(EntityredDiamondLustrous.class, customRender);
	}

	public static class EntityredDiamondLustrous extends EntityWolf {

		public EntityredDiamondLustrous(World world) {
			super(world);
			setSize(0.6f, 1.95f);
			experienceValue = 7;
			this.isImmuneToFire = true;
			setNoAI(!true);
			enablePersistence();
			this.tasks.addTask(1, new EntityAIWander(this, 1));
			this.tasks.addTask(2, new EntityAIWanderAvoidWater(this, 0.8));
			this.tasks.addTask(3, new EntityAILookIdle(this));
			this.tasks.addTask(4, new EntityAISwimming(this));
			this.tasks.addTask(5, new EntityAILeapAtTarget(this, (float) 0.8));
			this.targetTasks.addTask(6, new EntityAIHurtByTarget(this, true));
			this.targetTasks.addTask(7, new EntityAINearestAttackableTarget(this, EntitySkeleton.class, true, true));
			this.targetTasks.addTask(8, new EntityAINearestAttackableTarget(this, EntityZombie.class, true, true));
			this.targetTasks.addTask(9, new EntityAINearestAttackableTarget(this, EntityZombieVillager.class, true, true));
			this.tasks.addTask(10, new EntityAITempt(this, 1, new ItemStack(mcreator_redDiamondShards.block, (int) (1)).getItem(), true));
			this.tasks.addTask(11, new EntityAIAvoidEntity(this, EntityCreeper.class, (float) 6, 1, 1.2));
			this.tasks.addTask(12, new EntityAIOpenDoor(this, true));
			this.tasks.addTask(13, new EntityAIOpenDoor(this, false));
			this.tasks.addTask(14, new EntityAIMoveIndoors(this));
		}

		@Override
		public EnumCreatureAttribute getCreatureAttribute() {
			return EnumCreatureAttribute.UNDEFINED;
		}

		@Override
		protected boolean canDespawn() {
			return false;
		}

		@Override
		protected Item getDropItem() {
			return new ItemStack(mcreator_redDiamondShards.block, (int) (1)).getItem();
		}

		@Override
		public net.minecraft.util.SoundEvent getAmbientSound() {
			return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation(""));
		}

		@Override
		public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
			return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.irongolem.hurt"));
		}

		@Override
		public net.minecraft.util.SoundEvent getDeathSound() {
			return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.irongolem.death"));
		}

		@Override
		protected float getSoundVolume() {
			return 1.0F;
		}

		@Override
		public boolean attackEntityFrom(DamageSource source, float amount) {
			boolean retval = super.attackEntityFrom(source, amount);
			int x = (int) this.posX;
			int y = (int) this.posY;
			int z = (int) this.posZ;
			Entity entity = this;
			{
				java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
				$_dependencies.put("x", x);
				$_dependencies.put("y", y);
				$_dependencies.put("z", z);
				$_dependencies.put("world", world);
				mcreator_redDiaDamage.executeProcedure($_dependencies);
			}
			return retval;
		}

		@Override
		public boolean processInteract(EntityPlayer entity, EnumHand hand) {
			boolean retval = super.processInteract(entity, hand);
			int x = (int) this.posX;
			int y = (int) this.posY;
			int z = (int) this.posZ;
			ItemStack itemstack = entity.getHeldItem(hand);
			{
				java.util.HashMap<String, Object> $_dependencies = new java.util.HashMap<>();
				$_dependencies.put("entity", entity);
				mcreator_redDiaCure.executeProcedure($_dependencies);
			}
			return retval;
		}
	}

	// Made with Blockbench
	// Paste this code into your mod.
	public static class ModelLustrous3 extends ModelBase {

		private final ModelRenderer head;
		private final ModelRenderer body;
		private final ModelRenderer leftArm;
		private final ModelRenderer rightArm;
		private final ModelRenderer leftLeg;
		private final ModelRenderer rightLeg;
		public ModelLustrous3.ArmPose leftArmPose;
		public ModelLustrous3.ArmPose rightArmPose;
		public boolean isSneak;
		public ModelRenderer Headwear;

		public ModelLustrous3() {
			this(1.0F);
		}

		public ModelLustrous3(float modelSize) {
			this(modelSize, 1.0F, 56, 32);
		}

		public ModelLustrous3(float modelSize, float p_i1149_2_, int textureWidthIn, int textureHeightIn) {
			textureWidth = 56;
			textureHeight = 32;
			this.leftArmPose = ModelLustrous3.ArmPose.EMPTY;
			this.rightArmPose = ModelLustrous3.ArmPose.EMPTY;
			this.head = new ModelRenderer(this);
			this.head.setRotationPoint(-4.0F, 1.0F, 2.0F);
			this.head.cubeList.add(new ModelBox(head, 0, 0, -4.0F, -9.0F, -3.0F, 8, 8, 6, 0.0F, false));
			this.head.cubeList.add(new ModelBox(head, 28, 2, -1.5F, -1.0F, -2.0F, 3, 1, 4, 0.0F, false));
			this.head.cubeList.add(new ModelBox(head, 0, 0, -3.0F, -10.0F, -3.0F, 6, 1, 6, 0.0F, false));
			this.head.cubeList.add(new ModelBox(head, 25, 20, -5.0F, -8.0F, -2.5F, 1, 6, 5, 0.0F, false));
			this.head.cubeList.add(new ModelBox(head, 25, 20, 4.0F, -8.0F, -2.5F, 1, 6, 5, 0.0F, false));
			this.head.cubeList.add(new ModelBox(head, 39, 25, -3.0F, -8.0F, 3.0F, 6, 6, 1, 0.0F, false));
			this.body = new ModelRenderer(this);
			this.body.setRotationPoint(-4.0F, 7.3F, 2.0F);
			this.body.cubeList.add(new ModelBox(body, 0, 16, -4.0F, -6.3F, -2.0F, 8, 5, 4, 0.0F, false));
			this.body.cubeList.add(new ModelBox(body, 0, 25, -3.0F, -1.3F, -2.0F, 6, 3, 4, 0.0F, false));
			this.body.cubeList.add(new ModelBox(body, 32, 16, -4.0F, 1.7F, -2.0F, 8, 3, 4, 0.0F, false));
			this.body.cubeList.add(new ModelBox(body, 4, 13, -3.5F, -1.3F, -2.0F, 0, 3, 4, 0.0F, false));
			this.body.cubeList.add(new ModelBox(body, 7, 13, 3.0F, -1.3F, -2.0F, 0, 3, 4, 0.0F, false));
			this.body.cubeList.add(new ModelBox(body, 32, 0, -1.0F, -6.3F, -2.5F, 2, 5, 0, 0.0F, false));
			this.leftArm = new ModelRenderer(this);
			this.leftArm.setRotationPoint(-8.0F, 1.0F, 1.0F);
			this.leftArm.cubeList.add(new ModelBox(leftArm, 42, 2, -2.0F, 0.0F, 0.0F, 2, 12, 2, 0.0F, false));
			this.rightArm = new ModelRenderer(this);
			this.rightArm.setRotationPoint(0.0F, 1.0F, 1.0F);
			this.rightArm.cubeList.add(new ModelBox(rightArm, 42, 2, 0.0F, 0.0F, 0.0F, 2, 12, 2, 0.0F, false));
			this.leftLeg = new ModelRenderer(this);
			this.leftLeg.setRotationPoint(-2.2167F, 11.8333F, 1.3333F);
			this.leftLeg.cubeList.add(new ModelBox(leftLeg, 28, 0, -1.1833F, 0.1667F, -1.3333F, 3, 12, 4, 0.0F, false));
			this.rightLeg = new ModelRenderer(this);
			this.rightLeg.setRotationPoint(-5.75F, 11.8333F, 1.3333F);
			this.rightLeg.cubeList.add(new ModelBox(rightLeg, 28, 0, -2.25F, 0.1667F, -1.3333F, 3, 12, 4, 0.0F, false));
		}

		@Override
		public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
			this.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entityIn);
			GlStateManager.pushMatrix();
			if (this.isChild) {
				float f = 2.0F;
				GlStateManager.scale(0.75F, 0.75F, 0.75F);
				GlStateManager.translate(0.0F, 16.0F * scale, 0.0F);
				this.head.render(scale);
				GlStateManager.popMatrix();
				GlStateManager.pushMatrix();
				GlStateManager.scale(0.5F, 0.5F, 0.5F);
				GlStateManager.translate(0.0F, 24.0F * scale, 0.0F);
				this.body.render(scale);
				this.rightArm.render(scale);
				this.leftArm.render(scale);
				this.rightLeg.render(scale);
				this.leftLeg.render(scale);
				this.Headwear.render(scale);
			} else {
				if (entityIn.isSneaking()) {
					GlStateManager.translate(0.0F, 0.2F, 0.0F);
				}
				this.head.render(scale);
				this.body.render(scale);
				this.rightArm.render(scale);
				this.leftArm.render(scale);
				this.rightLeg.render(scale);
				this.leftLeg.render(scale);
				this.Headwear.render(scale);
			}
			GlStateManager.popMatrix();
		}

		public void setModelAttributes(ModelBase model) {
			super.setModelAttributes(model);
			if (model instanceof ModelLustrous3) {
				ModelLustrous3 modellustrous3 = (ModelLustrous3) model;
				this.leftArmPose = modellustrous3.leftArmPose;
				this.rightArmPose = modellustrous3.rightArmPose;
				this.isSneak = modellustrous3.isSneak;
			}
		}

		public void setVisible(boolean visible) {
			this.head.showModel = visible;
			this.Headwear.showModel = visible;
			this.body.showModel = visible;
			this.rightArm.showModel = visible;
			this.leftArm.showModel = visible;
			this.rightLeg.showModel = visible;
			this.leftLeg.showModel = visible;
		}

		public void postRenderArm(float scale, EnumHandSide side) {
			this.getArmForSide(side).postRender(scale);
		}

		protected ModelRenderer getArmForSide(EnumHandSide side) {
			return side == EnumHandSide.LEFT ? this.leftArm : this.rightArm;
		}

		protected EnumHandSide getMainHand(Entity entityIn) {
			if (entityIn instanceof EntityLivingBase) {
				EntityLivingBase entitylivingbase = (EntityLivingBase) entityIn;
				EnumHandSide enumhandside = entitylivingbase.getPrimaryHand();
				return entitylivingbase.swingingHand == EnumHand.MAIN_HAND ? enumhandside : enumhandside.opposite();
			} else {
				return EnumHandSide.RIGHT;
			}
		}

		@SideOnly(Side.CLIENT)
		public static enum ArmPose {
			EMPTY, ITEM, BLOCK, BOW_AND_ARROW;
		}

		public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e) {
			super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
		}
	}
}

 

Last seen on 20:43, 14. Feb 2024
Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
??? What did you write?…
Thu, 02/21/2019 - 17:15

???

What did you write?

There are so many arguments here that simply aren't necessary for a normal mob.

Last seen on 05:23, 7. Jul 2021
Joined Feb 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It is a mess, I know.  I'll…
Mon, 02/25/2019 - 04:22

It is a mess, I know.  I'll say that up until the model I didn't change much, just added a few lines here and there from other examples I found,  and copied from "public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {" from the biped model. 

 

I think I fixed the main problem I had by deleting all the mentions of "Headwear", but now I have a problem with this part:

@SideOnly(Side.CLIENT)
		public static enum ArmPose {
			EMPTY, ITEM, BLOCK, BOW_AND_ARROW;
		}

I'll probably make another post if I don't find any solution, thank you anyways. 

 

 

Last seen on 05:23, 7. Jul 2021
Joined Feb 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ah! But if you can tell me…
Mon, 02/25/2019 - 04:27

Ah! But if you can tell me what it is unnecesary and I can delete, I'll be very grateful.