Jump to content

[1.7.10] Spawning entity with item - onItemUse


KakesRevenge

Recommended Posts

Hi,

Im trying to make some kind of ritual which will spawn wither ...

this is my item class

 

 

package fewmorethings.items;

 

import net.minecraft.block.Block;

import net.minecraft.entity.boss.EntityWither;

import net.minecraft.entity.effect.EntityLightningBolt;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.ItemStack;

import net.minecraft.util.IIcon;

import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import fewmorethings.help.LogHelper;

import fewmorethings.items.bases.ItemBase;

 

public class TestItem extends ItemBase {

 

public TestItem () {

this.setUnlocalizedName("TestItem");

}

 

 

@Override

public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par1, float par2, float par3, float par4) {

Block blockoneye = world.getBlock(x, y, z);

if(!world.isRemote) {

if(blockoneye == Blocks.iron_block && this.checkRitualBlocks(x, y, z, world)) {

LogHelper.info("DEBUG");

EntityWither wither = new EntityWither(world);

world.spawnEntityInWorld(wither);

}

}

return true;

}

 

@SideOnly(Side.CLIENT)

    public IIcon getIcon(ItemStack i, int j) {

        return Items.stick.getIcon(i, j);

    }

 

private boolean checkRitualBlocks(int x, int y,int z, World world) {

if(world.getBlock(x, y, z - 1) == Blocks.obsidian &&

  world.getBlock(x, y, z + 1) == Blocks.obsidian &&

  world.getBlock(x + 1, y, z) == Blocks.obsidian &&

  world.getBlock(x - 1, y, z) == Blocks.obsidian &&

 

  world.getBlock(x - 1, y, z - 1) == Blocks.glowstone &&

  world.getBlock(x + 1, y, z - 1) == Blocks.glowstone &&

  world.getBlock(x + 1, y, z - 1) == Blocks.glowstone &&

  world.getBlock(x + 1, y, z + 1) == Blocks.glowstone &&

 

  world.getBlock(x - 4, y + 1, z - 1) == Blocks.quartz_block &&

  world.getBlock(x - 4, y + 2, z - 1) == Blocks.quartz_block &&

  world.getBlock(x - 4, y + 3, z - 1) == Blocks.diamond_block &&

 

  world.getBlock(x - 4, y + 1, z + 2) == Blocks.quartz_block &&

  world.getBlock(x - 4, y + 2, z + 2) == Blocks.quartz_block &&

  world.getBlock(x - 4, y + 3, z + 2) == Blocks.diamond_block &&

 

  world.getBlock(x + 4, y + 1, z + 1) == Blocks.quartz_block &&

  world.getBlock(x + 4, y + 2, z + 1) == Blocks.quartz_block &&

  world.getBlock(x + 4, y + 3, z + 1) == Blocks.diamond_block &&

 

  world.getBlock(x + 1, y + 1, z + 4) == Blocks.quartz_block &&

  world.getBlock(x + 1, y + 2, z + 4) == Blocks.quartz_block &&

  world.getBlock(x + 1, y + 3, z + 4) == Blocks.beacon &&

 

  world.getBlock(x - 1, y + 1, z - 4) == Blocks.quartz_block &&

  world.getBlock(x - 1, y + 2, z - 4) == Blocks.quartz_block &&

  world.getBlock(x - 1, y + 3, z - 4) == Blocks.beacon) {

return true;

}

return false;

}

}

 

 

 

 

 

The word DEBUG will be actually printed out but the wither will not spawn

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

You use the alternative constructor.

 

Edit: I just found out there's no alternative constructor, so you'd have to set the position manually using

entity.posX/Y/Z = ?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

no idea why but this is not working

wither.setPosition(x, y, z);

this one either

wither.posX = x;
wither.posY = y;
wither.posZ = z;

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Link to comment
Share on other sites

this isnt working

 

@Override

public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par1, float par2, float par3, float par4) {

Block blockoneye = world.getBlock(x, y, z);

if(!world.isRemote) {

if(blockoneye == Blocks.iron_block && this.checkRitualBlocks(x, y, z, world)) {

LogHelper.info("DEBUG");

EntityPlayer p = worldObj.getClosestPlayer(xCoord, yCoord, zCoord, 100);

                float yaw = p.rotationYaw;

                float pitch = p.rotationPitch;

EntityWither wither = new EntityWither(world);

world.spawnEntityInWorld(wither);

wither.setLocationAndAngles(x, y, z, yaw, pitch);

}

}

return true;

}

 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

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.



×
×
  • Create New...

Important Information

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