Jump to content

Recommended Posts

Posted

Hello Forge, My problem is that "ret.add(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, this.getFleeceColor().getMetadata()));" and the Item I want my mob to drop when sheared is not a block(because of Item.getItemFromBlock) but a pure Item itself,  I tried setting it to my Item according to breed but when I shear my mob it drops and untexured block with the same en_US.lang name, when I place it on the ground game crashes.

Posted

You've been here long enough to know that without code, we can't help you.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
Just now, Draco18s said:

You've been here long enough to know that without code, we can't help you.

@Override
    public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) {
        return !this.isChild();
    }

    @Override
    public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
        this.setTamed(true);
        int i = 1 + this.rand.nextInt(3);

        java.util.List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
        for (int j = 0; j < i; ++j)
            ret.add(new ItemStack(Item.getItemFromBlock(ModItems.JadeDragonScales), 1, this.getBreedType().getMeta()));

        this.playSound(SoundEvents.ENTITY_SHEEP_SHEAR, 1.0F, 1.0F);
        return ret;
    }

 

Also I want to know what to replace getItemFromBlock to make it use an Item instead of a block.

Posted
4 minutes ago, TheRPGAdventurer said:

Item.getItemFromBlock(ModItems.JadeDragonScales)

Item::getItemFromBlock as the name implies gets you an Item from a Block. Unless ModItems.JadeDragonScales is a Block(and if it is why is it located in the ModItems class?) you are not doing things correctly.

 

4 minutes ago, TheRPGAdventurer said:

I want to know what to replace getItemFromBlock to make it use an Item instead of a block.

Just pass your ModItems.JadeDragonScales to the ItemStack constructor directly, it will figure everything out for you.

  • Like 1
Posted
Just now, V0idWa1k3r said:

Item::getItemFromBlock as the name implies gets you an Item from a Block. Unless ModItems.JadeDragonScales is a Block(and if it is why is it located in the ModItems class?) you are not doing things correctly.

 

Just pass your ModItems.JadeDragonScales to the ItemStack constructor directly, it will figure everything out for you.

If I fixed It i will try to reply with the code to make kids or unexperienced Modders understand, also how do I change the title of this post so it can be easily found by other modders?

Posted
9 minutes ago, TheRPGAdventurer said:

also how do I change the title of this post so it can be easily found by other modders?

 

Edit the first post of a thread to edit the thread's title.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
Just now, V0idWa1k3r said:

Item::getItemFromBlock as the name implies gets you an Item from a Block. Unless ModItems.JadeDragonScales is a Block(and if it is why is it located in the ModItems class?) you are not doing things correctly.

 

Just pass your ModItems.JadeDragonScales to the ItemStack constructor directly, it will figure everything out for you.

also what does that 1 number do?

Posted
1 minute ago, TheRPGAdventurer said:

also what does that 1 number do?

Look at the constructor of the ItemStack, the names of parameters are pretty descriptive. That 1 in particular is the amount of items in the stack

  • Like 1
Posted
Just now, V0idWa1k3r said:

Look at the constructor of the ItemStack, the names of parameters are pretty descriptive. That 1 in particular is the amount of items in the stack

dude

public boolean getSheared()
    {
        return (((Byte)this.dataManager.get(DYE_COLOR)).byteValue() & 16) != 0;
    }

    /**
     * make a sheep sheared if set to true
     */
   

 

public void setSheared(boolean sheared)
    {
        byte b0 = ((Byte)this.dataManager.get(DYE_COLOR)).byteValue();

        if (sheared)
        {
            this.dataManager.set(DYE_COLOR, Byte.valueOf((byte)(b0 | 16)));
        }
        else
        {
            this.dataManager.set(DYE_COLOR, Byte.valueOf((byte)(b0 & -17)));
        }
    }

 

what do I do with these methods, I don't have some sort of data for them, but I still want it to be sheared and wait 3 ints,

Posted
Just now, V0idWa1k3r said:

Please elaborate on what you are trying to achieve.

I want to make it shear once and wait another time using this on onSheared method,

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

 without knowing what to put on set Sheared method above and getSheared above, it doesn't work

Posted

What is you problem exactly? Just store the delay value somewhere, decrement it each tick/time period and as it reaches 0 set the mob as not sheared(presumably by calling setSheared(false)). You don't even need a DataManager for that as the client does not need to know about the delay(unless you want it to for some rendering or something, then you need another DataParameter).  Kinda how sheep does it at EntitySheep::eatGrassBonus. 

Posted (edited)
Just now, TheRPGAdventurer said:

I want to make it shear once and wait another time using this on onSheared method,

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

 without knowing what to put on set Sheared method above and getSheared above, it doesn't work

because I don't have the data like the wool block;

 

Edit: delayed

Edited by TheRPGAdventurer
Delayed
Posted
3 minutes ago, TheRPGAdventurer said:

I don't have the data like the wool block

I assume that you can't use these methods as you do not have the DYE_COLOR data parameter as you manage your sheared items differently and don't exatcly store the wool color anywhere, correct? You do not need these methods then. Simply store your delay and it can be your isSheared indicator aswell - if it is at 0 the mob is not sheared and if it is anything else then the mob was sheared.

  • Like 1
Posted
Just now, V0idWa1k3r said:

I assume that you can't use these methods as you do not have the DYE_COLOR data parameter as you manage your sheared items differently and don't exatcly store the wool color anywhere, correct? You do not need these methods then. Simply store your delay and it can be your isSheared indicator aswell - if it is at 0 the mob is not sheared and if it is anything else then the mob was sheared.

