Jump to content

Why isn't my mob spawning code working?


MrDireball

Recommended Posts

So I've got some simple code that should spawn in a zombie in the onBlockActivated method of my block, but it doesn't seem to be doing anything, even though I could spawn in item entities just fine.

 

                EntityZombie mobEntity = new EntityZombie(world);
                mobEntity.setPosition(pos.getX(), pos.getZ(), pos.getZ());
                world.spawnEntity(mobEntity);

 

Also, if someone could tell me how to properly post code, that would be great.

Edited by MrDireball
Link to comment
Share on other sites

5 hours ago, diesieben07 said:

Show more of your code.

 

You can do the following to post code (ordered from best to "worst"):

  1. Create a Git repository of your code.
  2. Use Github Gists.
  3. Use pastebin.com or similar.
  4. Use the Code-Button on the forum editor (opening and closing angle bracket icon).
    @Override
    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
                EnumFacing side, float hitX, float hitY, float hitZ) {
        if (!world.isRemote) {
            if (side == state.getValue(FACING)) {
                //world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.DIAMOND)));
                                                                                       
    		    EntityZombie mobEntity = new EntityZombie(world);
    		    mobEntity.setPosition(pos.getX(), pos.getZ(), pos.getZ());
    		    world.spawnEntity(mobEntity);
            }
        }
        return true;
    }

 

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.

Announcements



×
×
  • Create New...

Important Information

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