Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RenderOffsets #116

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions src/item/component/RenderOffsetsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
dadodasyra marked this conversation as resolved.
Show resolved Hide resolved
$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;
}
}
}