sorry sir it was delayed; bad typhoon in our country causing slow Internet, I was programming in the middle of the storm, while my family is panicking from lightnings and thunders,

Posted
Just now, V0idWa1k3r said:

I assume that you can't use these methods as you do not have the DYE_COLOR data parameter as you manage your sheared items differently and don't exatcly store the wool color anywhere, correct? You do not need these methods then. Simply store your delay and it can be your isSheared indicator aswell - if it is at 0 the mob is not sheared and if it is anything else then the mob was sheared.

How do I make my mob shift right clicking to ride it, it was conflicting with my shearing method because right clicking to shear and right clicking to ride and I want my mob to be right clicked when riding it,

Posted
Just now, TheRPGAdventurer said:

it was conflicting with my shearing method because right clicking to shear and right clicking to ride

In what way? You can simply check if the player is holding shears or not. If they are - run the shearing code, if they are not - ride your entity.

Posted
Just now, V0idWa1k3r said:

In what way? You can simply check if the player is holding shears or not. If they are - run the shearing code, if they are not - ride your entity.

when my dragon is saddled and tamed and right clicked it with a shear I actually ride the dragon, I want to make it in a way that I need to Shift right click or press middle mouse when riding the saddled dragon,

Posted
Just now, TheRPGAdventurer said:

when my dragon is saddled and tamed and right clicked it with a shear I actually ride the dragon, I want to make it in a way that I need to Shift right click or press middle mouse when riding the saddled dragon,

also can you tell me what's wrong with this 

    public boolean setSheared(boolean sheared)  {
        return false;
    }
    
    public boolean getSheared() {
        return false;
    }

    @Override 
    public boolean isShearable(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos) { 
        return !this.getSheared() && !this.isChild(); }
    @Override
    public java.util.List<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune)
    {
        this.setSheared(true);
        int i = 1 + this.rand.nextInt(3);

        java.util.List<ItemStack> ret = new java.util.ArrayList<ItemStack>();
        for (int j = 0; j < i; ++j)
            ret.add(new ItemStack(this.getDropItem(), 1));

        this.playSound(SoundEvents.ENTITY_SHEEP_SHEAR, 1.0F, 1.0F);
        return ret;
    }
}

 

it gives me in the console a FATAL ERROR yet it still drops the item I set to it.         

Posted (edited)

If you want a custom keybind you can't use the default methods, you will need custom packets. 

The problem with shift-right clicking is that shift is the default keybind to stop riding an entity(or rather it is a sneak keybind and sneaking is what makes you dismount) and that is defined in EntityPlayer so you can't change that.

 

6 minutes ago, TheRPGAdventurer said:

public boolean setSheared(boolean sheared)  {
        return false;
    }

?

 

6 minutes ago, TheRPGAdventurer said:

public boolean getSheared() {
        return false;
    }

If you are creating getters and setters make them have a purpose. 

 

6 minutes ago, TheRPGAdventurer said:

it gives me in the console a FATAL ERROR

Post the log then.

Edited by V0idWa1k3r
Posted
Just now, V0idWa1k3r said:

If you want a custom keybind you can't use the default methods, you will need custom packets. 

The problem with shift-right clicking is that shift is the default keybind to stop riding an entity(or rather it is a sneak keybind and sneaking is what makes you dismount) and that is defined in EntityPlayer so you can't change that.

 

?

 

If you are creating getters and setters make them have a purpose. 

 

Post the log then.

1. what do you mean give them a purpose? I  don't have the data like in the wool blocks of the sheep, some sort of return them to true?

 

Posted
Just now, TheRPGAdventurer said:

what do you mean give them a purpose?

I literally mean to give them a purpose. Why do you have a method that does nothing? If you do not need them - drop them, you are returning false to begin with and that is a constant value. If you want them to do something - introduce the code to do so. 

2 minutes ago, TheRPGAdventurer said:

I  don't have the data like in the wool blocks of the sheep

That is irrelevant. The names of methods imply that they are getters and setters for whether your entity was sheared or not. If you do not need them - delete them, this is your own code. If they are supposed to be setters and getters for a value - introduce that value with a field or a DataParameter in the DataManager. This is a basic java concept.

 

I'm not telling you to do that because of code cleanup or something like that. I'm telling you to do so because you are still using those methods as getters and setters which they are not in their current implementation and that can lead to potential issues.

Posted
Just now, V0idWa1k3r said:

I literally mean to give them a purpose. Why do you have a method that does nothing? If you do not need them - drop them, you are returning false to begin with and that is a constant value. If you want them to do something - introduce the code to do so. 

That is irrelevant. The names of methods imply that they are getters and setters for whether your entity was sheared or not. If you do not need them - delete them, this is your own code. If they are supposed to be setters and getters for a value - introduce that value with a field or a DataParameter in the DataManager. This is a basic java concept.

 

I'm not telling you to do that because of code cleanup or something like that. I'm telling you to do so because you are still using those methods as getters and setters which they are not in their current implementation and that can lead to potential issues.

how abut this one?

private boolean getSheared() {
        return true;
    }
    
    public boolean setSheared(boolean sheared) {
        return sheared;
    }

Posted
Just now, TheRPGAdventurer said:

how abut this one?

private boolean getSheared() {
        return true;
    }
    
    public boolean setSheared(boolean sheared) {
        return sheared;
    }

Okay now I fixed it's riding and shearing ability without changing the controls.

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.