Jump to content

Recommended Posts

Posted

I have put the past 5-6 hours into looking for a way to dispense a throwable entity instead of a throwable entities' item.

 

I have created a class within a new package/folder like so:

 

package guru.tbe.entity.DispenseProjectiles;

import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;

public abstract class BehaviorDispense extends BehaviorDefaultDispenseItem
{
    /**
     * Dispense the specified stack, play the dispense sound and spawn particles.
     */
    public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
    {
        World world = source.getWorld();
        IPosition iposition = BlockDispenser.getDispensePosition(source);
        EnumFacing enumfacing = (EnumFacing)source.func_189992_e().getValue(BlockDispenser.FACING);
        IProjectile iprojectile = this.getProjectileEntity(world, iposition, stack);
        iprojectile.setThrowableHeading((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy());
        world.spawnEntityInWorld((Entity)iprojectile);
        stack.splitStack(1);
        return stack;
    }

    /**
     * Play the dispense sound from the specified block.
     */
    protected void playDispenseSound(IBlockSource source)
    {
        source.getWorld().playEvent(1002, source.getBlockPos(), 0);
    }

    /**
     * Return the projectile entity spawned by this dispense behavior.
     */
    protected abstract IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn);

    protected float getProjectileInaccuracy()
    {
        return 6.0F;
    }

    protected float getProjectileVelocity()
    {
        return 1.1F;
    }
}

 

I have been reading for hours and I still don't know where to go from here, or what to do next.

To be honest I've been looking for a way to solve this for months... and I haven't been able to find any info that actually helps with accomplishing this task.

 

Any help is nice.  ???

Posted

You need to actually make a real projectile class, i.e. not an abstract one. Easiest way is to extend EntityThrowable and override #onImpact to do what you want; remember to register the entity and entity renderer classes.

 

Then in your dispenser behavior implementation, create a new YourThrowableEntity instance and spawn it.

 

And yes, you have to register your dispenser behavior - the following was in 1.8, probably something similar these days:

BlockDispenser.dispenseBehaviorRegistry.putObject(yourItem, new YourCustomDispenserBehavior());

Posted

Well you are making all of your classes abstract... do you know what that means? That means you can't actually instantiate them, i.e. you can't use them the way you seem to think you can, unless somewhere else you are actually making a concrete class implementation?

 

Show your concrete class implementations for the Entity AND the dispenser behavior.

Show where you register your Entity class.

Show where your register your dispenser behavior.

Show where you register your Entity's Render factory.

 

All of those things must be done or it won't work at all - this has nothing to do with 1.10.2 vs. 1.8 or other versions - you have do do all of those things regardless of version, they're just done slightly differently.

Posted

How do i register the dispenser behavior?

Already showed you - you just have to check and see if it still works in 1.10.2. If it doesn't, I bet BlockDispenser will have something similar, or you can use your IDE to find where other dispenser behaviors are registered.

BlockDispenser.dispenseBehaviorRegistry.putObject(yourItem, new YourCustomDispenserBehavior());

BUT, you can't do that until you have non-abstract versions of your classes.

 

I still don't see where you register your projectile entity?

 

Am I correct in assuming that e.g. EntityFireOrb extends your abstract EntityOrb class?

 

Note: I'm not going to download random files from you, sorry. Post code using Pastebin, Gist, or create an online repository such as with GitHub.

Posted
gimme a friggin screen shot of an example or something then rather than bs'n me

 

Insult or not, you are being less than friendly. I simply asked you if you knew how to search through the MC source? If you do not, I will teach you how.

 

No one is giving you crap or misleading you either, you have a problem, we have given solutions. The solution coolAlias gave for registering dispenser behaviours would be valid if the mappings hadn't changed in 1.10.2(dispenseBehaviorRegistry is now DISPENSE_BEHAVIOR_REGISTRY); since you did not open BlockDispenser and find that out yourself, I am assuming you do not know how to search the MC source. If a solution isn't clear, ask for clarification.

Posted

A dispenser can only dispense items, you cannot put an Entity in it's inventory. Hence the interface is called IBehaviourDispenseItem, because it defines how the dispenser should behave when it dispenses a certain Item. However you can create and register an IBehaviorDispenseItem to spawn an entity when an Item is dispensed.

 

If you just want your item to behave like a snowball, you want BehaviorProjectileDispense. Override BehaviorProjectileDispense#getProjectileEntity() to return the appropriate Entity using an anonymous class. Examples can be found in net.minecraft.init.Bootstrap#registerDispenserBehaviors().

 

I also recommend that you investigate the options in the context menu that appears when you right-click inside the code window. I figure out how to use most things by looking at call hierarchies; The options labeled Open Type Hierarchy, Declarations and References are useful for figuring out how something works or what it does.

Posted

I'd seriously like to know where thats copy and pasted from...

 

Nowhere, it's the result of a bit of digging through the MC source plus my knowledge of Java

 

This isn't helping at all, I'm not getting anywhere... I need like a video tutorial or something.

Like Here is how you do it and here is an example of this.

 

There are plenty of examples in the source, if you know how to find them(Which I'm happy to show you)

For example:

BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(Items.ARROW, new BehaviorProjectileDispense()
        {
            /**
             * Return the projectile entity spawned by this dispense behavior.
             */
            protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn)
            {
                EntityTippedArrow entitytippedarrow = new EntityTippedArrow(worldIn, position.getX(), position.getY(), position.getZ());
                entitytippedarrow.pickupStatus = EntityArrow.PickupStatus.ALLOWED;
                return entitytippedarrow;
            }
        })

 

And here is some code and this is where you put it and thats that and thats how its done.

that way i can actually enjoy it.

 

This aint doin anything other than frustrating me... im just going to do something else. modding really is cool... but its not that fun.

Posted

I do have this package located in the right place though correct?

 

As in init

 

guru.tbe.item.ItemEarthOrb

is a package and a class, it is not an Object.

 

You need to do "new ItemEarthOrb()" or reference one that already exists.

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

You need to reference it like this:

GuruItems.EarthOrb

 

That's your class and it's static item reference field.

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

// TODO Auto-generated method stub

return null;

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

Github for Windows isn't completely terrible, but yeah: I would recommend using something else.

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

as of last week windows stopped supporting vista, and I can't afford a new os atm.

 

I really need 70 bucks to get off this ddr2, and upgrade to a ddr3 graphics card before I get a new os anyways.

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.