1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

Map animations separately from geometry

This commit is contained in:
Eclipse
2025-07-06 11:48:10 +00:00
parent 9348423977
commit c04493c24b
4 changed files with 14 additions and 11 deletions

View File

@@ -180,10 +180,14 @@ public class BedrockItemMapper {
} }
// TODO Should probably get a better way to get geometry texture // TODO Should probably get a better way to get geometry texture
Optional<BedrockGeometryContext> bedrockGeometry = customModel.map(model -> GeometryMapper.mapGeometry(definition.textureName(), model, texture)); String safeIdentifier = definition.textureName();
String bone = "bone";
Optional<BedrockGeometryContext> bedrockGeometry = customModel.map(model -> GeometryMapper.mapGeometry(safeIdentifier, bone, model, texture));
Optional<BedrockAnimationContext> bedrockAnimation = customModel.map(model -> AnimationMapper.mapAnimation(safeIdentifier, bone, model.getTopTransforms()));
itemConsumer.accept(new BedrockItem(bedrockIdentifier, definition.textureName(), texture, itemConsumer.accept(new BedrockItem(bedrockIdentifier, definition.textureName(), texture,
AttachableMapper.mapItem(componentPatch, bedrockIdentifier, bedrockGeometry, additionalTextureConsumer), bedrockGeometry.map(BedrockGeometryContext::geometry), AttachableMapper.mapItem(componentPatch, bedrockIdentifier, bedrockGeometry, bedrockAnimation, additionalTextureConsumer),
bedrockGeometry.map(BedrockGeometryContext::animation).map(BedrockAnimationContext::animation))); bedrockGeometry.map(BedrockGeometryContext::geometry), bedrockAnimation.map(BedrockAnimationContext::animation)));
} }
} }
} }

View File

@@ -9,6 +9,7 @@ import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.equipment.Equippable; import net.minecraft.world.item.equipment.Equippable;
import org.geysermc.packgenerator.mapping.animation.BedrockAnimationContext;
import org.geysermc.packgenerator.mapping.geometry.BedrockGeometryContext; import org.geysermc.packgenerator.mapping.geometry.BedrockGeometryContext;
import org.geysermc.packgenerator.mixin.EntityRenderDispatcherAccessor; import org.geysermc.packgenerator.mixin.EntityRenderDispatcherAccessor;
import org.geysermc.packgenerator.pack.attachable.BedrockAttachable; import org.geysermc.packgenerator.pack.attachable.BedrockAttachable;
@@ -20,7 +21,7 @@ import java.util.function.Consumer;
public class AttachableMapper { public class AttachableMapper {
public static Optional<BedrockAttachable> mapItem(DataComponentPatch components, ResourceLocation bedrockIdentifier, Optional<BedrockGeometryContext> customGeometry, public static Optional<BedrockAttachable> mapItem(DataComponentPatch components, ResourceLocation bedrockIdentifier, Optional<BedrockGeometryContext> customGeometry,
Consumer<ResourceLocation> textureConsumer) { Optional<BedrockAnimationContext> customAnimation, Consumer<ResourceLocation> textureConsumer) {
// Crazy optional statement // Crazy optional statement
// Unfortunately we can't have both equippables and custom models, so we prefer the latter :( // Unfortunately we can't have both equippables and custom models, so we prefer the latter :(
return customGeometry return customGeometry
@@ -41,7 +42,7 @@ public class AttachableMapper {
return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), texture.getPath()); return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), texture.getPath());
})) }))
.map(attachable -> { .map(attachable -> {
customGeometry.map(BedrockGeometryContext::animation).ifPresent(context -> { customAnimation.ifPresent(context -> {
attachable.withAnimation("first_person", context.firstPerson()); attachable.withAnimation("first_person", context.firstPerson());
attachable.withAnimation("third_person", context.thirdPerson()); attachable.withAnimation("third_person", context.thirdPerson());
attachable.withScript("animate", "first_person", "context.is_first_person == 1.0"); attachable.withScript("animate", "first_person", "context.is_first_person == 1.0");

View File

@@ -1,7 +1,6 @@
package org.geysermc.packgenerator.mapping.geometry; package org.geysermc.packgenerator.mapping.geometry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.geysermc.packgenerator.mapping.animation.BedrockAnimationContext;
import org.geysermc.packgenerator.pack.geometry.BedrockGeometry; import org.geysermc.packgenerator.pack.geometry.BedrockGeometry;
public record BedrockGeometryContext(BedrockGeometry geometry, BedrockAnimationContext animation, ResourceLocation texture) {} public record BedrockGeometryContext(BedrockGeometry geometry, ResourceLocation texture) {}

View File

@@ -7,7 +7,6 @@ import net.minecraft.client.renderer.block.model.SimpleUnbakedGeometry;
import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.geysermc.packgenerator.mapping.animation.AnimationMapper;
import org.geysermc.packgenerator.pack.geometry.BedrockGeometry; import org.geysermc.packgenerator.pack.geometry.BedrockGeometry;
import org.joml.Vector2f; import org.joml.Vector2f;
import org.joml.Vector3f; import org.joml.Vector3f;
@@ -18,7 +17,7 @@ import java.util.Map;
public class GeometryMapper { public class GeometryMapper {
private static final Vector3fc CENTRE_OFFSET = new Vector3f(8.0F, 0.0F, 8.0F); private static final Vector3fc CENTRE_OFFSET = new Vector3f(8.0F, 0.0F, 8.0F);
public static BedrockGeometryContext mapGeometry(String identifier, ResolvedModel model, ResourceLocation texture) { public static BedrockGeometryContext mapGeometry(String identifier, String boneName, ResolvedModel model, ResourceLocation texture) {
BedrockGeometry.Builder builder = BedrockGeometry.builder(identifier); BedrockGeometry.Builder builder = BedrockGeometry.builder(identifier);
// Blockbench seems to always use these values // Blockbench seems to always use these values
builder.withVisibleBoundsWidth(2.0F); builder.withVisibleBoundsWidth(2.0F);
@@ -29,7 +28,7 @@ public class GeometryMapper {
builder.withTextureWidth(16); builder.withTextureWidth(16);
builder.withTextureHeight(16); builder.withTextureHeight(16);
BedrockGeometry.Bone.Builder bone = BedrockGeometry.bone(identifier); BedrockGeometry.Bone.Builder bone = BedrockGeometry.bone(boneName);
Vector3f min = new Vector3f(Float.MAX_VALUE); Vector3f min = new Vector3f(Float.MAX_VALUE);
Vector3f max = new Vector3f(Float.MIN_VALUE); Vector3f max = new Vector3f(Float.MIN_VALUE);
@@ -48,7 +47,7 @@ public class GeometryMapper {
// Bind to the bone of the current item slot // Bind to the bone of the current item slot
bone.withBinding("q.item_slot_to_bone_name(context.item_slot)"); bone.withBinding("q.item_slot_to_bone_name(context.item_slot)");
return new BedrockGeometryContext(builder.withBone(bone).build(), AnimationMapper.mapAnimation(identifier, identifier, model.getTopTransforms()), texture); return new BedrockGeometryContext(builder.withBone(bone).build(), texture);
} }
private static BedrockGeometry.Cube.Builder mapBlockElement(BlockElement element) { private static BedrockGeometry.Cube.Builder mapBlockElement(BlockElement element) {