Jump to content

[SOLVED] Hook for custom dispenser behaviour?


Aggurai

Recommended Posts

Hello, I have a custom entity that spawns from an item, and I would like to make it so that when the item is placed in a dispenser, it shoots out the entity, like an egg or snowball.

 

I have googled this already, but only found a few other people needing to do this, but on one of them someone said to the person that there was a way to do this, but didn't tell him how.

 

I assume there probably is a way because it is implemented in modloader, and i don't want to have to overwrite DispenserBehaviours.java D:

 

Any help gladly appreciated i'm sure its probable simple

Link to comment
Share on other sites

You don't have to edit any base classes.

Just do the same thing that DispenseBehaviors is doing in your code. REGISTER your handler...

You can do that from anywhere in your code without having to have it in a base class...

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Thanks! I have now registered my Dispenser behavior, however I am using an item with metadata and need to get the damage value of the item that is going to be shot, so that I can change the entity that spawns.

 

The easy way of normally doing this without metadata would to use the code DispenserBehaviorEgg.java uses

final class DispenserBehaviorEgg extends BehaviorProjectileDispense
{
    /**
     * Return the projectile entity spawned by this dispense behavior.
     */
    protected IProjectile getProjectileEntity(World par1World, IPosition par2IPosition)
    {
        return new EntityEgg(par1World, par2IPosition.getX(), par2IPosition.getY(), par2IPosition.getZ());
    }
}

But there is no itemstack argument I can use to find the damage value.

Then I looked in the behavior for BehaviorDefaultDispenseItem, used by fireworks, mob eggs, etc so similar to what I am doing, and it has a method called

public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack)

I have tried modifying my Dispenser Behaviour to use this, and have managed to get it to shoot my custom item out, howver it does not spawn the entity that it normally does when it hits the ground (when you throw it yourself) . I know it must have got to this part of code, because it is in the same place that the particles are told to appear, and they show up fine...

 

If anyone could shed some light on this, I'd be very happy!

Link to comment
Share on other sites

Yeah, dispenser behaviors are very easy to make.  I actually made my own version of the dispenser recently (fires twice per trigger*) and has some special effects (like for fire I have it create a line of fire four wide in front of it, rather than only the first block).  I had to copy most of the net.minecraft.dispenser package to do it, but once I had that and had things registered, it was really easy to create custom behaviors.

 

*Was originally four, but seeing as there's a damage-delay only one would effect the player, so I had it trigger only twice, but do twice as much damage.  Kept it at two so that it would cause arrow clusters to pepper the walls.

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.

Link to comment
Share on other sites

  • 1 month later...

Yeah, dispenser behaviors are very easy to make.  I actually made my own version of the dispenser recently (fires twice per trigger*) and has some special effects (like for fire I have it create a line of fire four wide in front of it, rather than only the first block).  I had to copy most of the net.minecraft.dispenser package to do it, but once I had that and had things registered, it was really easy to create custom behaviors.

 

*Was originally four, but seeing as there's a damage-delay only one would effect the player, so I had it trigger only twice, but do twice as much damage.  Kept it at two so that it would cause arrow clusters to pepper the walls.

 

How did you register your dispenser behavior?  I see a putObject method in RegistrySimple, but I don't know what the second object is for.

 

Apologies for commenting on the solved thread, I'm just curious as to how you did it.

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.