#Client-side entities..?

108 messages · Page 1 of 1 (latest)

heady solstice
#

I want to spawn an entity relative to a block based on a location specified in a resource pack and I already have a resource reloader set up and all that stuff, but i can't figure out how to spawn my entity on the client.

This is for a more complex block interaction system I'm working on.
The idea is that the player can click on several small buttons on a block which would all send a packet to the server and the server can perform the interaction. The buttons are actual geometry on the block and aren't flat so I can't just use math to figure out the positions, I've tried voxelshapes but those are useless so I have to use entities for this.

In my case world.spawnEntity is being called on a ClientWorld, but it isn't spawning anything. The code is indeed being executed but there is nothing showing up in my F3 menu

barren bluff
#

It looks like ClientWorld doesn't override the default implementation of spawnEntity in ModifiableWorld, so it does nothing. If you really want to do this, perhaps try ClientWorld::addEntity, which is what ClientPlayNetworkHandler uses to cause entity spawns.

I feel like you should be able to achieve configurable buttons by using a custom BakedModel, caching a dynamic VoxelShape in the block entity, and using the 3D position of the raycast result to determine which button has been pressed when a player clicks the block. It might turn out to be more complicated than entities, though. I'm not sure.

#

@heady solstice

heady solstice
#

Blockbench has an option to export models directly into code, and there's no way im doing that xD

barren bluff
#

Not necessarily. You can use a multipart blockstate to combine the JSON model with a dynamic one for the buttons. You could also grab the model from the Baker and emit its quads alongside the button models. @heady solstice

heady solstice
#

i understood none of that xD

#

it would be nice to avoid entities even if it added complexity because of how heavy they are

#

I already have a fancy way of getting where every button is and how large every button is client-side

#

not sure what i would do from here though

#

(omg you've been typing for like 5 minutes I appreciate the effort, other people on here respond to problems with like 4 word long answers xD)

barren bluff
# heady solstice i understood none of that xD

In the blockstate file, you have the option of specifying single models for all variants, or applying multiple models simultaneously depending on each property. Here's an example:

{
  "multipart": [
    {
      "apply": {
        "model": "modid:block/main_model"
      }
    },
    {
      "apply": {
        "model": "modid:block/a_custom_baked_model"
      }
    }
  ]
}

When an UnabkedModel is baked, a Baker (or ModelLoader pre-1.20) object is passed which allows you to load models manually. You can store this in the BakedModel and render it in emitBlockQuads

heady solstice
#

ohh

barren bluff
heady solstice
#

still not sure I understand that
though i am using GeckoLib so it wouldnt really make a difference

barren bluff
#

I don't think GeckoLib will be much help here. Although, you could also use a BlockEntityRenderer to do the button models.

heady solstice
#

i know
rendering is not the problem though xD

#

im just saying i cant exactly use vanilla models

#

it bothers me you cant just create several voxel shapes and get what shape the player's raycast hit inside onUse

barren bluff
#

Can't you calculate that from the BlockHitResult?

heady solstice
#

if it was always that easy i would've left this server xD

#

.. actually im not exactly sure

#

it might be possible to do that, but the amount of math required..

barren bluff
#

How many buttons do you have?

heady solstice
heady solstice
#

i'm working on a general system for handling advanced input for blocks

barren bluff
#

Are they aligned to one face, or can they be anywhere within the block?

heady solstice
#

anywhere in the block

barren bluff
#

Argh

#

I see

heady solstice
#

.. or even slightly outside the block

#

which is the problem xD

#

ik how chiseled bookshelves work

heady solstice
#

there is probably some way to add several voxel/collision shapes to the block and using that hit.getPos() to get which voxel shape it hit but the math required for that hurts my brain

barren bluff
#

Could you perhaps iterate through each button, inflate its Box slightly and check if the hit pos falls inside any of them?

heady solstice
#

that might be possible..

heady solstice
#

hmmm

#

the main problem trying to do that is i can't really get the boxes

#
@Override
public boolean hasDynamicBounds() {
    return true;
}

private VoxelShape getShape(BlockState state, BlockView world, BlockPos pos) {
    var shape = VoxelShapes.empty();
    
    if (world.getBlockEntity(pos) instanceof ShowSelectorBlockEntity blockEntity) {
        for (var entry : blockEntity.multiPart.interactableParts.entrySet()) {
            var key = entry.getKey();
            var part = entry.getValue();
            if (part == null || part.bounds() == null) continue;
            
            ShowbizMod.LOGGER.info(key);
            shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(part.bounds()), BooleanBiFunction.AND);
        }
    }
    return shape;
}

