#Supplier of value from the inside of the definition of the value

1 messages · Page 1 of 1 (latest)

plain tide
#

In minecraft forge 1.20.1 you instantiate a specific type of class (entities) with a constructor that looks like this:

    {
        super(ModBlockEntities.LIQUID_ENTITY.get(), pos, state);
    }```

To instantiate you need to register a object of RegistryObject<BlockEntityType<Entity>>:
```    public static final RegistryObject<BlockEntityType<LiquidBlockEntity>> LIQUID_ENTITY =
            BLOCK_ENTITIES.register("block_liquid_entity",
                    () -> BlockEntityType.Builder.of(
                            LiquidBlockEntity::new,
                    ModBlocks.LIQUID_BLOCK.get()).build(null));```

As you can see, within the constructor, you use the RegistryObject itself within super.

That kinda annoys me, so i wanna find a solution for that.


My idea was to create a constructor like this:
```    public LiquidBlockEntity(BlockEntityType<?> pType, BlockPos pos, BlockState state)
    {
        super(pType, pos, state);
    }```
and use this one in the instantiating of the LIQUID_ENTITY by giving 
```(pos, state) -> new LiquidBlockEntity(LIQUID_ENTITY.get(), pos, state)```
instead of LiquidBlockEntity::new.

But obviously this doesnt work because i'm referencing the RegistryObject while creating the RegistryObject.

Trying something samey with using a supplier of BlockEntityType<?>
```    public LiquidBlockEntity(Supplier<BlockEntityType<?>> pTypeSupplier, BlockPos pos, BlockState state)
    {
        super(pTypeSupplier.get, pos, state);
    }

    (pos, state) -> new LiquidBlockEntity(LIQUID_ENTITY::get, pos, state)

doesnt work for the same reason.

So, is there a way how i could fix this?

fringe ravenBOT
#

<@&987246652869971988> please have a look, thanks.

plain tide
#

Something that would work is by basically creating a dummy method like this:

    {
        return registerFilteredBlockEntityType("block_liquid_entity",
                (pos, state) -> new LiquidBlockEntity(() -> LIQUID_ENTITY.get(), pos, state),
                LiquidBlock.class);
    }

and then calling it for the instantiating of the RegistryObject:
public static final RegistryObject<BlockEntityType<LiquidBlockEntity>> LIQUID_BLOCK_ENTITYtest = test();
But i would need to create a method like that for every RegistryObject and Entity i create, which is annoying in it self.

atomic lake
#

It is done this way for a reason

#

it opens up possibilities for dynamic reloading of registries

valid nymph
plain tide