From b993ae64cae9ab96a8ddf084e74aa10268f18728 Mon Sep 17 00:00:00 2001 From: dadodasyra <44753923+dadodasyra@users.noreply.github.com> Date: Wed, 24 Jan 2024 08:39:56 +0100 Subject: [PATCH 1/3] Fix RenderOffsets This may (and will) lead to API BC --- src/item/component/RenderOffsetsComponent.php | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/item/component/RenderOffsetsComponent.php b/src/item/component/RenderOffsetsComponent.php index 1788433..6920e1d 100644 --- a/src/item/component/RenderOffsetsComponent.php +++ b/src/item/component/RenderOffsetsComponent.php @@ -3,16 +3,13 @@ namespace customiesdevs\customies\item\component; -final class RenderOffsetsComponent implements ItemComponent { - private int $textureWidth; - private int $textureHeight; - private bool $handEquipped; +final class RenderOffsetsComponent implements ItemComponent { //thanks to https://github.com/MedicalJewel105/bedrock-render-offsets-generator/blob/main/main.py - 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 { @@ -20,23 +17,32 @@ public function getName(): string { } 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; + $mainHand_fp = round(0.039 * 16 / $textureSize, 8); + $offhand_fp = round(0.065 * 16 / $textureSize, 8); + $mainHand_tp = $offhand_tp = round(0.0965 * 16 / $textureSize, 8); + + return [ + "main_hand" => [ + "first_person" => [ + "scale" => [$mainHand_fp, $mainHand_fp, $mainHand_fp], + ], + "third_person" => [ + "scale" => [$mainHand_tp, $mainHand_tp, $mainHand_tp] + ] ], - "third_person" => [ - "scale" => [$horizontal, $vertical, $horizontal] + "off_hand" => [ + "first_person" => [ + "scale" => [$offhand_fp, $offhand_fp, $offhand_fp], + ], + "third_person" => [ + "scale" => [$offhand_tp, $offhand_tp, $offhand_tp] + ] ] ]; - return [ - "main_hand" => $perspectives, - "off_hand" => $perspectives - ]; } public function isProperty(): bool { return false; } -} \ No newline at end of file +} From 9bea3f6f761fe558459329c993aed8966e730344 Mon Sep 17 00:00:00 2001 From: dadodasyra <44753923+dadodasyra@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:38:02 +0100 Subject: [PATCH 2/3] Move to snake case --- src/item/component/RenderOffsetsComponent.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/item/component/RenderOffsetsComponent.php b/src/item/component/RenderOffsetsComponent.php index 6920e1d..6f19405 100644 --- a/src/item/component/RenderOffsetsComponent.php +++ b/src/item/component/RenderOffsetsComponent.php @@ -18,25 +18,25 @@ public function getName(): string { public function getValue(): array { $textureSize = $this->textureSize; - $mainHand_fp = round(0.039 * 16 / $textureSize, 8); - $offhand_fp = round(0.065 * 16 / $textureSize, 8); - $mainHand_tp = $offhand_tp = round(0.0965 * 16 / $textureSize, 8); + $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" => [$mainHand_fp, $mainHand_fp, $mainHand_fp], + "scale" => [$mainHandFirst, $mainHandFirst, $mainHandFirst], ], "third_person" => [ - "scale" => [$mainHand_tp, $mainHand_tp, $mainHand_tp] + "scale" => [$mainHandThird, $mainHandThird, $mainHandThird] ] ], "off_hand" => [ "first_person" => [ - "scale" => [$offhand_fp, $offhand_fp, $offhand_fp], + "scale" => [$offHandFirst, $offHandFirst, $offHandFirst], ], "third_person" => [ - "scale" => [$offhand_tp, $offhand_tp, $offhand_tp] + "scale" => [$offHandThird, $offHandThird, $offHandThird] ] ] ]; From 7535c1fed31f501d8efc71b58c1b40f67f74521b Mon Sep 17 00:00:00 2001 From: dadodasyra <44753923+dadodasyra@users.noreply.github.com> Date: Thu, 15 Feb 2024 21:45:50 +0100 Subject: [PATCH 3/3] Update RenderOffsetsComponent.php --- src/item/component/RenderOffsetsComponent.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/item/component/RenderOffsetsComponent.php b/src/item/component/RenderOffsetsComponent.php index 6f19405..db257bb 100644 --- a/src/item/component/RenderOffsetsComponent.php +++ b/src/item/component/RenderOffsetsComponent.php @@ -3,8 +3,7 @@ namespace customiesdevs\customies\item\component; - -final class RenderOffsetsComponent implements ItemComponent { //thanks to https://github.com/MedicalJewel105/bedrock-render-offsets-generator/blob/main/main.py +final class RenderOffsetsComponent implements ItemComponent { private int $textureSize; @@ -16,6 +15,10 @@ 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 { $textureSize = $this->textureSize; $mainHandFirst = round(0.039 * 16 / $textureSize, 8);