#Make custom item stay in inventory after projectile is thrown

1 messages · Page 1 of 1 (latest)

safe frost
#
{
    "format_version": "1.20.80",
    "minecraft:item": {
        "description": {
            "identifier": "thrash:multi",
            "menu_category": {
                "category": "equipment"
            }
        },
        "components": {
            "minecraft:max_stack_size": 64,
            "minecraft:stacked_by_data": true,
            "minecraft:allow_off_hand": true,
            "minecraft:icon": "thrash_multi",
            "minecraft:throwable": {
                "do_swing_animation": true,
                "launch_power_scale": 1
            },
            "minecraft:projectile": {
                "projectile_entity": "thrash:multi_throw"
            }
        }
    }
}
{
    "format_version": "1.20.80",
    "minecraft:entity": {
        "description": {
            "identifier": "thrash:multi_throw",
            "is_spawnable": false,
            "is_summonable": true,
            "is_experimental": false,
            "runtime_identifier": "minecraft:snowball"
        },
        "components": {
            "minecraft:collision_box": {
                "width": 0.15,
                "height": 0.15
            },
            "minecraft:projectile": {
                "on_hit": {
                    "remove_on_hit": {},
                    "particle_on_hit": {
                        "particle_type": "snowballpoof",
                        "num_particles": 4,
                        "on_entity_hit": true,
                        "on_other_hit": true
                    }
                },
                "anchor": 1,
                "power": 0.15,
                "gravity": 0.011,
                "angle_offset": 0,
                "offset": [ 0, 0.325, 0.75 ]
            },
            "minecraft:physics": {},
            "minecraft:pushable": {
                "is_pushable": true,
                "is_pushable_by_piston": true
            }
        }
    }
}

here is my custom item and projectile

ancient creek
#

A script would be the best way. I would not recommend using chat gpt at all unless you already know what you're doing, as it will hallucinate meaning you'd need to know what's wrong to be able to fix it

#

There are some wiki guides on using custom components, I'll link them below

slow baneBOT
#
HCF Removal and Custom Components

The Holiday Creator Features experimental toggle has been removed. Along with it includes JSON block and item events. This functionality has been replaced with custom components.

Please take a look at the following links to learn more about custom components:

Bedrock Wiki

MS Docs

ancient creek
#

Ah, looks like or doesn't contain how to shoot a projectile with a script

#

I'll send some example code for that

#
const ShootComponent = {
    onUse(data) {
      let item=data.itemStack;
  let player=data.source;
  
  let launchVel=5;
  const velocity = player.getViewDirection();
  let headLoc=player.getHeadLocation();
  const arrow = player.dimension.spawnEntity('minecraft:arrow', {x: headLoc.x+velocity.x, y: headLoc.y+velocity.y, z: headLoc.z+velocity.z});
  const projectileComp = arrow.getComponent('minecraft:projectile');
  projectileComp?.shoot({x: velocity.x*launchVel, y: velocity.y*launchVel, z: velocity.z*launchVel});
    },
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
    itemComponentRegistry.registerCustomComponent("example:shoot", ShootComponent);
});```
#

I will admit, I have not tested this exact code, but I know the code inside of the component works

safe frost
ancient creek
#

Ofc

safe frost
#

didnt mean to delete original message.... Im still having this issue. and i wasnt able to fix it with the above help.

I want my custom item(multi.json) to not be removed from my inventory when i right click. It has to spawn an entity(multi_throw.json). it needs to work pretty much the same as a snowball but i dont care if the entity has velocity or not. if the entity spawns in front of my face then falls to the ground thats fine.

the very first messages are my custom item and entity.. If this cant be done in json(like how i could before the update), then at least if it has to be done with javascript, i would like the script to last a while before mojang decides to break stuff again. if thats possible.

please and thank you to whoever can help me.

ancient creek
#

Does the custom component I sent not work when you register it to the item?

Also, you'll need ti remove the throwable and projectile components from your item for it to not decrement the stack

safe frost
ancient creek
#

Strange. I'll double check, but I beliebe it worked for me when i tested. Any content log errors in the world?

safe frost
#

no errors

#
{
    "format_version": "1.20.80",
    "minecraft:item": {
        "description": {
            "identifier": "thrash:multi",
            "menu_category": {
                "category": "equipment"
            }
        },
        "components": {
            "minecraft:max_stack_size": 64,
            "minecraft:stacked_by_data": true,
            "minecraft:allow_off_hand": true,
            "minecraft:icon": "thrash_multi",
        "minecraft:use_animation": "bow",
            "minecraft:use_duration": 32,
            "minecraft:shoot": "example:shoot"
        }
    }
}
#
import { world } from "@minecraft/server";

const ShootComponent = {
    onUse(data) {
        let item=data.itemStack;
        let player=data.source;
  
        let launchVel=5;
        const velocity = player.getViewDirection();
        let headLoc=player.getHeadLocation();
        const arrow = player.dimension.spawnEntity('thrash:multi_throw', {x: headLoc.x+velocity.x, y: headLoc.y+velocity.y, z: headLoc.z+velocity.z});
        const projectileComp = arrow.getComponent('minecraft:projectile');
        projectileComp?.shoot({x: velocity.x*launchVel, y: velocity.y*launchVel, z: velocity.z*launchVel});
    },
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
    itemComponentRegistry.registerCustomComponent("example:shoot", ShootComponent);
});
#

my script and item should look like this right?
ohh is the item wrong? i think i didnt register it right

ancient creek
#

Ah yeah, you need to add "minecraft:custom_components":["example:shoot"] to it