mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Generate attachables for custom geometries, use proper geometry identifiers
This commit is contained in:
@@ -31,6 +31,7 @@ import org.geysermc.packgenerator.accessor.BlockModelWrapperLocationAccessor;
|
||||
import org.geysermc.packgenerator.accessor.ResolvedModelAccessor;
|
||||
import org.geysermc.packgenerator.accessor.SelectItemModelCasesAccessor;
|
||||
import org.geysermc.packgenerator.mapping.attachable.AttachableMapper;
|
||||
import org.geysermc.packgenerator.mapping.geometry.BedrockGeometryContext;
|
||||
import org.geysermc.packgenerator.mapping.geometry.GeometryMapper;
|
||||
import org.geysermc.packgenerator.mapping.geyser.GeyserMappings;
|
||||
import org.geysermc.packgenerator.mapping.geyser.GeyserSingleDefinition;
|
||||
@@ -40,6 +41,7 @@ import org.geysermc.packgenerator.mapping.geyser.predicate.GeyserPredicate;
|
||||
import org.geysermc.packgenerator.mixin.ConditionalItemModelAccessor;
|
||||
import org.geysermc.packgenerator.mixin.SelectItemModelAccessor;
|
||||
import org.geysermc.packgenerator.pack.BedrockItem;
|
||||
import org.geysermc.packgenerator.pack.geometry.BedrockGeometry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -175,9 +177,12 @@ public class BedrockItemMapper {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO Should probably get a better way to get geometry texture
|
||||
Optional<BedrockGeometry> bedrockGeometry = customGeometry.map(geometry -> GeometryMapper.mapGeometry(definition.textureName(), geometry));
|
||||
Optional<BedrockGeometryContext> geometryInfo = bedrockGeometry.map(geometry -> new BedrockGeometryContext(geometry.definitions().getFirst(), texture));
|
||||
|
||||
itemConsumer.accept(new BedrockItem(bedrockIdentifier, definition.textureName(), texture,
|
||||
AttachableMapper.mapItem(componentPatch, bedrockIdentifier, additionalTextureConsumer),
|
||||
customGeometry.map(geometry -> GeometryMapper.mapGeometry(definition.textureName(), geometry))));
|
||||
AttachableMapper.mapItem(componentPatch, bedrockIdentifier, geometryInfo, additionalTextureConsumer), bedrockGeometry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.equipment.Equippable;
|
||||
import org.geysermc.packgenerator.mapping.geometry.BedrockGeometryContext;
|
||||
import org.geysermc.packgenerator.mixin.EntityRenderDispatcherAccessor;
|
||||
import org.geysermc.packgenerator.pack.attachable.BedrockAttachable;
|
||||
|
||||
@@ -18,23 +19,27 @@ import java.util.function.Consumer;
|
||||
|
||||
public class AttachableMapper {
|
||||
|
||||
public static Optional<BedrockAttachable> mapItem(DataComponentPatch components, ResourceLocation bedrockIdentifier, Consumer<ResourceLocation> textureConsumer) {
|
||||
public static Optional<BedrockAttachable> mapItem(DataComponentPatch components, ResourceLocation bedrockIdentifier, Optional<BedrockGeometryContext> customGeometry,
|
||||
Consumer<ResourceLocation> textureConsumer) {
|
||||
// Crazy optional statement
|
||||
return Optional.ofNullable(components.get(DataComponents.EQUIPPABLE))
|
||||
.flatMap(optional -> (Optional<Equippable>) optional)
|
||||
.flatMap(equippable -> {
|
||||
EquipmentAssetManager equipmentAssets = ((EntityRenderDispatcherAccessor) Minecraft.getInstance().getEntityRenderDispatcher()).getEquipmentAssets();
|
||||
return equippable.assetId().map(asset -> Pair.of(equippable.slot(), equipmentAssets.get(asset)));
|
||||
})
|
||||
.filter(assetInfo -> assetInfo.getSecond() != EquipmentAssetManager.MISSING)
|
||||
.map(assetInfo -> assetInfo
|
||||
.mapSecond(info -> info.getLayers(getLayer(assetInfo.getFirst()))))
|
||||
.filter(assetInfo -> !assetInfo.getSecond().isEmpty())
|
||||
.map(assetInfo -> {
|
||||
ResourceLocation texture = getTexture(assetInfo.getSecond(), getLayer(assetInfo.getFirst()));
|
||||
textureConsumer.accept(texture);
|
||||
return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), texture.getPath());
|
||||
});
|
||||
// Unfortunately we can't have both equippables and custom models, so we prefer the latter :(
|
||||
return customGeometry
|
||||
.map(geometry -> BedrockAttachable.geometry(bedrockIdentifier, geometry.geometry(), geometry.texture().getPath()))
|
||||
.or(() -> Optional.ofNullable(components.get(DataComponents.EQUIPPABLE))
|
||||
.flatMap(optional -> (Optional<Equippable>) optional)
|
||||
.flatMap(equippable -> {
|
||||
EquipmentAssetManager equipmentAssets = ((EntityRenderDispatcherAccessor) Minecraft.getInstance().getEntityRenderDispatcher()).getEquipmentAssets();
|
||||
return equippable.assetId().map(asset -> Pair.of(equippable.slot(), equipmentAssets.get(asset)));
|
||||
})
|
||||
.filter(assetInfo -> assetInfo.getSecond() != EquipmentAssetManager.MISSING)
|
||||
.map(assetInfo -> assetInfo
|
||||
.mapSecond(info -> info.getLayers(getLayer(assetInfo.getFirst()))))
|
||||
.filter(assetInfo -> !assetInfo.getSecond().isEmpty())
|
||||
.map(assetInfo -> {
|
||||
ResourceLocation texture = getTexture(assetInfo.getSecond(), getLayer(assetInfo.getFirst()));
|
||||
textureConsumer.accept(texture);
|
||||
return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), texture.getPath());
|
||||
}));
|
||||
}
|
||||
|
||||
private static EquipmentClientInfo.LayerType getLayer(EquipmentSlot slot) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.geysermc.packgenerator.mapping.geometry;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.geysermc.packgenerator.pack.geometry.BedrockGeometry;
|
||||
|
||||
public record BedrockGeometryContext(BedrockGeometry.GeometryDefinition geometry, ResourceLocation texture) {}
|
||||
@@ -61,7 +61,7 @@ public record BedrockGeometry(BedrockVersion formatVersion, List<GeometryDefinit
|
||||
private Optional<Integer> textureHeight = Optional.empty();
|
||||
|
||||
public Builder(String identifier) {
|
||||
this.identifier = identifier;
|
||||
this.identifier = "geometry." + identifier;
|
||||
}
|
||||
|
||||
public Builder withVisibleBoundsWidth(float visibleBoundsWidth) {
|
||||
|
||||
Reference in New Issue
Block a user