I tried this to no avail

#

my attempt to get the block entity always fails

heady solstice
#

trying to combine all the shapes just.. does this-

#

even using union

barren bluff
heady solstice
#

i think my scaling is off so thats easy enough to fix, but its making a weird border around all the shapes or idk whats happening

#

I've tried entities again and this time its spawning the entities but i cant see them or their hitboxes

#

and it is VERY laggy
30 entities already drops my frames down to like 50 and i have a mid-end PC

heady solstice
#

I can't see them with the F3 hitbox thing though

heady solstice
#

the entity counter in F3 says the entities are there but no matter where i look they arent uhh

barren bluff
#

I wonder how Tardis Refined does interactions with the console

sullen nymph
#

arent you provided the blockHitResult in the onUse and onItemUse methods?

heady solstice
#

it is useless though

#

it just provides the location the ray hit the block's voxel shape at

heady solstice
#

(their source code is a nightmare to navigate)

#

main issue im coming across now is that the game doesn't really know what to do with the entity

#

in some places the entities are recognized as entities, in some places they don't exist

#
var entities = world.getEntitiesByClass(InteractPartEntity.class, Box.of(player.getPos(), 20, 20, 20), p -> true);
for (var entity : entities) {
    entity.kill();
}

tried running this for a debug command i made, and it kills none of the entities

#

the entities also don't display a hitbox in the F3 hitbox debugger

barren bluff
#

Strange. Could something be setting their positions to somewhere weird?

Oh, have you thought of making the VoxelShape a full cube and doing an internal raycast manually?

heady solstice
#

ive tried the full cube thingy and actually nope, idk how raycasts work in this engine xD

#

Tardis Refined uses server-side entities

barren bluff
heady solstice
#

i might end up moving to that if the entity system is causing too much lag

#

entities feel like a better option though

#

especially since I can have custom rendering for them like displaying text above them

#

i don't know what im doing wrong though

#

and there's like NOTHING on client-side entities

#

so, spawning in a TextDisplayEntity works

#

for some reason

#

it shows the entity in the F3 menu

#

but my entity specifically just, does not

#

all i did was swap the types

#

.. I commented out a bunch of stuff and found the culporate!

#

the code to set the bounding box just doesn't work

heady solstice
#

overriding calculateBoundingBox seems to always break it for some reason..

#

or getVisibilityBoundingBox

heady solstice
#

i've tried overriding getDimensions but it doesn't do anything

#

its always either human-shaped or non-existent and i can't figure out why
it wont let me have a custom shape, not even a cube

sullen nymph
#

have you tried supplying just a 1x1 Box?

#

in your EntityType, did you tell it that the dimensions were changing?

heady solstice
#

tried that

#

also tried supplying 1 x 1 inside getDimensions to no avail

#

supplying the dimensions inside EntityTypeBuilder in my registry function works though..

#

supplying it by overriding getDimensions, calculateBoundingBox, or both does not

sullen nymph
#

changing those wont change anything if they arent called. how are you calling those methods?

heady solstice
#

thats interesting..

how are you calling those methods?
i was not xD

#

i thought the game called them before the game spawned in the entity because it'd need to get the bounds somehow

#

I'm calling setBoundingBox in the constructor now though and its not doing anything

#

i'm not sure what to look for in terms of reference here since entities like LeashKnotEntity all specify their bounds inside their EntityTypeBuilder

#

there's like no entity with bounds that get set as its placed

sullen nymph
#

call reinitDimensions in the constructor
set your dimensions in getDimensions(pose)
set the entity type dimensions to changing (not fixed)

#

zombies, for example, call calculateDimensions onTrackedDataSet since setting it to baby sets tracked data

slimes call reinit on constructor since their size is set on spawn, but also call it on setSize

heady solstice
#

this works!!

#

though.. my dimensions are stored as boxes

#

at least it works now, but some of my controls aren't perfectly square so i wonder if theres a way to just set the dimensions to an X Y Z size instead of a width/height

#

EntityDimensions only takes in a width and a height so I'd lose a dimension

sullen nymph
#

override calculateBoundingBox as well

#

this is called when setting entity position

#

by default it uses the dimensions but it doesnt need to