diff --git a/src/item/component/RenderOffsetsComponent.php b/src/item/component/RenderOffsetsComponent.php index 1788433..db257bb 100644 --- a/src/item/component/RenderOffsetsComponent.php +++ b/src/item/component/RenderOffsetsComponent.php @@ -5,38 +5,47 @@ final class RenderOffsetsComponent implements ItemComponent { - private int $textureWidth; - private int $textureHeight; - private bool $handEquipped; - - public function __construct(int $textureWidth, int $textureHeight, bool $handEquipped = false) { - $this->textureWidth = $textureWidth; - $this->textureHeight = $textureHeight; - $this->handEquipped = $handEquipped; + private int $textureSize; + + public function __construct(int $textureSize) { + $this->textureSize = $textureSize; } public function getName(): string { return "minecraft:render_offsets"; } + /** + * This is "MedicalJewel105"'s work. + * @see https://github.com/MedicalJewel105/bedrock-render-offsets-generator/blob/main/main.py + */ public function getValue(): array { - $horizontal = ($this->handEquipped ? 0.075 : 0.1) / ($this->textureWidth / 16); - $vertical = ($this->handEquipped ? 0.125 : 0.1) / ($this->textureHeight / 16); - $perspectives = [ - "first_person" => [ - "scale" => [$horizontal, $vertical, $horizontal], + $textureSize = $this->textureSize; + $mainHandFirst = round(0.039 * 16 / $textureSize, 8); + $offHandFirst = round(0.065 * 16 / $textureSize, 8); + $mainHandThird = $offHandThird = round(0.0965 * 16 / $textureSize, 8); + + return [ + "main_hand" => [ + "first_person" => [ + "scale" => [$mainHandFirst, $mainHandFirst, $mainHandFirst], + ], + "third_person" => [ + "scale" => [$mainHandThird, $mainHandThird, $mainHandThird] + ] ], - "third_person" => [ - "scale" => [$horizontal, $vertical, $horizontal] + "off_hand" => [ + "first_person" => [ + "scale" => [$offHandFirst, $offHandFirst, $offHandFirst], + ], + "third_person" => [ + "scale" => [$offHandThird, $offHandThird, $offHandThird] + ] ] ]; - return [ - "main_hand" => $perspectives, - "off_hand" => $perspectives - ]; } public function isProperty(): bool { return false; } -} \ No newline at end of file +}