Jump to content

How Do I Dispense A Custom Throwable Entity? (1.10.2)


gurujive

Recommended Posts

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.  ???

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

// 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.

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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