#Falling Chest

32 messages · Page 1 of 1 (latest)

open nexus
#

I'm working on a function of fishing a loot chest.

import { $ItemFishedEvent } from "packages/net/minecraftforge/event/entity/player/$ItemFishedEvent"
import { $Blocks } from "packages/net/minecraft/world/level/block/$Blocks"
import { $Player } from "packages/net/minecraft/world/entity/player/$Player"
import { $FallingBlockEntity } from "packages/net/minecraft/world/entity/item/$FallingBlockEntity"
/**
 * 
 * @param {$ItemFishedEvent} event 
 */
global.fishingLoot = (event) => {
    /** @type {$Player} */
    const player = event.getEntity()
    const hook = event.getHookEntity()
    const level = player.getLevel()

    if (!player.isPlayer()) return

    console.log("Player is fishing")

    const chestState = $Blocks.CHEST.defaultBlockState()
    /**@type {$FallingBlockEntity} */
    const lootChest = level.createEntity('minecraft:falling_block')
    lootChest.blockState = chestState
    lootChest.setPos(hook.getX(), hook.getY()+1, hook.getZ())
    const dx = (player.getX() - hook.getX()) * 0.1
    const dy = (player.getY() - hook.getY() + 1) * 0.1
    const dz = (player.getZ() - hook.getZ()) * 0.1 
    lootChest.setMotion(dx, dy, dz)
    lootChest.spawn()
    event.setCanceled(true)
}

/**
 * 
 * @param {$ItemFishedEvent} event 
 */
export const handleFishingLoot = (event) => {
    global.fishingLoot(event)
}

My codes can summon a chest and fly it to the player, but the render of falling blocks' animation is not available and I can't find the way of making the chests be loot chest. Is there any possible methods?

half nacelleBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

open nexus
#

I just figured it out. But still have no ideas about how to render the moving chests.

import { $ItemFishedEvent } from "packages/net/minecraftforge/event/entity/player/$ItemFishedEvent"
import { $Blocks } from "packages/net/minecraft/world/level/block/$Blocks"
import { $Player } from "packages/net/minecraft/world/entity/player/$Player"
import { $FallingBlockEntity } from "packages/net/minecraft/world/entity/item/$FallingBlockEntity"

/**
 * 
 * @param {$ItemFishedEvent} event 
 */
global.fishingLoot = (event) => {
    /** @type {$Player} */
    const player = event.getEntity()
    const hook = event.getHookEntity()
    const level = player.getLevel()

    if (!player.isPlayer()) return

    const chestState = $Blocks.CHEST.defaultBlockState()
    /**@type {$FallingBlockEntity} */
    const lootChest = level.createEntity('minecraft:falling_block')
    lootChest.blockState = chestState
    lootChest.setPos(hook.getX(), hook.getY()+1, hook.getZ())
    const dx = (player.getX() - hook.getX()) * 0.1
    const dy = (player.getY() - hook.getY() + 1) * 0.1
    const dz = (player.getZ() - hook.getZ()) * 0.1
    lootChest.setMotion(dx, dy, dz)

    lootChest.mergeNbt({TileEntityData:
        {LootTable:"minecraft:chests/village/village_tannery",LootTableSeed: Math.floor(Math.random() * 2147483647)}
    })

    console.log(lootChest.nbt)
    lootChest.spawn()
    event.setCanceled(true)
}

/**
 * 
 * @param {$ItemFishedEvent} event 
 */
export const handleFishingLoot = (event) => {
    global.fishingLoot(event)
}
hybrid ibex
#

I tested this script and it works fine:

ItemEvents.rightClicked(e => {
    const falling_block = e.level.createEntity('falling_block')
    falling_block.copyPosition(e.player)
    falling_block.setDeltaMovement(e.player.lookAngle.scale(0.5))
    falling_block.mergeNbt({
        BlockState: {Name: 'minecraft:chest'},
        TileEntityData: {LootTable: 'minecraft:chests/bastion_treasure'}
    })
    falling_block.spawn()
})
#

it spawns a falling block entity of chest with loot inside

#

and it has moving animation, just like those falling block entities

open nexus
#

I can't reproduce the animation, no matter which method I use.

#

I don't know whether this is caused by lootr mod.

open nexus
hybrid ibex
#

i was actually running this script in my modpack, with almost all performance mods on fabric 1.19.2hmmm

#

and a bunch of other mods

open nexus
#

I'm running it on forge 1.20.1. Maybe falling blocks have special logic on rendering. It's quite wield that I can see the move of chest's shadow but I couldn't see them.

hybrid ibex
#

what mods are you using?

open nexus
#

emb which might be the suspects.

#

I'm checking whether i need to sync or send packets for falling blocks now although I don't think its needed...

hybrid ibex
#

maybe send a screenshot of all mods?

open nexus
#

I'm generating a mod list if you don't mind?

hybrid ibex
#

yes

open nexus
keen tapirBOT
#

Paste version of Minecraft-Hunt.txt from @open nexus

open nexus
#

Thanks so much.

hybrid ibex
#

try removing:

ModernFix
Redirector
Embeddium
Embeddium++
Radium

Rubidium Dynamic Lights
BadOptimizations
Krypton Reforged

Memory Leak Fix
ImmediatelyFast
Model Gap Fix
Ferrite Core

Gpu memory leak fix
Mobtimizations
Quark
#

quite not sure which causes the problem, so here're all suspects

open nexus
#

hmmm I actually suspected forge at the start.

hybrid ibex
open nexus
#

The most dramatic thing is that it may really be caused by Forge. I disabled all optimization mods and still have this problem. It seems strange that a single render class is used to perform this operation but it's not used when rendering blocks other than sands.

#

I use mac to test, maybe it's differnt in other system. I will double check later, thanks fore ur help though.

#

Could anyone else test it for me to see whteher you have correct animation.

#
global.fishingLoot = (event) => {
    /** @type {$Player} */
    const player = event.getEntity()
    const hook = event.getHookEntity()

    if (!player.isPlayer()) return

    const falling_block = player.level.createEntity('falling_block')
    falling_block.setPos(hook.getX(), hook.getY()+1, hook.getZ())
    const dx = (player.getX() - hook.getX()) * 0.1
    const dy = (player.getY() - hook.getY() + 1) * 0.1
    const dz = (player.getZ() - hook.getZ()) * 0.1
    falling_block.setMotion(dx, dy, dz)
    falling_block.mergeNbt({
        BlockState: {Name: "minecraft:chest"},
        TileEntityData: {LootTable: 'minecraft:chests/bastion_treasure'}
    })
    falling_block.spawn()
    console.log(falling_block.nbt)
    event.setCanceled(true)
}

In ItemFishedEvent.

keen tapirBOT
# deep maple ??ai

NEVER use any AI to generate KubeJS code. They currently know very little about it, and what they do know is often outdated or false. You can instead look at the KubeJS wiki or ask for help in #1047320998199955458.

open nexus