1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

ItemComponentPacketEntry render_offsets

Discussion in 'Development' started by Tobias14, Mar 20, 2022.

  1. Tobias14

    Tobias14 Spider

    Messages:
    7
    GitHub:
    tobias-2006
    Good day,

    I am trying to add custom items with the ItemComponentPacket.
    Adding them works without any problems.

    The only problem I have is that some items are displayed too large.
    I was able to find the solution at the Bedrock Wiki.

    You can work with the "render_offsets" component to solve the problem.

    However, ItemComponentPacketEntries need CacheableNbt's and not json format.
    Likewise, the json looks a little different from the ItemDefinition.
    The Bedrock Protocol shows what it should look like:

    Code:
    {
      "components": {
        "item_properties": {
          "allow_off_hand": true,
          "hand_equipped": true,
          "max_stack_size": 64
        },
        "minecraft:icon": {
          "texture": "example_item"
        }
      },
      "id": 1020,
      "name": "wikivg:example_item"
    }
    As a CacheableNbt, this would look like this:
    PHP:
    $nbt = new CompoundTag();

    $componentsTag = new CompoundTag();

    $itemPropertiesTag = new CompoundTag();
    $itemPropertiesTag->setByte('allow_off_hand'1);
    $itemPropertiesTag->setByte('hand_equipped'1);
    $itemPropertiesTag->setInt('max_stack_size'64);
    $componentsTag->setTag('item_properties'$itemPropertiesTag);

    $iconTag = new CompoundTag();
    $iconTag->setString('texture''example_item');
    $componentsTag->setTag('minecraft:icon'$iconTag);

    $nbt->setTag('components'$componentsTag);

    $nbt->setInt('id'1020);
    $nbt->setString('name''wikivg:example_item');

    $cacheableNbt = new CacheableNbt($nbt);
    Up to here everything works without problems.
    But the attempt to add the "render_offsets" component fails.

    As json it would look like this:
    Code:
    {
      "components": {
        "item_properties": {
          "allow_off_hand": true,
          "hand_equipped": true,
          "max_stack_size": 64
        },
        "minecraft:icon": {
          "texture": "example_item"
        },
        "minecraft:render_offsets": {
          "main_hand": {
            "first_person": {
              "scale": [0, 0, 0]
            },
            "third_person": {
              "scale": [0, 0, 0]
            }
          },
          "off_hand": {
            "first_person": {
              "scale": [0, 0, 0]
            },
            "third_person": {
              "scale": [0, 0, 0]
            }
          }
        }
      },
      "id": 1020,
      "name": "wikivg:example_item"
    }
    My attempt to put this into PHP:
    PHP:
    $nbt = new CompoundTag();

    $componentsTag = new CompoundTag();

    $itemPropertiesTag = new CompoundTag();
    $itemPropertiesTag->setByte('allow_off_hand'1);
    $itemPropertiesTag->setByte('hand_equipped'1);
    $itemPropertiesTag->setInt('max_stack_size'64);
    $componentsTag->setTag('item_properties'$itemPropertiesTag);

    $iconTag = new CompoundTag();
    $iconTag->setString('texture''example_item');
    $componentsTag->setTag('minecraft:icon'$iconTag);

    $renderOffsetsTag = new CompoundTag();

    $offsetsTag = new CompoundTag();
    $offsetsTag->setTag('scale', new ListTag([new FloatTag(0), new FloatTag(0), new FloatTag(0)]));

    $mainHandTag = new CompoundTag();
    $mainHandTag->setTag('first_person'$offsetsTag);
    $mainHandTag->setTag('third_person'$offsetsTag);
    $renderOffsetsTag->setTag('main_hand'$mainHandTag);

    $offHandTag = new CompoundTag();
    $offHandTag->setTag('first_person'$offsetsTag);
    $offHandTag->setTag('third_person'$offsetsTag);
    $renderOffsetsTag->setTag('off_hand'$offHandTag);

    $componentsTag->setTag('minecraft:render_offsets'$renderOffsetsTag);

    $nbt->setTag('components'$componentsTag);

    $nbt->setInt('id'1020);
    $nbt->setString('name''wikivg:example_item');

    $cacheableNbt = new CacheableNbt($nbt);
    The difficult thing is that there is no feedback from Minecraft on what the problem is.
    Microsoft describes the component a bit differently, as you can see here.
    For this reason I have already tried to represent "main_hand" and "off_hand" directly as ListTag:
    PHP:
    $renderOffsetsTag = new CompoundTag();

    $mainHandTag = new ListTag([new FloatTag(0), new FloatTag(0), new FloatTag(0)]);
    $renderOffsetsTag->setTag('main_hand'$mainHandTag);
    $offHandTag = new ListTag([new FloatTag(0), new FloatTag(0), new FloatTag(0)]);
    $renderOffsetsTag->setTag('off_hand'$offHandTag);

    $componentsTag->setTag('minecraft:render_offsets'$renderOffsetsTag);
    There were also other attempts, such as moving the component to "item_properties" and/or removing the "minecraft:" prefix.

    Current status: The items are still displayed too large

    Edit: To recap the problem, the render_offsets component does not work.
     
    Last edited: Mar 20, 2022
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.