#How do I register a block entity with logic every server tick?

6 messages · Page 1 of 1 (latest)

tranquil bane
#

I'm trying to have a block emit particles idly, and apparently I need to register it as a block entity and spawn particles as part of it ticking server-side. I've tried plenty of ways to accomplish this but nothing I do seems to work. I'm using ProbeJS but I can't figure out what I am doing wrong.

Current implementation (testing to see if I can get anything in console first):

StartupEvents.registry('block', event => {
  event.create("mymod:testblock", "slab")
    .mapColor("GOLD").soundType("METAL")
    .blockEntity(be => {
        be.serverTicking();
        be.tickFrequency(20);
        be.eventHandler(0, event => {
            console.info("Hello???")
        });
    });
})
mental pecanBOT
#

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

cobalt iris
#

the ticking logic is event based, so you don't need the be.eventHandler
You can do both Client-Side and Server-Side, but any non-rendering based-or-adjacent stuff should happen on the server

BlockEvents.blockEntityTick("mymod:testblock", event => {
  //ontick logic here
})
tranquil bane
#

Thank you for answering, but even a barebones

BlockEvents.blockEntityTick("mymod:testblock", event => {
  console.info("Hello?");
})

Isn't printing anything inside console, even if the block is also registered thusly (without an eventHandler):

StartupEvents.registry('block', event => {
  event.create("mymod:testblock", "slab")
    .mapColor("GOLD").soundType("METAL")
    .blockEntity(be => {
        be.serverTicking();
        be.tickFrequency(20);
    });
})

I expect to see "Hello?" printed inside my console every 20 ticks, but nothing occurs. I've restarted my game plenty of times, and I am testing this inside a singleplayer world.

cobalt iris
#

I made a showcase on github of my laser crafting table last week, you can have a look and see how I do it
You should be fine just using .ticking() to enable it on both client & server
Oh and the BlockEvents.blockEntityTick callbacks have to of course be in either/both of server_scripts and/or client_scripts, not startup_scripts. I didn't explicitly state as much in my prior message

tranquil bane
#

Thank you! Being able to reference code that actually works is exactly what I needed. I can tell you that it works on my end now too, and I've concluded that slabs actually cannot be block entities, and that was what my problem was at the start. Linking me your showcase helped a lot! Gonna close this ticket now as resolved :)