Migrated some API calls

This commit is contained in:
Frank 2022-11-12 12:10:59 +01:00
parent c11fca74a5
commit daa4a2b4af
56 changed files with 172 additions and 167 deletions

View file

@ -9,7 +9,6 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.level.block.Block;
@ -32,38 +31,44 @@ public class CustomModelBakery {
}
public void loadCustomModels(ResourceManager resourceManager) {
Registry.BLOCK.stream().parallel().filter(block -> block instanceof BlockModelProvider).forEach(block -> {
ResourceLocation blockID = Registry.BLOCK.getKey(block);
ResourceLocation storageID = new ResourceLocation(
blockID.getNamespace(),
"blockstates/" + blockID.getPath() + ".json"
);
if (resourceManager.getResource(storageID).isEmpty()) {
addBlockModel(blockID, block);
}
storageID = new ResourceLocation(blockID.getNamespace(), "models/item/" + blockID.getPath() + ".json");
if (resourceManager.getResource(storageID).isEmpty()) {
addItemModel(blockID, (ItemModelProvider) block);
}
});
BuiltInRegistries.BLOCK.stream()
.parallel()
.filter(block -> block instanceof BlockModelProvider)
.forEach(block -> {
ResourceLocation blockID = BuiltInRegistries.BLOCK.getKey(block);
ResourceLocation storageID = new ResourceLocation(
blockID.getNamespace(),
"blockstates/" + blockID.getPath() + ".json"
);
if (resourceManager.getResource(storageID).isEmpty()) {
addBlockModel(blockID, block);
}
storageID = new ResourceLocation(
blockID.getNamespace(),
"models/item/" + blockID.getPath() + ".json"
);
if (resourceManager.getResource(storageID).isEmpty()) {
addItemModel(blockID, (ItemModelProvider) block);
}
});
Registry.ITEM.stream()
.parallel()
.filter(item -> item instanceof ItemModelProvider || RecordItemModelProvider.has(item))
.forEach(item -> {
ResourceLocation registryID = Registry.ITEM.getKey(item);
ResourceLocation storageID = new ResourceLocation(
registryID.getNamespace(),
"models/item/" + registryID.getPath() + ".json"
);
final ItemModelProvider provider = (item instanceof ItemModelProvider)
? (ItemModelProvider) item
: RecordItemModelProvider.get(item);
BuiltInRegistries.ITEM.stream()
.parallel()
.filter(item -> item instanceof ItemModelProvider || RecordItemModelProvider.has(item))
.forEach(item -> {
ResourceLocation registryID = BuiltInRegistries.ITEM.getKey(item);
ResourceLocation storageID = new ResourceLocation(
registryID.getNamespace(),
"models/item/" + registryID.getPath() + ".json"
);
final ItemModelProvider provider = (item instanceof ItemModelProvider)
? (ItemModelProvider) item
: RecordItemModelProvider.get(item);
if (resourceManager.getResource(storageID).isEmpty()) {
addItemModel(registryID, provider);
}
});
if (resourceManager.getResource(storageID).isEmpty()) {
addItemModel(registryID, provider);
}
});
}
private void addBlockModel(ResourceLocation blockID, Block block) {

View file

@ -13,7 +13,6 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
@ -165,7 +164,7 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
}
public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block);
ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(block);
String modId = blockId.getNamespace();
String path = blockId.getPath();
LAYERS.put(

View file

@ -18,7 +18,6 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.SignRenderer;
import net.minecraft.client.resources.model.Material;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Mth;
@ -181,7 +180,7 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
}
public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block);
ResourceLocation blockId = BuiltInRegistries.BLOCK.getKey(block);
RenderType layer = RenderType.entitySolid(new ResourceLocation(
blockId.getNamespace(),
"textures/entity/sign/" + blockId.getPath() + ".png"