mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Use any possible texture when layer0 doesn't exist
This commit is contained in:
@@ -52,6 +52,7 @@ import org.geysermc.rainbow.mapping.geyser.predicate.GeyserPredicate;
|
|||||||
import org.geysermc.rainbow.mixin.ConditionalItemModelAccessor;
|
import org.geysermc.rainbow.mixin.ConditionalItemModelAccessor;
|
||||||
import org.geysermc.rainbow.mixin.RangeSelectItemModelAccessor;
|
import org.geysermc.rainbow.mixin.RangeSelectItemModelAccessor;
|
||||||
import org.geysermc.rainbow.mixin.SelectItemModelAccessor;
|
import org.geysermc.rainbow.mixin.SelectItemModelAccessor;
|
||||||
|
import org.geysermc.rainbow.mixin.TextureSlotsAccessor;
|
||||||
import org.geysermc.rainbow.pack.BedrockItem;
|
import org.geysermc.rainbow.pack.BedrockItem;
|
||||||
import org.geysermc.rainbow.pack.BedrockTextures;
|
import org.geysermc.rainbow.pack.BedrockTextures;
|
||||||
|
|
||||||
@@ -108,31 +109,38 @@ public class BedrockItemMapper {
|
|||||||
((ResolvedModelAccessor) Minecraft.getInstance().getModelManager()).rainbow$getResolvedModel(itemModelLocation)
|
((ResolvedModelAccessor) Minecraft.getInstance().getModelManager()).rainbow$getResolvedModel(itemModelLocation)
|
||||||
.ifPresentOrElse(itemModel -> {
|
.ifPresentOrElse(itemModel -> {
|
||||||
ResolvedModel parentModel = itemModel.parent();
|
ResolvedModel parentModel = itemModel.parent();
|
||||||
boolean handheld = false;
|
// debugName() returns the resource location of the model as a string
|
||||||
if (parentModel != null) {
|
boolean handheld = parentModel != null && HANDHELD_MODELS.contains(ResourceLocation.parse(parentModel.debugName()));
|
||||||
// debugName() returns the resource location of the model as a string
|
|
||||||
handheld = HANDHELD_MODELS.contains(ResourceLocation.parse(parentModel.debugName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceLocation bedrockIdentifier = itemModelLocation;
|
ResourceLocation bedrockIdentifier;
|
||||||
if (bedrockIdentifier.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE)) {
|
if (itemModelLocation.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE)) {
|
||||||
bedrockIdentifier = ResourceLocation.fromNamespaceAndPath("geyser_mc", itemModelLocation.getPath());
|
bedrockIdentifier = ResourceLocation.fromNamespaceAndPath("geyser_mc", itemModelLocation.getPath());
|
||||||
|
} else {
|
||||||
|
bedrockIdentifier = itemModelLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceLocation texture = itemModelLocation;
|
|
||||||
Material layer0Texture = itemModel.getTopTextureSlots().getMaterial("layer0");
|
Material layer0Texture = itemModel.getTopTextureSlots().getMaterial("layer0");
|
||||||
Optional<ResolvedModel> customGeometry = Optional.empty();
|
Optional<ResourceLocation> texture;
|
||||||
|
Optional<ResolvedModel> customGeometry;
|
||||||
if (layer0Texture != null) {
|
if (layer0Texture != null) {
|
||||||
texture = layer0Texture.texture();
|
texture = Optional.of(layer0Texture.texture());
|
||||||
|
customGeometry = Optional.empty();
|
||||||
} else {
|
} else {
|
||||||
|
// We can't stitch multiple textures together yet, so we just grab the first one we see
|
||||||
|
// This will only work properly for models with just one texture
|
||||||
|
texture = ((TextureSlotsAccessor) itemModel.getTopTextureSlots()).getResolvedValues().values().stream()
|
||||||
|
.map(Material::texture)
|
||||||
|
.findAny();
|
||||||
// Unknown texture (doesn't use layer0), so we immediately assume the geometry is custom
|
// Unknown texture (doesn't use layer0), so we immediately assume the geometry is custom
|
||||||
// This check should probably be done differently
|
// This check should probably be done differently
|
||||||
customGeometry = Optional.of(itemModel);
|
customGeometry = Optional.of(itemModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not a problem, but just report to get the model printed in the report file
|
texture.ifPresentOrElse(itemTexture -> {
|
||||||
context.reporter.report(() -> "creating mapping for block model " + itemModelLocation);
|
// Not a problem, but just report to get the model printed in the report file
|
||||||
context.create(bedrockIdentifier, texture, handheld, customGeometry);
|
context.reporter.report(() -> "creating mapping for block model " + itemModelLocation);
|
||||||
|
context.create(bedrockIdentifier, itemTexture, handheld, customGeometry);
|
||||||
|
}, () -> context.reporter.report(() -> "not mapping block model " + itemModelLocation + " because it has no texture"));
|
||||||
}, () -> context.reporter.report(() -> "missing block model " + itemModelLocation));
|
}, () -> context.reporter.report(() -> "missing block model " + itemModelLocation));
|
||||||
}
|
}
|
||||||
case ConditionalItemModel conditional -> mapConditionalModel(conditional, context.child("condition model "));
|
case ConditionalItemModel conditional -> mapConditionalModel(conditional, context.child("condition model "));
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.geysermc.rainbow.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.block.model.TextureSlots;
|
||||||
|
import net.minecraft.client.resources.model.Material;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mixin(TextureSlots.class)
|
||||||
|
public interface TextureSlotsAccessor {
|
||||||
|
|
||||||
|
@Accessor
|
||||||
|
Map<String, Material> getResolvedValues();
|
||||||
|
}
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
"SelectItemModelAccessor",
|
"SelectItemModelAccessor",
|
||||||
"SelectItemModelMixin",
|
"SelectItemModelMixin",
|
||||||
"SelectItemModelMixin$UnbakedSwitchMixin",
|
"SelectItemModelMixin$UnbakedSwitchMixin",
|
||||||
"SplashRendererAccessor"
|
"SplashRendererAccessor",
|
||||||
|
"TextureSlotsAccessor"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
Reference in New Issue
Block a user