world.afterEvents.playerInteractWithBlock.subscribe((event) => {
let { block, blockFace, itemStack, player } = event;
const filters = ['minecraft:barrel', 'minecraft:chest', 'minecraft:crafting_table', 'minecraft:enchant_table', 'minecraft:anvil', 'minecraft:trapped_chest', 'minecraft:hopper', 'minecraft:wooden_door','minecraft:wooden_trapdoor','minecraft:acacia_door','minecraft:acacia_trapdoor','minecraft:iron_door','minecraft:iron_trapdoor','minecraft:bamboo_door','minecraft:bamboo_trapdoor','minecraft:birch_door','minecraft:birch_trapdoor','minecraft:cherry_door','minecraft:cherry_trapdoor','minecraft:crimson_trapdoor','minecraft:crimson_door','minecraft:dark_oak_door','minecraft:dark_oak_trapdoor','minecraft:jungle_door','minecraft:trapdoor','minecraft:jungle_trapdoor','minecraft:mangrove_trapdoor','minecraft:mangrove_door','minecraft:spruce_trapdoor','minecraft:spruce_door','minecraft:dispenser', 'minecraft:command_block','minecraft:repeating_command_block', 'minecraft:comparator', 'minecraft:repeater', 'minecraft:decorated_pot', 'minecraft:chain_command_block','minecraft:item_frame','minecraft:switch','minecraft:smithing_table', 'minecraft:glow_frame', 'minecraft:cartography_table', 'minecraft:crafting_table','minecraft:frame', 'minecraft:dropper','minecraft:furnace','minecraft:smoker','minecraft:blast_furnace']
if (filters.includes(block.typeId)) return;
if (!itemStack?.typeId.startsWith("frogbowls:bowl_frog_warm")) return;
if ((player['spawnCD'] ?? 0) > Date.now()) return;
const name = itemStack.nameTag ?? "";
const type = itemStack.typeId.split("frogbowls:bowl_frog_warm")[1]
switch (blockFace) {
case "Down": block = block.below(); break;
case "Up": block = block.above(); break;
case "East": block = block.east(); break;
case "North": block = block.north(); break;
case "South": block = block.south(); break;
case "West": block = block.west(); break;
}
player['spawnCD'] = Date.now() + 500; // 1 second delay
const entity = player.dimension.spawnEntity('minecraft:frog', block.center());
entity.nameTag = name;
entity.triggerEvent(`spawn_warm`);
const item = new ItemStack("minecraft:bowl",1);
const {container} = player.getComponent("minecraft:inventory");
container.setItem(player.selectedSlot, item)
world.playSound("mob.frog.ambient", entity.location)
world.playSound("break.decorated_pot", entity.location)
});```
Issue: this is supposed to switch your mainhand item to a bowl, while summoning a frog of a specific type, and naming it the item's name.
#world.afterEvents.playerInteractWithBlock.subscribe((event) not working properly
1 messages · Page 1 of 1 (latest)
Defining constants outside of world events is recommended, so they don’t get recreated as variables every time the code runs
Btw, what's the actual issue? Your remarks about the "issue" at the bottom are more like a description than the actual issue.
The issue is that it's not doing that
In fact. Nothing happens when you right click the ground or a wall with the item
When trying to fix this, i ran into another weird problem
Did you split the code for each type of frogs?
Yes. One for each.
I can only see the warm variants
Just copy pasted
Changing only spawn type
(I know, inefficient)
world.afterEvents.playerInteractWithBlock.subscribe((event) => {
let { block, blockFace, itemStack, player } = event;
const filters = ['minecraft:barrel', 'minecraft:chest', 'minecraft:crafting_table', 'minecraft:enchant_table', 'minecraft:anvil', 'minecraft:trapped_chest', 'minecraft:hopper', 'minecraft:wooden_door','minecraft:wooden_trapdoor','minecraft:acacia_door','minecraft:acacia_trapdoor','minecraft:iron_door','minecraft:iron_trapdoor','minecraft:bamboo_door','minecraft:bamboo_trapdoor','minecraft:birch_door','minecraft:birch_trapdoor','minecraft:cherry_door','minecraft:cherry_trapdoor','minecraft:crimson_trapdoor','minecraft:crimson_door','minecraft:dark_oak_door','minecraft:dark_oak_trapdoor','minecraft:jungle_door','minecraft:trapdoor','minecraft:jungle_trapdoor','minecraft:mangrove_trapdoor','minecraft:mangrove_door','minecraft:spruce_trapdoor','minecraft:spruce_door','minecraft:dispenser', 'minecraft:command_block','minecraft:repeating_command_block', 'minecraft:comparator', 'minecraft:repeater', 'minecraft:decorated_pot', 'minecraft:chain_command_block','minecraft:item_frame','minecraft:switch','minecraft:smithing_table', 'minecraft:glow_frame', 'minecraft:cartography_table', 'minecraft:crafting_table','minecraft:frame', 'minecraft:dropper','minecraft:furnace','minecraft:smoker','minecraft:blast_furnace']
if (filters.includes(block.typeId)) return;
if (!itemStack?.typeId.startsWith("frogbowls:bowl_frog_cold")) return;
if ((player['spawnCD'] ?? 0) > Date.now()) return;
const name = itemStack.nameTag ?? "";
const type = itemStack.typeId.split("frogbowls:bowl_frog_cold")[1]
switch (blockFace) {
case "Down": block = block.below(); break;
case "Up": block = block.above(); break;
case "East": block = block.east(); break;
case "North": block = block.north(); break;
case "South": block = block.south(); break;
case "West": block = block.west(); break;
}
player['spawnCD'] = Date.now() + 500; // 1 second delay
const entity = player.dimension.spawnEntity('minecraft:frog', block.center());
entity.nameTag = name;
entity.triggerEvent(`spawn_cold`);
const item = new ItemStack("minecraft:bowl",1);
const {container} = player.getComponent("minecraft:inventory");
container.setItem(player.selectedSlot, item)
world.playSound("mob.frog.ambient", entity.location)
world.playSound("break.decorated_pot", entity.location)
});```
try using the !== operator to check the item typeId
Could you write down an example?
if (itemStack?.typeId !== "frogbowls:bowl_frog_warm") return;
Thanks
It fixed the issue with placing blocks and spawneggs summoning frogs, but it's still not working
What is the stuff that didn't work?
You fixed the two things in the vids
Is it the cool down?
It's not placing the frog when using the item on the ground
I removed the cooldown and no change.
world.afterEvents.playerInteractWithBlock.subscribe((event) => {
let { block, blockFace, itemStack, player } = event;
const filters = ['minecraft:barrel', 'minecraft:chest', 'minecraft:crafting_table', 'minecraft:enchant_table', 'minecraft:anvil', 'minecraft:trapped_chest', 'minecraft:hopper', 'minecraft:wooden_door','minecraft:wooden_trapdoor','minecraft:acacia_door','minecraft:acacia_trapdoor','minecraft:iron_door','minecraft:iron_trapdoor','minecraft:bamboo_door','minecraft:bamboo_trapdoor','minecraft:birch_door','minecraft:birch_trapdoor','minecraft:cherry_door','minecraft:cherry_trapdoor','minecraft:crimson_trapdoor','minecraft:crimson_door','minecraft:dark_oak_door','minecraft:dark_oak_trapdoor','minecraft:jungle_door','minecraft:trapdoor','minecraft:jungle_trapdoor','minecraft:mangrove_trapdoor','minecraft:mangrove_door','minecraft:spruce_trapdoor','minecraft:spruce_door','minecraft:dispenser', 'minecraft:command_block','minecraft:repeating_command_block', 'minecraft:comparator', 'minecraft:repeater', 'minecraft:decorated_pot', 'minecraft:chain_command_block','minecraft:item_frame','minecraft:switch','minecraft:smithing_table', 'minecraft:glow_frame', 'minecraft:cartography_table', 'minecraft:crafting_table','minecraft:frame', 'minecraft:dropper','minecraft:furnace','minecraft:smoker','minecraft:blast_furnace']
if (filters.includes(block.typeId)) return;
if (itemStack?.typeId !== "frogbowls:bowl_frog_warm") return;
const name = itemStack.nameTag ?? "";
const type = itemStack.typeId.split("frogbowls:bowl_frog_warm")[1]
switch (blockFace) {
case "Down": block = block.below(); break;
case "Up": block = block.above(); break;
case "East": block = block.east(); break;
case "North": block = block.north(); break;
case "South": block = block.south(); break;
case "West": block = block.west(); break;
}
const entity = player.dimension.spawnEntity('minecraft:frog', block.center());
entity.nameTag = name;
entity.triggerEvent(`spawn_warm`);
const item = new ItemStack("minecraft:bowl",1);
const {container} = player.getComponent("minecraft:inventory");
container.setItem(player.selectedSlot, item)
world.playSound("mob.frog.ambient", entity.location)
world.playSound("break.decorated_pot", entity.location)
});```
Do you have the correct frog bowl when testing it?
It's kinda infuriating. It's should work, but it doesn't
Yes.
"format_version": "1.20.0",
"minecraft:item": {
"description": {
"identifier": "frogbowls:bowl_frog_warm"
},
"components": {
"minecraft:creative_category": {
"category": "items"
},
"minecraft:display_name": {
"value": "Warm Frog in a bowl"
},
"minecraft:max_stack_size": 1,
"minecraft:icon": {
"texture": "frogsinbuckets_bowl_frog_warm"
}
},
"events": {}
}
btw, what does the const type do here?
I'll remove it and see if any difference is made
Here's the other part of the code, it works but it might have something to do with breaking the code or something.
world.afterEvents.playerInteractWithEntity.subscribe((eventData) => {
const {player,itemStack,target} = eventData;
if(!itemStack || target.typeId !== "minecraft:frog") return;
if(itemStack.typeId !== "minecraft:bowl") return;
const variant = target.getComponent("minecraft:variant").value;
switch (variant) {
case 0: pickFrog("temperate",player,target); break;
case 1: pickFrog("cold",player,target); break;
case 2: pickFrog("warm",player,target); break;
};
});
function pickFrog(variant,player,target){
const {container} = player.getComponent("minecraft:inventory");
const bowl = container.getItem(player.selectedSlot);
const name = target.nameTag;
const itemType = "frogbowls:bowl_frog_" + variant
let item = new ItemStack(itemType,1)
item.nameTag = name
if(bowl.amount == 1){
container.setItem(player.selectedSlot, item)
} else{
bowl.amount -= 1
container.addItem(item)
container.setItem(player.selectedSlot, bowl)
}
world.playSound("mob.frog.ambient", target.location)
world.playSound("break.decorated_pot", target.location)
target.remove();
}```
this works already right?
Used to work. But doesnt now
Does not throw any errors.
whats the Blockface?
did you define it?
Blockface is used to summon the frog beside, above or below the selected block
It worked earlier, but it wont work with the items for some reason.
@severe turtle
working on it
Need the full script?
i have it
Gotcha
@sage wasp i may port it to stable
Yeah, as long as it works
That might help the mod actually
Damn. Good job!
I'll give you credit in the addon's update
Send in dms