diff --git a/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.java.patch b/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.java.patch index 15086362c3..f7fad50b17 100644 --- a/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.java.patch +++ b/patches/minecraft/net/minecraft/client/renderer/texture/TextureMap.java.patch @@ -136,6 +136,15 @@ } private boolean func_184397_a(IResourceManager p_184397_1_, final TextureAtlasSprite p_184397_2_) +@@ -194,7 +239,7 @@ + label9: + { + boolean flag; +- ++ if (p_184397_2_.hasCustomLoader(p_184397_1_, resourcelocation)) break label9; + try + { + iresource = p_184397_1_.func_110536_a(resourcelocation); @@ -317,4 +362,37 @@ { return this.field_94249_f; diff --git a/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java b/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java index 4700d20337..e813982b18 100644 --- a/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java +++ b/src/main/java/net/minecraftforge/client/model/BlockStateLoader.java @@ -163,6 +163,7 @@ public class BlockStateLoader public IModel process(IModel base) { int size = parts.size(); + // FIXME: should missing base be handled this way? boolean hasBase = base != ModelLoaderRegistry.getMissingModel(); if (hasBase) @@ -182,7 +183,7 @@ public class BlockStateLoader { SubModel part = entry.getValue(); - IModel model = ModelLoaderRegistry.getModel(part.getModelLocation()); + IModel model = ModelLoaderRegistry.getModelOrLogError(part.getModelLocation(), "Unable to load block sub-model: \'" + part.getModelLocation()); IModelState partState = new ModelStateComposition(baseTr, part.getState()); diff --git a/src/main/java/net/minecraftforge/client/model/ICustomModelLoader.java b/src/main/java/net/minecraftforge/client/model/ICustomModelLoader.java index 6dd74668f9..3aea07e733 100644 --- a/src/main/java/net/minecraftforge/client/model/ICustomModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ICustomModelLoader.java @@ -14,5 +14,5 @@ public interface ICustomModelLoader extends IResourceManagerReloadListener /* * loads (or reloads) specified model */ - public IModel loadModel(ResourceLocation modelLocation); + public IModel loadModel(ResourceLocation modelLocation) throws Exception; } diff --git a/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java b/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java index b8946e1003..7d23d4dc72 100644 --- a/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java +++ b/src/main/java/net/minecraftforge/client/model/ItemLayerModel.java @@ -29,7 +29,7 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -public class ItemLayerModel implements IRetexturableModel +public final class ItemLayerModel implements IRetexturableModel { public static final ItemLayerModel instance = new ItemLayerModel(ImmutableList.of()); @@ -108,7 +108,7 @@ public class ItemLayerModel implements IRetexturableModel return new BakedItemModel(builder.build(), particle, map, overrides, null); } - private static class BakedItemModel implements IPerspectiveAwareModel + private static final class BakedItemModel implements IPerspectiveAwareModel { private final ImmutableList quads; private final TextureAtlasSprite particle; @@ -170,7 +170,7 @@ public class ItemLayerModel implements IRetexturableModel } } - public ImmutableList getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional transform) + public static ImmutableList getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional transform) { ImmutableList.Builder builder = ImmutableList.builder(); @@ -240,7 +240,7 @@ public class ItemLayerModel implements IRetexturableModel return builder.build(); } - protected boolean isTransparent(int[] pixels, int uMax, int vMax, int u, int v) + private static boolean isTransparent(int[] pixels, int uMax, int vMax, int u, int v) { return (pixels[u + (vMax - 1 - v) * uMax] >> 24 & 0xFF) == 0; } diff --git a/src/main/java/net/minecraftforge/client/model/ModelDynBucket.java b/src/main/java/net/minecraftforge/client/model/ModelDynBucket.java index 6b4303126c..31f28744a1 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelDynBucket.java +++ b/src/main/java/net/minecraftforge/client/model/ModelDynBucket.java @@ -39,7 +39,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; -public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableModel +public final class ModelDynBucket implements IModel, IModelCustomData, IRetexturableModel { public static final ModelResourceLocation LOCATION = new ModelResourceLocation(new ResourceLocation("forge", "dynbucket"), "inventory"); @@ -51,12 +51,12 @@ public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableMo public static final IModel MODEL = new ModelDynBucket(); - protected final ResourceLocation baseLocation; - protected final ResourceLocation liquidLocation; - protected final ResourceLocation coverLocation; + private final ResourceLocation baseLocation; + private final ResourceLocation liquidLocation; + private final ResourceLocation coverLocation; - protected final Fluid fluid; - protected final boolean flipGas; + private final Fluid fluid; + private final boolean flipGas; public ModelDynBucket() { @@ -223,7 +223,7 @@ public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableMo } } - protected static final class BakedDynBucketOverrideHandler extends ItemOverrideList + private static final class BakedDynBucketOverrideHandler extends ItemOverrideList { public static final BakedDynBucketOverrideHandler INSTANCE = new BakedDynBucketOverrideHandler(); private BakedDynBucketOverrideHandler() @@ -277,7 +277,7 @@ public class ModelDynBucket implements IModel, IModelCustomData, IRetexturableMo } // the dynamic bucket is based on the empty bucket - protected static class BakedDynBucket implements IPerspectiveAwareModel + private static final class BakedDynBucket implements IPerspectiveAwareModel { private final ModelDynBucket parent; diff --git a/src/main/java/net/minecraftforge/client/model/ModelFluid.java b/src/main/java/net/minecraftforge/client/model/ModelFluid.java index 2543037a57..a876fc4796 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelFluid.java +++ b/src/main/java/net/minecraftforge/client/model/ModelFluid.java @@ -43,7 +43,7 @@ import com.google.common.collect.Maps; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -public class ModelFluid implements IModelCustomData +public final class ModelFluid implements IModelCustomData { public static final ModelFluid waterModel = new ModelFluid(FluidRegistry.WATER); public static final ModelFluid lavaModel = new ModelFluid(FluidRegistry.LAVA); @@ -95,7 +95,7 @@ public class ModelFluid implements IModelCustomData } } - public static class BakedFluid implements IPerspectiveAwareModel + private static final class BakedFluid implements IPerspectiveAwareModel { private static final int x[] = { 0, 0, 1, 1 }; private static final int z[] = { 0, 1, 1, 0 }; @@ -126,16 +126,6 @@ public class ModelFluid implements IModelCustomData private final boolean gas; private final EnumMap> faceQuads; - public BakedFluid(Optional transformation, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas) - { - this(transformation, format, color, still, flowing, gas, Optional.absent()); - } - - public BakedFluid(Optional transformation, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, Optional stateOption) - { - this(transformation, ImmutableMap.of(), format, color, still, flowing, gas, stateOption); - } - public BakedFluid(Optional transformation, ImmutableMap transforms, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, Optional stateOption) { this(transformation, transforms, format, color, still, flowing, gas, stateOption.isPresent(), getCorners(stateOption), getFlow(stateOption)); diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoader.java b/src/main/java/net/minecraftforge/client/model/ModelLoader.java index 781bafbe2b..b3c8280ab4 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoader.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoader.java @@ -10,12 +10,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Queue; import java.util.Set; -import com.google.common.base.Joiner; -import com.google.common.collect.*; - import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -26,15 +22,24 @@ import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BlockPart; import net.minecraft.client.renderer.block.model.BlockPartFace; import net.minecraft.client.renderer.block.model.BlockPartRotation; +import net.minecraft.client.renderer.block.model.BuiltInModel; +import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.block.model.ItemModelGenerator; +import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelBlock; import net.minecraft.client.renderer.block.model.ModelBlockDefinition; import net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.block.model.ModelRotation; import net.minecraft.client.renderer.block.model.MultipartBakedModel; +import net.minecraft.client.renderer.block.model.SimpleBakedModel; import net.minecraft.client.renderer.block.model.Variant; import net.minecraft.client.renderer.block.model.VariantList; +import net.minecraft.client.renderer.block.model.WeightedBakedModel; +import net.minecraft.client.renderer.block.model.multipart.Multipart; +import net.minecraft.client.renderer.block.model.multipart.Selector; import net.minecraft.client.renderer.block.statemap.IStateMapper; import net.minecraft.client.renderer.texture.IIconCreator; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -42,22 +47,13 @@ import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.resources.IResourceManager; -import net.minecraft.client.renderer.block.model.BuiltInModel; -import net.minecraft.client.renderer.block.model.IBakedModel; -import net.minecraft.client.renderer.block.model.ModelBakery; -import net.minecraft.client.renderer.block.model.ModelResourceLocation; -import net.minecraft.client.renderer.block.model.ModelRotation; -import net.minecraft.client.renderer.block.model.SimpleBakedModel; -import net.minecraft.client.renderer.block.model.WeightedBakedModel; -import net.minecraft.client.renderer.block.model.multipart.Multipart; -import net.minecraft.client.renderer.block.model.multipart.Selector; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.launchwrapper.Launch; import net.minecraft.util.EnumFacing; -import net.minecraft.util.registry.IRegistry; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.registry.IRegistry; import net.minecraftforge.client.model.animation.Animation; import net.minecraftforge.client.model.animation.IAnimatedModel; import net.minecraftforge.client.model.animation.IClip; @@ -78,9 +74,18 @@ import net.minecraftforge.fml.common.registry.RegistryDelegate; import org.apache.commons.lang3.tuple.Pair; import com.google.common.base.Function; +import com.google.common.base.Joiner; import com.google.common.base.Optional; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; -public class ModelLoader extends ModelBakery +public final class ModelLoader extends ModelBakery { private final Map stateModels = Maps.newHashMap(); private final Set missingVariants = Sets.newHashSet(); @@ -110,7 +115,7 @@ public class ModelLoader extends ModelBakery isLoading = true; loadBlocks(); loadVariantItemModels(); - missingModel = ModelLoaderRegistry.getModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath())); + missingModel = ModelLoaderRegistry.getMissingModel(); stateModels.put(MODEL_MISSING, missingModel); final Set textures = Sets.newHashSet(ModelLoaderRegistry.getTextures()); @@ -181,7 +186,17 @@ public class ModelLoader extends ModelBakery @Override protected void registerVariant(ModelBlockDefinition definition, ModelResourceLocation location) { - stateModels.put(location, ModelLoaderRegistry.getModel(location)); + IModel model; + try + { + model = ModelLoaderRegistry.getModel(location); + } + catch(Exception e) + { + storeException(location, e); + model = getMissingModel(); + } + stateModels.put(location, model); } @Override @@ -189,7 +204,7 @@ public class ModelLoader extends ModelBakery { for (ModelResourceLocation location : locations) { - stateModels.put(location, ModelLoaderRegistry.getModel(location)); + registerVariant(null, location); } } @@ -235,25 +250,27 @@ public class ModelLoader extends ModelBakery ResourceLocation file = getItemLocation(s); ModelResourceLocation memory = getInventoryVariant(s); itemBar.step(memory.toString()); + IModel model = ModelLoaderRegistry.getMissingModel(); + Exception exception = null; try { - IModel model = ModelLoaderRegistry.getModel(file); - if(model == getMissingModel()) - { - // try blockstate json if the item model is missing - FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json"); - try - { - model = ModelLoaderRegistry.getModel(memory); - } - catch (Exception exception) - { - storeException(memory, new Exception("Could not load item model either from the normal location " + file + " or from the blockstate", exception)); - } - } - stateModels.put(memory, model); + model = ModelLoaderRegistry.getModel(file); } - catch (Exception exception) + catch(Exception e) + { + // try blockstate json if the item model is missing + FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json"); + try + { + model = ModelLoaderRegistry.getModel(memory); + } + catch (Exception ex) + { + exception = new Exception("Could not load item model either from the normal location " + file + " or from the blockstate", ex); + } + } + stateModels.put(memory, model); + if(exception != null) { storeException(memory, exception); } @@ -282,7 +299,7 @@ public class ModelLoader extends ModelBakery for(String s : getVariantNames(Items.bucket)) { ModelResourceLocation memory = getInventoryVariant(s); - IModel model = ModelLoaderRegistry.getModel(new ResourceLocation("forge", "item/bucket")); + IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forge", "item/bucket")); // only on successful load, otherwise continue using the old model if(model != getMissingModel()) { @@ -309,7 +326,7 @@ public class ModelLoader extends ModelBakery for(String s : getVariantNames(Items.milk_bucket)) { ModelResourceLocation memory = getInventoryVariant(s); - IModel model = ModelLoaderRegistry.getModel(new ResourceLocation("forge", "item/bucket_milk")); + IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("forge", "item/bucket_milk")); // only on successful load, otherwise continue using the old model if(model != getMissingModel()) { @@ -348,7 +365,7 @@ public class ModelLoader extends ModelBakery return new ResourceLocation(model.getResourceDomain(), model.getResourcePath() + ".json"); } - private class VanillaModelWrapper implements IRetexturableModel, IModelSimpleProperties, IModelUVLock, IAnimatedModel + private final class VanillaModelWrapper implements IRetexturableModel, IModelSimpleProperties, IModelUVLock, IAnimatedModel { private final ResourceLocation location; private final ModelBlock model; @@ -372,7 +389,7 @@ public class ModelLoader extends ModelBakery { set.add(dep); // TODO: check if this can go somewhere else, random access to global things is bad - stateModels.put(getInventoryVariant(dep.toString()), ModelLoaderRegistry.getModel(dep)); + stateModels.put(getInventoryVariant(dep.toString()), ModelLoaderRegistry.getModelOrLogError(dep, "Could not load override model " + dep + " for model " + location)); } } if(model.getParentLocation() != null && !model.getParentLocation().getResourcePath().startsWith("builtin/")) @@ -393,11 +410,7 @@ public class ModelLoader extends ModelBakery } else { - IModel parent = ModelLoaderRegistry.getModel(model.getParentLocation()); - if(parent == getMissingModel()) - { - FMLLog.warning("Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model); - } + IModel parent = ModelLoaderRegistry.getModelOrLogError(model.getParentLocation(), "Could not load vanilla model parent '" + model.getParentLocation() + "' for '" + model); if(parent instanceof VanillaModelWrapper) { model.parent = ((VanillaModelWrapper) parent).model; @@ -629,7 +642,7 @@ public class ModelLoader extends ModelBakery } } - private static class WeightedRandomModel implements IModel + private static final class WeightedRandomModel implements IModel { private final List variants; private final List locations = new ArrayList(); @@ -637,7 +650,7 @@ public class ModelLoader extends ModelBakery private final List models = new ArrayList(); private final IModelState defaultState; - public WeightedRandomModel(ResourceLocation parent, VariantList variants) + public WeightedRandomModel(ResourceLocation parent, VariantList variants) throws Exception { this.variants = variants.getVariantList(); ImmutableList.Builder> builder = ImmutableList.builder(); @@ -646,21 +659,11 @@ public class ModelLoader extends ModelBakery ResourceLocation loc = v.getModelLocation(); locations.add(loc); - IModel model = null; - try - { - model = ModelLoaderRegistry.getModel(loc); - } - catch (Exception e) - { - /* - * Vanilla eats this, which makes it only show variants that have models. - * But that doesn't help debugging, so we maintain the missing model - * so that resource pack makers have a hint that their states are broken. - */ - FMLLog.getLogger().error("Unable to load block model: \'" + loc + "\' for variant: \'" + parent, e); - model = ModelLoaderRegistry.getMissingModel(); - } + /* + * Vanilla eats this, which makes it only show variants that have models. + * But that doesn't help debugging, so throw the exception + */ + IModel model = ModelLoaderRegistry.getModel(loc); // FIXME: is this the place? messes up dependency and texture resolution if (v instanceof ISmartVariant) @@ -668,7 +671,7 @@ public class ModelLoader extends ModelBakery model = ((ISmartVariant)v).process(model); for(ResourceLocation location : model.getDependencies()) { - ModelLoaderRegistry.getModel(location); + ModelLoaderRegistry.getModelOrMissing(location); } //FMLLog.getLogger().error("Exception resolving indirect dependencies for model" + loc, e); textures.addAll(model.getTextures()); // Kick this, just in case. @@ -680,6 +683,7 @@ public class ModelLoader extends ModelBakery if (models.size() == 0) //If all variants are missing, add one with the missing model and default rotation. { + // FIXME: log this? IModel missing = ModelLoaderRegistry.getMissingModel(); models.add(missing); builder.add(Pair.of(missing, TRSRTransformation.identity())); @@ -728,7 +732,14 @@ public class ModelLoader extends ModelBakery { if (missingModel == null) { - missingModel = VanillaLoader.instance.loadModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath())); + try + { + missingModel = VanillaLoader.instance.loadModel(new ResourceLocation(MODEL_MISSING.getResourceDomain(), MODEL_MISSING.getResourcePath())); + } + catch(Exception e) + { + throw new RuntimeException("Missing the missing model, this should never happen"); + } } return missingModel; } @@ -738,7 +749,7 @@ public class ModelLoader extends ModelBakery return itemModel; } - static enum VanillaLoader implements ICustomModelLoader + protected static enum VanillaLoader implements ICustomModelLoader { instance; @@ -764,7 +775,7 @@ public class ModelLoader extends ModelBakery return true; } - public IModel loadModel(ResourceLocation modelLocation) + public IModel loadModel(ResourceLocation modelLocation) throws Exception { String modelPath = modelLocation.getResourcePath(); if(modelLocation.getResourcePath().startsWith("models/")) @@ -773,21 +784,8 @@ public class ModelLoader extends ModelBakery } ResourceLocation armatureLocation = new ResourceLocation(modelLocation.getResourceDomain(), "armatures/" + modelPath + ".json"); ModelBlockAnimation animation = Animation.INSTANCE.loadVanillaAnimation(armatureLocation); - ModelBlock model = null; - try - { - model = loader.loadModel(modelLocation); - } - catch(Exception e) - { - // FIXME better error reporting? - FMLLog.getLogger().error("Unable to load vanilla model " + modelLocation, e); - } - if(model != null) - { - return loader.new VanillaModelWrapper(modelLocation, model, false, animation); - } - return ModelLoaderRegistry.getMissingModel(); + ModelBlock model = loader.loadModel(modelLocation); + return loader.new VanillaModelWrapper(modelLocation, model, false, animation); } @Override @@ -797,7 +795,7 @@ public class ModelLoader extends ModelBakery } } - public static class White extends TextureAtlasSprite + public static final class White extends TextureAtlasSprite { public static ResourceLocation loc = new ResourceLocation("white"); public static White instance = new White(); @@ -824,6 +822,7 @@ public class ModelLoader extends ModelBakery int[][] pixels = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][]; pixels[0] = new int[image.getWidth() * image.getHeight()]; image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels[0], 0, image.getWidth()); + this.clearFramesTextureData(); this.framesTextureData.add(pixels); return false; } @@ -1045,7 +1044,7 @@ public class ModelLoader extends ModelBakery } @Override - public IModel loadModel(ResourceLocation modelLocation) + public IModel loadModel(ResourceLocation modelLocation) throws Exception { ModelResourceLocation variant = (ModelResourceLocation) modelLocation; ModelBlockDefinition definition = loader.getModelBlockDefinition(variant); @@ -1060,9 +1059,8 @@ public class ModelLoader extends ModelBakery { return new MultipartModel(new ResourceLocation(variant.getResourceDomain(), variant.getResourcePath()), definition.getMultipartData()); } - // FIXME log missing model? + throw e; } - return ModelLoaderRegistry.getMissingModel(); } @Override @@ -1078,7 +1076,7 @@ public class ModelLoader extends ModelBakery private final Multipart multipart; private final ImmutableMap partModels; - public MultipartModel(ResourceLocation location, Multipart multipart) + public MultipartModel(ResourceLocation location, Multipart multipart) throws Exception { this.location = location; this.multipart = multipart; diff --git a/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java b/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java index 13089f744f..3f64a7c71d 100644 --- a/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java +++ b/src/main/java/net/minecraftforge/client/model/ModelLoaderRegistry.java @@ -69,7 +69,7 @@ public class ModelLoaderRegistry * ResourceLocation argument will be passed directly to the custom model loaders, * ModelResourceLocation argument will be loaded through the blockstate system. */ - public static IModel getModel(ResourceLocation location) + public static IModel getModel(ResourceLocation location) throws Exception { IModel model; if(cache.containsKey(location)) return cache.get(location); @@ -77,7 +77,7 @@ public class ModelLoaderRegistry { if(location.getClass() == loading.getClass() && location.equals(loading)) { - throw new IllegalStateException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]"); + throw new LoaderException("circular model dependencies, stack: [" + Joiner.on(", ").join(loadingModels) + "]"); } } loadingModels.addLast(location); @@ -93,15 +93,14 @@ public class ModelLoaderRegistry { if(accepted != null) { - FMLLog.severe("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location); - throw new IllegalStateException("2 loaders want to load the same model"); + throw new LoaderException(String.format("2 loaders (%s and %s) want to load the same model %s", accepted, loader, location)); } accepted = loader; } } catch(Exception e) { - FMLLog.log(Level.ERROR, e, "Exception checking if model %s can be loaded with loader %s, skipping", location, loader); + throw new LoaderException(String.format("Exception checking if model %s can be loaded with loader %s, skipping", location, loader), e); } } @@ -120,31 +119,25 @@ public class ModelLoaderRegistry if(accepted == null) { - FMLLog.severe("no suitable loader found for the model %s, skipping", location); - model = getMissingModel(); + throw new LoaderException("no suitable loader found for the model " + location + ", skipping"); } - else + try { - try - { - model = accepted.loadModel(actual); - } - catch(Exception e) - { - FMLLog.log(Level.ERROR, e, "Exception loading model %s with loader %s, skipping", location, accepted); - model = getMissingModel(); - } - if(model == getMissingModel()) - { - FMLLog.log(Level.ERROR, "Loader %s returned missing model while loading model %s", accepted, location); - } - if(model == null) - { - FMLLog.log(Level.ERROR, "Loader %s returned null while loading model %s", accepted, location); - model = getMissingModel(); - } - textures.addAll(model.getTextures()); + model = accepted.loadModel(actual); } + catch(Exception e) + { + throw new LoaderException(String.format("Exception loading model %s with loader %s, skipping", location, accepted), e); + } + if(model == getMissingModel()) + { + throw new LoaderException(String.format("Loader %s returned missing model while loading model %s", accepted, location)); + } + if(model == null) + { + throw new LoaderException(String.format("Loader %s returned null while loading model %s", accepted, location)); + } + textures.addAll(model.getTextures()); } finally { @@ -157,11 +150,42 @@ public class ModelLoaderRegistry cache.put(location, model); for (ResourceLocation dep : model.getDependencies()) { - getModel(dep); + getModelOrMissing(dep); } return model; } + /** + * Use this if you don't care about the exception and want some model anyway. + */ + public static IModel getModelOrMissing(ResourceLocation location) + { + try + { + return getModel(location); + } + catch(Exception e) + { + return getMissingModel(); + } + } + + /** + * Use this if you want the model, but need to log the error. + */ + public static IModel getModelOrLogError(ResourceLocation location, String error) + { + try + { + return getModel(location); + } + catch(Exception e) + { + FMLLog.getLogger().error(error, e); + return getMissingModel(); + } + } + public static IModel getMissingModel() { return ModelLoader.VanillaLoader.instance.getLoader().getMissingModel(); @@ -180,4 +204,19 @@ public class ModelLoaderRegistry { return textures; } + + public static class LoaderException extends Exception + { + public LoaderException(String message) + { + super(message); + } + + public LoaderException(String message, Throwable cause) + { + super(message, cause); + } + + private static final long serialVersionUID = 1L; + } } diff --git a/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java b/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java index b8ae6d4314..b110763cb9 100644 --- a/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java +++ b/src/main/java/net/minecraftforge/client/model/MultiLayerModel.java @@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -public class MultiLayerModel implements IModelCustomData +public final class MultiLayerModel implements IModelCustomData { public static final MultiLayerModel instance = new MultiLayerModel(ImmutableMap., ModelResourceLocation>of()); @@ -58,7 +58,7 @@ public class MultiLayerModel implements IModelCustomData ImmutableMap.Builder, IBakedModel> builder = ImmutableMap.builder(); for(Optional key : models.keySet()) { - IModel model = ModelLoaderRegistry.getModel(models.get(key)); + IModel model = ModelLoaderRegistry.getModelOrLogError(models.get(key), "Couldn't load MultiLayerModel dependency: " + models.get(key)); builder.put(key, model.bake(new ModelStateComposition(state, model.getDefaultState()), format, bakedTextureGetter)); } return builder.build(); @@ -115,7 +115,7 @@ public class MultiLayerModel implements IModelCustomData return new ModelResourceLocation("builtin/missing", "missing"); } - public static class MultiLayerBakedModel implements IPerspectiveAwareModel + private static final class MultiLayerBakedModel implements IPerspectiveAwareModel { private final ImmutableMap, IBakedModel> models; private final ImmutableMap cameraTransforms;; diff --git a/src/main/java/net/minecraftforge/client/model/MultiModel.java b/src/main/java/net/minecraftforge/client/model/MultiModel.java index c35004f7a6..a6f3b6c8c8 100644 --- a/src/main/java/net/minecraftforge/client/model/MultiModel.java +++ b/src/main/java/net/minecraftforge/client/model/MultiModel.java @@ -32,21 +32,16 @@ import com.google.common.collect.Sets; // TODO: Switch to vanilla class, or to something similar @Deprecated -public class MultiModel implements IModel +public final class MultiModel implements IModel { - public static class Baked implements IPerspectiveAwareModel + private static final class Baked implements IPerspectiveAwareModel { - protected final IBakedModel base; - protected final ImmutableMap parts; + private final IBakedModel base; + private final ImmutableMap parts; - protected final IBakedModel internalBase; - protected ImmutableMap, ImmutableList> quads; - protected final ImmutableMap> transforms; - - public Baked(IBakedModel base, ImmutableMap parts) - { - this(null, false, base, parts); - } + private final IBakedModel internalBase; + private ImmutableMap, ImmutableList> quads; + private final ImmutableMap> transforms; public Baked(ResourceLocation location, boolean perspective, IBakedModel base, ImmutableMap parts) { @@ -148,16 +143,6 @@ public class MultiModel implements IModel return quads.get(Optional.fromNullable(side)); } - public IBakedModel getBaseModel() - { - return base; - } - - public Map getParts() - { - return parts; - } - @Override public Pair handlePerspective(TransformType cameraTransformType) { @@ -173,10 +158,10 @@ public class MultiModel implements IModel } } - protected final ResourceLocation location; - protected final IModel base; - protected final IModelState baseState; - protected final Map> parts; + private final ResourceLocation location; + private final IModel base; + private final IModelState baseState; + private final Map> parts; public MultiModel(ResourceLocation location, IModel base, IModelState baseState, ImmutableMap> parts) { @@ -186,16 +171,6 @@ public class MultiModel implements IModel this.parts = parts; } - public MultiModel(IModel base, IModelState baseState, ImmutableMap> parts) - { - this(null, base, baseState, parts); - } - - public MultiModel(IModel base, IModelState baseState, Map> parts) - { - this(null, base, baseState, ImmutableMap.copyOf(parts)); - } - public MultiModel(ResourceLocation location, IModel base, IModelState baseState, Map> parts) { this(location, base, baseState, ImmutableMap.copyOf(parts)); @@ -254,22 +229,6 @@ public class MultiModel implements IModel return new Baked(location, true, bakedBase, mapBuilder.build()); } - /** - * @return The base model of this MultiModel. May be null. - */ - public IModel getBaseModel() - { - return base; - } - - /** - * @return A map of the submodel name to its IModel and IModelState. - */ - public Map> getParts() - { - return parts; - } - @Override public IModelState getDefaultState() { diff --git a/src/main/java/net/minecraftforge/client/model/MultiModelState.java b/src/main/java/net/minecraftforge/client/model/MultiModelState.java index 15e9dff77a..6b06fcc76c 100644 --- a/src/main/java/net/minecraftforge/client/model/MultiModelState.java +++ b/src/main/java/net/minecraftforge/client/model/MultiModelState.java @@ -7,7 +7,7 @@ import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -public class MultiModelState implements IModelState +public final class MultiModelState implements IModelState { private final ImmutableMap states; diff --git a/src/main/java/net/minecraftforge/client/model/SimpleModelState.java b/src/main/java/net/minecraftforge/client/model/SimpleModelState.java index a4da1cc287..5c2e384399 100644 --- a/src/main/java/net/minecraftforge/client/model/SimpleModelState.java +++ b/src/main/java/net/minecraftforge/client/model/SimpleModelState.java @@ -6,7 +6,7 @@ import com.google.common.collect.ImmutableMap; /* * Simple implementation of IModelState via a map and a default value. */ -public class SimpleModelState implements IModelState +public final class SimpleModelState implements IModelState { private final ImmutableMap map; private final Optional def; diff --git a/src/main/java/net/minecraftforge/client/model/TRSRTransformation.java b/src/main/java/net/minecraftforge/client/model/TRSRTransformation.java index 06d05167b2..368c2adc58 100644 --- a/src/main/java/net/minecraftforge/client/model/TRSRTransformation.java +++ b/src/main/java/net/minecraftforge/client/model/TRSRTransformation.java @@ -30,7 +30,7 @@ import com.google.common.base.Optional; * should be comparable to using Matrix4f directly. * Immutable. */ -public class TRSRTransformation implements IModelState, ITransformation +public final class TRSRTransformation implements IModelState, ITransformation { private final Matrix4f matrix; diff --git a/src/main/java/net/minecraftforge/client/model/animation/Clips.java b/src/main/java/net/minecraftforge/client/model/animation/Clips.java index 2b5d910c2f..5561e3d187 100644 --- a/src/main/java/net/minecraftforge/client/model/animation/Clips.java +++ b/src/main/java/net/minecraftforge/client/model/animation/Clips.java @@ -62,7 +62,7 @@ public final class Clips */ public static IClip getModelClipNode(ResourceLocation modelLocation, String clipName) { - IModel model = ModelLoaderRegistry.getModel(modelLocation); + IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation); if(model instanceof IAnimatedModel) { Optional clip = ((IAnimatedModel)model).getClip(clipName); diff --git a/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java b/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java index 0424343d61..7196cda27c 100644 --- a/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java +++ b/src/main/java/net/minecraftforge/client/model/b3d/B3DLoader.java @@ -25,15 +25,25 @@ import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResourceManager; import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.*; -import net.minecraftforge.client.model.animation.IClip; +import net.minecraft.util.math.MathHelper; +import net.minecraftforge.client.model.ICustomModelLoader; +import net.minecraftforge.client.model.IModel; +import net.minecraftforge.client.model.IModelCustomData; +import net.minecraftforge.client.model.IModelPart; +import net.minecraftforge.client.model.IModelSimpleProperties; +import net.minecraftforge.client.model.IModelState; +import net.minecraftforge.client.model.IPerspectiveAwareModel; +import net.minecraftforge.client.model.IRetexturableModel; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.client.model.ModelLoaderRegistry; +import net.minecraftforge.client.model.ModelStateComposition; +import net.minecraftforge.client.model.TRSRTransformation; import net.minecraftforge.client.model.animation.IAnimatedModel; +import net.minecraftforge.client.model.animation.IClip; import net.minecraftforge.client.model.animation.IJoint; import net.minecraftforge.client.model.b3d.B3DModel.Animation; import net.minecraftforge.client.model.b3d.B3DModel.Face; -import net.minecraftforge.client.model.b3d.B3DModel.IKind; import net.minecraftforge.client.model.b3d.B3DModel.Key; import net.minecraftforge.client.model.b3d.B3DModel.Mesh; import net.minecraftforge.client.model.b3d.B3DModel.Node; @@ -48,7 +58,6 @@ import net.minecraftforge.fml.common.FMLLog; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; -import org.apache.logging.log4j.Level; import com.google.common.base.Function; import com.google.common.base.Objects; @@ -69,7 +78,7 @@ import com.google.gson.JsonParser; * To enable for your mod call instance.addDomain(modid). * If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry. */ -public class B3DLoader implements ICustomModelLoader +public final class B3DLoader implements ICustomModelLoader { public static final B3DLoader instance = new B3DLoader(); @@ -95,7 +104,7 @@ public class B3DLoader implements ICustomModelLoader } @SuppressWarnings("unchecked") - public IModel loadModel(ResourceLocation modelLocation) + public IModel loadModel(ResourceLocation modelLocation) throws Exception { ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath()); if(!cache.containsKey(file)) @@ -121,12 +130,12 @@ public class B3DLoader implements ICustomModelLoader } catch(IOException e) { - FMLLog.log(Level.ERROR, e, "Exception loading model %s with B3D loader, skipping", modelLocation); cache.put(file, null); + throw e; } } B3DModel model = cache.get(file); - if(model == null) return ModelLoaderRegistry.getMissingModel(); + if(model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file); if(!(model.getRoot().getKind() instanceof Mesh)) { return new ModelWrapper(modelLocation, model, ImmutableSet.of(), true, true, 1); @@ -134,7 +143,7 @@ public class B3DLoader implements ICustomModelLoader return new ModelWrapper(modelLocation, model, ImmutableSet.of(((Node)model.getRoot()).getName()), true, true, 1); } - public static class B3DState implements IModelState + public static final class B3DState implements IModelState { private final Animation animation; private final int frame; @@ -304,7 +313,7 @@ public class B3DLoader implements ICustomModelLoader } } - public static class NodeJoint implements IJoint + static final class NodeJoint implements IJoint { private final Node node; @@ -380,27 +389,7 @@ public class B3DLoader implements ICustomModelLoader } } - public static class PartWrapper> implements IModelPart - { - private final Node node; - - public static > PartWrapper create(Node node) - { - return new PartWrapper(node); - } - - public PartWrapper(Node node) - { - this.node = node; - } - - public Node getNode() - { - return node; - } - } - - public static class ModelWrapper implements IRetexturableModel, IModelCustomData, IModelSimpleProperties, IAnimatedModel + private static final class ModelWrapper implements IRetexturableModel, IModelCustomData, IModelSimpleProperties, IAnimatedModel { private final ResourceLocation modelLocation; private final B3DModel model; @@ -591,7 +580,7 @@ public class B3DLoader implements ICustomModelLoader } } - private static class BakedWrapper implements IPerspectiveAwareModel + private static final class BakedWrapper implements IPerspectiveAwareModel { private final Node node; private final IModelState state; @@ -697,7 +686,7 @@ public class B3DLoader implements ICustomModelLoader return quads; } - protected void generateQuads(ImmutableList.Builder builder, Node node, final IModelState state) + private void generateQuads(ImmutableList.Builder builder, Node node, final IModelState state) { for(Node child : node.getNodes().values()) { @@ -828,7 +817,6 @@ public class B3DLoader implements ICustomModelLoader return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, state, cameraTransformType); } - @Override public ItemOverrideList getOverrides() { // TODO handle items diff --git a/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java b/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java index 935f3ecbae..a84b680f6b 100644 --- a/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java +++ b/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java @@ -1,7 +1,6 @@ package net.minecraftforge.client.model.obj; import java.io.FileNotFoundException; -import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -22,7 +21,7 @@ import org.apache.logging.log4j.Level; * To enable your mod call instance.addDomain(modid). * If you need more control over accepted resources - extend the class, and register a new instance with ModelLoaderRegistry. */ -public class OBJLoader implements ICustomModelLoader { +public final class OBJLoader implements ICustomModelLoader { public static final OBJLoader instance = new OBJLoader(); private IResourceManager manager; private final Set enabledDomains = new HashSet(); @@ -45,44 +44,37 @@ public class OBJLoader implements ICustomModelLoader { return enabledDomains.contains(modelLocation.getResourceDomain()) && modelLocation.getResourcePath().endsWith(".obj"); } - public IModel loadModel(ResourceLocation modelLocation) + public IModel loadModel(ResourceLocation modelLocation) throws Exception { ResourceLocation file = new ResourceLocation(modelLocation.getResourceDomain(), modelLocation.getResourcePath()); if (!cache.containsKey(file)) { + IResource resource = null; try { - IResource resource = null; - try - { - resource = manager.getResource(file); - } - catch (FileNotFoundException e) - { - if (modelLocation.getResourcePath().startsWith("models/block/")) - resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length()))); - else if (modelLocation.getResourcePath().startsWith("models/item/")) - resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length()))); - else throw e; - } - OBJModel.Parser parser = new OBJModel.Parser(resource, manager); - OBJModel model = null; - try - { - model = parser.parse(); - } - finally - { - cache.put(modelLocation, model); - } + resource = manager.getResource(file); } - catch (IOException e) + catch (FileNotFoundException e) { - cache.put(modelLocation, null); + if (modelLocation.getResourcePath().startsWith("models/block/")) + resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/item/" + file.getResourcePath().substring("models/block/".length()))); + else if (modelLocation.getResourcePath().startsWith("models/item/")) + resource = manager.getResource(new ResourceLocation(file.getResourceDomain(), "models/block/" + file.getResourcePath().substring("models/item/".length()))); + else throw e; + } + OBJModel.Parser parser = new OBJModel.Parser(resource, manager); + OBJModel model = null; + try + { + model = parser.parse(); + } + finally + { + cache.put(modelLocation, model); } } OBJModel model = cache.get(file); - if (model == null) return ModelLoaderRegistry.getMissingModel(); + if (model == null) throw new ModelLoaderRegistry.LoaderException("Error loading model previously: " + file); return model; } } diff --git a/src/test/java/net/minecraftforge/debug/DynBucketTest.java b/src/test/java/net/minecraftforge/debug/DynBucketTest.java index a303f048ac..6e0b4e6eac 100644 --- a/src/test/java/net/minecraftforge/debug/DynBucketTest.java +++ b/src/test/java/net/minecraftforge/debug/DynBucketTest.java @@ -37,9 +37,10 @@ import net.minecraftforge.fml.common.registry.GameRegistry; import java.util.List; -@Mod(modid = "DynBucketTest", version = "0.1", dependencies = "after:" + ModelFluidDebug.MODID) +@Mod(modid = DynBucketTest.MODID, version = "0.1", dependencies = "after:" + ModelFluidDebug.MODID) public class DynBucketTest { + public static final String MODID = "DynBucketTest"; public static final Item dynBucket = new DynBucket(); public static final Item dynBottle = new DynBottle(); @@ -79,6 +80,7 @@ public class DynBucketTest } }); ModelBakery.registerItemVariants(dynBottle, bottle); + ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(GameRegistry.findBlock(MODID, "simpletank")), 0, new ModelResourceLocation(new ResourceLocation(MODID, "simpletank"), "normal")); } } diff --git a/src/test/java/net/minecraftforge/debug/ItemTileDebug.java b/src/test/java/net/minecraftforge/debug/ItemTileDebug.java index 644155865b..309a4ea6c5 100644 --- a/src/test/java/net/minecraftforge/debug/ItemTileDebug.java +++ b/src/test/java/net/minecraftforge/debug/ItemTileDebug.java @@ -55,7 +55,7 @@ public class ItemTileDebug public static class ClientProxy extends CommonProxy { - private static ModelResourceLocation itemLocation = new ModelResourceLocation(blockName, "inventory"); + private static ModelResourceLocation itemLocation = new ModelResourceLocation(blockName, "normal"); @SuppressWarnings("deprecation") @Override diff --git a/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java b/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java index a554c07b92..3156a226fb 100644 --- a/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java +++ b/src/test/java/net/minecraftforge/debug/ModelAnimationDebug.java @@ -203,8 +203,8 @@ public class ModelAnimationDebug { model = ((IModelCustomData)model).process(ImmutableMap.of("mesh", "[\"Base\", \"Lid\"]")); }*/ - IModel base = ModelLoaderRegistry.getModel(new ResourceLocation(ModelAnimationDebug.MODID, "block/engine")); - IModel ring = ModelLoaderRegistry.getModel(new ResourceLocation(ModelAnimationDebug.MODID, "block/engine_ring")); + IModel base = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ModelAnimationDebug.MODID, "block/engine")); + IModel ring = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ModelAnimationDebug.MODID, "block/engine_ring")); ImmutableMap textures = ImmutableMap.of( "base", "blocks/stone", "front", "blocks/log_oak", diff --git a/src/test/java/net/minecraftforge/debug/ModelBakeEventDebug.java b/src/test/java/net/minecraftforge/debug/ModelBakeEventDebug.java index cb829bec5c..c15b75b289 100644 --- a/src/test/java/net/minecraftforge/debug/ModelBakeEventDebug.java +++ b/src/test/java/net/minecraftforge/debug/ModelBakeEventDebug.java @@ -251,21 +251,24 @@ public class ModelBakeEventDebug @Override public List getQuads(IBlockState state, EnumFacing side, long rand) { - if(side != null || !(state instanceof IExtendedBlockState)) return ImmutableList.of(); + if(side != null) return ImmutableList.of(); IExtendedBlockState exState = (IExtendedBlockState)state; int len = cubeSize * 5 + 1; List ret = new ArrayList(); for(EnumFacing f : EnumFacing.values()) { ret.add(createSidedBakedQuad(0, 1, 0, 1, 1, base, f)); - for(int i = 0; i < cubeSize; i++) + if(state != null) { - for(int j = 0; j < cubeSize; j++) + for(int i = 0; i < cubeSize; i++) { - Integer value = exState.getValue(properties[f.ordinal()]); - if(value != null && (value & (1 << (i * cubeSize + j))) != 0) + for(int j = 0; j < cubeSize; j++) { - ret.add(createSidedBakedQuad((float)(1 + i * 5) / len, (float)(5 + i * 5) / len, (float)(1 + j * 5) / len, (float)(5 + j * 5) / len, 1.0001f, overlay, f)); + Integer value = exState.getValue(properties[f.ordinal()]); + if(value != null && (value & (1 << (i * cubeSize + j))) != 0) + { + ret.add(createSidedBakedQuad((float)(1 + i * 5) / len, (float)(5 + i * 5) / len, (float)(1 + j * 5) / len, (float)(5 + j * 5) / len, 1.0001f, overlay, f)); + } } } } diff --git a/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java b/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java index 8d41475488..68488aa299 100644 --- a/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java +++ b/src/test/java/net/minecraftforge/debug/ModelLoaderRegistryDebug.java @@ -255,7 +255,7 @@ public class ModelLoaderRegistryDebug { if (world.getTileEntity(pos) == null) world.setTileEntity(pos, new OBJTesseractTileEntity()); OBJTesseractTileEntity tileEntity = (OBJTesseractTileEntity) world.getTileEntity(pos); - IModel model = ModelLoaderRegistry.getModel(new ResourceLocation(MODID.toLowerCase() + ":" + "block/tesseract.obj")); + IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(MODID.toLowerCase() + ":" + "block/tesseract.obj")); if (player.isSneaking()) { diff --git a/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java b/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java index 88ea98dc39..6b5d702f42 100644 --- a/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java +++ b/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java @@ -1,5 +1,6 @@ package net.minecraftforge.test; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer.EnumStatus; @@ -14,6 +15,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; @@ -24,6 +26,7 @@ import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import net.minecraftforge.event.entity.player.SleepingLocationCheckEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -37,12 +40,35 @@ public class NoBedSleepingTest @CapabilityInject(IExtraSleeping.class) private static final Capability SLEEP_CAP = null; + @SidedProxy + public static CommonProxy proxy = null; + + public static abstract class CommonProxy + { + public void preInit(FMLPreInitializationEvent event) + { + GameRegistry.registerItem(ItemSleepingPill.instance, ItemSleepingPill.name); + CapabilityManager.INSTANCE.register(IExtraSleeping.class, new Storage(), DefaultImpl.class); + MinecraftForge.EVENT_BUS.register(new EventHandler()); + } + } + + public static final class ServerProxy extends CommonProxy {} + + public static final class ClientProxy extends CommonProxy + { + @Override + public void preInit(FMLPreInitializationEvent event) + { + super.preInit(event); + ModelLoader.setCustomModelResourceLocation(ItemSleepingPill.instance, 0, new ModelResourceLocation(new ResourceLocation(MODID, ItemSleepingPill.name), "inventory")); + } + } + @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { - GameRegistry.registerItem(ItemSleepingPill.instance, ItemSleepingPill.name); - CapabilityManager.INSTANCE.register(IExtraSleeping.class, new Storage(), DefaultImpl.class); - MinecraftForge.EVENT_BUS.register(new EventHandler()); + proxy.preInit(event); } public static class EventHandler diff --git a/src/test/resources/assets/dynbuckettest/blockstates/simpletank.json b/src/test/resources/assets/dynbuckettest/blockstates/simpletank.json new file mode 100644 index 0000000000..a407ada13e --- /dev/null +++ b/src/test/resources/assets/dynbuckettest/blockstates/simpletank.json @@ -0,0 +1,10 @@ +{ + "forge_marker": 1, + "defaults": { + "transform": "forge:default-block", + "model": "builtin/generated" + }, + "variants": { + "normal": [{}] + } +} \ No newline at end of file diff --git a/src/test/resources/assets/forgedebugitemtile/blockstates/custom_model_block.json b/src/test/resources/assets/forgedebugitemtile/blockstates/custom_model_block.json new file mode 100644 index 0000000000..67e2f34328 --- /dev/null +++ b/src/test/resources/assets/forgedebugitemtile/blockstates/custom_model_block.json @@ -0,0 +1,10 @@ +{ + "forge_marker": 1, + "defaults": { + "transform": "forge:default-block", + "model": "builtin/generated" + }, + "variants": { + "normal": [{}] + } +} diff --git a/src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json b/src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json deleted file mode 100644 index 43a272a605..0000000000 --- a/src/test/resources/assets/forgedebugitemtile/models/item/custom_model_block.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "builtin/entity" -} diff --git a/src/test/resources/assets/forgedebugnobedsleeping/models/item/sleeping_pill.json b/src/test/resources/assets/forgedebugnobedsleeping/models/item/sleeping_pill.json new file mode 100644 index 0000000000..15928e0b20 --- /dev/null +++ b/src/test/resources/assets/forgedebugnobedsleeping/models/item/sleeping_pill.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "items/beef_cooked" + } +} \ No newline at end of file