Last active
April 20, 2020 18:51
-
-
Save AlexIIL/129f797d20bcf8897a18cc42bfa848c4 to your computer and use it in GitHub Desktop.
Fabric custom item model loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A cut down version. This isn't compilabale as-is! | |
public class BCSiliconModels { | |
public static final ModelIdentifier CHIPSET_PART_A = new ModelIdentifier("buildcraftsilicon:redstone_chipset_a#inventory"); | |
public static final ModelIdentifier CHIPSET_PART_B = new ModelIdentifier("buildcraftsilicon:redstone_chipset_b#inventory"); | |
/** Called by the ClientModInitialiser */ | |
public static void load() { | |
ModelLoadingRegistry.INSTANCE.registerAppender((manager, out) -> { | |
out.accept(CHIPSET_PART_A); | |
out.accept(CHIPSET_PART_B); | |
}); | |
ModelLoadingRegistry.INSTANCE.registerVariantProvider(res -> (id, ctx) -> { | |
// The identifer for the item we want to replace | |
if ("buildcraft_silicon:redstone_chipset#inventory".equals(id.toString())) { | |
return new PreBakedModel(new BakedModel(){ | |
// Override all the normal methods to return either empty lists or something else | |
// The point is it's not imporatant, as they won't be used | |
final ModelItemPropertyOverrideList overrideList | |
= new ModelItemPropertyOverrideList(null, null, null, Collections.emptyList()) { | |
@Override | |
public BakedModel apply(BakedModel original, ItemStack stack, World world, LivingEntity entity) { | |
if (shouldUseVariantA(stack)) { | |
return MinecraftClient.getInstance().getBakedModelManager().getModel(CHIPSET_PART_A); | |
} else { | |
return MinecraftClient.getInstance().getBakedModelManager().getModel(CHIPSET_PART_B); | |
} | |
} | |
}; | |
@Override | |
public ModelItemPropertyOverrideList getItemPropertyOverrides() { | |
return overrideList; | |
} | |
}); | |
} | |
return null; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package buildcraft.lib.client.model; | |
import java.util.Collection; | |
import java.util.Collections; | |
import java.util.Set; | |
import java.util.function.Function; | |
import net.minecraft.client.render.model.BakedModel; | |
import net.minecraft.client.render.model.ModelBakeSettings; | |
import net.minecraft.client.render.model.ModelLoader; | |
import net.minecraft.client.render.model.UnbakedModel; | |
import net.minecraft.client.texture.Sprite; | |
import net.minecraft.util.Identifier; | |
public final class PreBakedModel implements UnbakedModel { | |
private final BakedModel baked; | |
public PreBakedModel(BakedModel baked) { | |
this.baked = baked; | |
} | |
@Override | |
public Collection<Identifier> getModelDependencies() { | |
return Collections.emptyList(); | |
} | |
@Override | |
public Collection<Identifier> getTextureDependencies(Function<Identifier, UnbakedModel> var1, Set<String> var2) { | |
return Collections.emptyList(); | |
} | |
@Override | |
public BakedModel bake(ModelLoader var1, Function<Identifier, Sprite> var2, ModelBakeSettings var3) { | |
return baked; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment