Jump to content

Recommended Posts

Posted

Hey,

Im trying to find out what wool color a particular sheep has.

So when I right click the sheep, I want to get the color it has.

And I want to make the sheep sheared when I get the wool out of it.

 

Any ideas will be appreciated :)

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 :)

Posted

i have looked and i dont understand it :/

this is the interactwithentity method in ItemShears

 

 

@Override

    public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)

    {

        if (entity.worldObj.isRemote)

        {

            return false;

        }

        if (entity instanceof IShearable)

        {

            IShearable target = (IShearable)entity;

            if (target.isShearable(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ))

            {

                ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,

                        EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));

 

                Random rand = new Random();

                for(ItemStack stack : drops)

                {

                    EntityItem ent = entity.entityDropItem(stack, 1.0F);

                    ent.motionY += rand.nextFloat() * 0.05F;

                    ent.motionX += (rand.nextFloat() - rand.nextFloat()) * 0.1F;

                    ent.motionZ += (rand.nextFloat() - rand.nextFloat()) * 0.1F;

                }

                itemstack.damageItem(1, entity);

            }

            return true;

        }

        return false;

    }

 

 

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 :)

Posted
 ArrayList<ItemStack> drops = target.onSheared(itemstack, entity.worldObj, (int)entity.posX, (int)entity.posY, (int)entity.posZ,
                        EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemstack));

Shears call

IShearable#onSheared

, and sheep implement that interface. So go to

EntitySheep#onSheared

and look how they figure out the color of the sheep.

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/

Posted

ok thank you it looks like this :

 

 

@Override

    public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune)

    {

        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

        setSheared(true);

        int i = 1 + rand.nextInt(3);

        for (int j = 0; j < i; j++)

        {

            ret.add(new ItemStack(Blocks.wool, 1, getFleeceColor()));

        }

        this.playSound("mob.sheep.shear", 1.0F, 1.0F);

        return ret;

    }

 

 

But i cant get the datawatcher in

 

public int getFleeceColor()
    {
        return EntitySheep.getDataWatcher().getWatchableObjectByte(16) & 15;
    }

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 :)

Posted

This is what ive got so far ... but its crashing

public class ClayBucketHandler {

    protected DataWatcher dataWatcher;
    
    public boolean getSheared()
    {
        return (this.dataWatcher.getWatchableObjectByte(16) & 16) != 0;
    }
    
@SubscribeEvent
    public void EntityInteract(EntityInteractEvent event) {
	if(event.target instanceof EntitySheep) {
		Item equipped = event.entityPlayer.getCurrentEquippedItem().getItem();
		EntityPlayer player = event.entityPlayer;
		int color = dataWatcher.getWatchableObjectByte(16) & 15;
	    if(equipped == ItemsHandler.ClayBucketFired) {
	    	player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(ItemsHandler.ClayBucketWool));
	    	player.inventory.addItemStackToInventory(new ItemStack(Blocks.wool, 1, color ));
	    	
		}
	}

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 :)

Posted

Thats my eventhandler

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 :)

Posted

dunno if thats a problem i will do it another way

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 :)

Posted

Im stilll wondering how EXACTLY get the color of the sheep that im interacting with ...

in entitysheep class the getFleeceColor method isnt static so i cant use it...

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 :)

Posted

ok but how to get the color of the sheep taht im interacting with ?

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 :)

Posted

wow ok im ashamed of myself ..

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 :)

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.