Jump to content

Spawning an Entity


TLHPoE

Recommended Posts

In my mod, there's a block that when right clicked spawns the Monkeysaur entity:

package tlhpoe.fs.block;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import tlhpoe.fs.entity.boss.EntityMonkeysaur;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockMonkeysaurAltar extends Block {
public IIcon iSide, iTop;

public BlockMonkeysaurAltar() {
	super(Material.rock);
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int p_149691_2_) {
	if(side == 1)
		return iTop;
	return iSide;
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister p_149651_1_) {
	this.iSide = Blocks.gold_block.getBlockTextureFromSide(0);
	this.iTop = p_149651_1_.registerIcon("fs:monkeysaurAltar");
	this.blockIcon = this.iTop;
}

@Override
public boolean onBlockActivated(World w, int x, int y, int z, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
	if(!w.isRemote) {
		EntityMonkeysaur e = new EntityMonkeysaur(w);
		e.posX = x;
		e.posY = y;
		e.posZ = z;
		w.spawnEntityInWorld(e);
		w.setBlock(x, y, z, Blocks.air);
	}
	return true;
}
}

 

The problem is, the entity appears and I can't interact with it and it doesn't do anything. A few seconds later it disappears.

 

Here's the entity's code:

package tlhpoe.fs.entity.boss;

import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.boss.IBossDisplayData;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.IMob;
import net.minecraft.world.World;

public class EntityMonkeysaur extends EntityMob implements IBossDisplayData, IMob {
private static final IEntitySelector attackEntitySelector = new IEntitySelector() {
	public boolean isEntityApplicable(Entity par1Entity) {
		return par1Entity instanceof EntityLivingBase && !(par1Entity instanceof EntityMonkeysaur);
	}
};

public EntityMonkeysaur(World par1World) {
	super(par1World);
	this.setSize(0.6F * 4, 1.8F * 4);
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityLivingBase.class, 1.0D, false));
	this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityLivingBase.class, 8.0F));
	this.tasks.addTask(8, new EntityAILookIdle(this));
	this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
	this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityLivingBase.class, 0, false, false, attackEntitySelector));
	this.experienceValue = 350;
}

@Override
protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(64.0D);
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(200.0D);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
}

@Override
public void setInWeb() {
}

@Override
protected void despawnEntity() {
	this.entityAge = 0;
}

@Override
protected void fall(float par1) {
}

@Override
protected boolean isAIEnabled() {
	return true;
}
}

Kain

Link to comment
Share on other sites

I'm using 1.7.2, Minecraft stores its blocks in the Blocks class.

 

Here's where I do my entity registering:

package tlhpoe.fs.helper;

import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import tlhpoe.fs.entity.EntityIceCreeper;
import tlhpoe.fs.entity.EntityWaterCreeper;
import tlhpoe.fs.entity.boss.EntityMonkeysaur;
import tlhpoe.fs.entity.render.RenderFSCreeper;
import tlhpoe.fs.entity.render.RenderMonkeysaur;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;

public class EntityHelper {
public static void doServer() {
	doEntity(EntityIceCreeper.class, "iceCreeper", 0xFFFFFF, 0x00FFFF);
	doEntity(EntityWaterCreeper.class, "waterCreeper", 0x0F8FFF, 0x00B2FF);
	doEntity(EntityMonkeysaur.class, "monkeysaur", 0x663300, 0x472400);
}

public static void doClient() {
	doRender(EntityIceCreeper.class, new RenderFSCreeper("ice"));
	doRender(EntityWaterCreeper.class, new RenderFSCreeper("water"));
	doRender(EntityMonkeysaur.class, new RenderMonkeysaur());
}

private static void doEntity(Class<? extends Entity> clazz, String name, int bgColor, int spotColor) {
	int id = EntityRegistry.findGlobalUniqueEntityId();
	EntityRegistry.registerGlobalEntityID(clazz, name, id, bgColor, spotColor);
}

private static void doRender(Class<? extends Entity> clazz, Render render) {
	RenderingRegistry.registerEntityRenderingHandler(clazz, render);
}
}

 

I can spawn it just fine with the spawn egg.

Kain

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://mclo.gs/ZlRMU4G Still crash, help 
    • Hi, im having problem with error: Could not resolve dependency: net.minecraftforge:forge:1.20.1:userdev   im new in modding, but i tried everything, and it is still not working. all versions are correct etc.   build gradle: plugins {     id 'eclipse'     id 'idea'     id 'maven-publish'     id 'net.minecraftforge.gradle' version '[6.0,6.2)'     id 'org.parchmentmc.librarian.forgegradle' version '1.+' } version = mod_version group = mod_group_id base {     archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft {     // See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md     // Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started     mappings channel: mapping_channel, version: mapping_version          copyIdeResources = true          runs {         // applies to all the run configs below         configureEach {             workingDirectory project.file('run')             property 'forge.logging.markers', 'REGISTRIES'             // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels             property 'forge.logging.console.level', 'debug'             mods {                 "${mod_id}" {                     source sourceSets.main                 }             }         }         client {             // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.             property 'forge.enabledGameTestNamespaces', mod_id         }         server {             property 'forge.enabledGameTestNamespaces', mod_id             args '--nogui'         }                  gameTestServer {             property 'forge.enabledGameTestNamespaces', mod_id         }         data {             workingDirectory project.file('run-data')                          args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')         }     } } // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { } dependencies {     minecraft "net.minecraftforge:forge:1.20.1" } tasks.named('processResources', ProcessResources).configure {     var replaceProperties = [             minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,             forge_version: forge_version, forge_version_range: forge_version_range,             loader_version_range: loader_version_range,             mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,             mod_authors: mod_authors, mod_description: mod_description,     ]     inputs.properties replaceProperties     filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {         expand replaceProperties + [project: project]     } } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure {     manifest {         attributes([                 'Specification-Title'     : mod_id,                 'Specification-Vendor'    : mod_authors,                 'Specification-Version'   : '1', // We are version 1 of ourselves                 'Implementation-Title'    : project.name,                 'Implementation-Version'  : project.jar.archiveVersion,                 'Implementation-Vendor'   : mod_authors,                 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")         ])     }     // This is the preferred method to reobfuscate your jar file     finalizedBy 'reobfJar' } publishing {     publications {         register('mavenJava', MavenPublication) {             artifact jar         }     }     repositories {         maven {             url "file://${project.projectDir}/mcmodsrepo"         }     } } tasks.withType(JavaCompile).configureEach {     options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation }       please help me out
    • Hi, im having same issue, but it is my time creating mode, can you help out and explain more?
  • Topics

×
×
  • Create New...

Important Information

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