diff --git a/src/main/java/forestry/api/arboriculture/WoodBlockKind.java b/src/main/java/forestry/api/arboriculture/WoodBlockKind.java index 402a3857f..e1994031b 100755 --- a/src/main/java/forestry/api/arboriculture/WoodBlockKind.java +++ b/src/main/java/forestry/api/arboriculture/WoodBlockKind.java @@ -57,6 +57,6 @@ public enum WoodBlockKind { break; } textures.putAll(customTextures); - return model.retexture(new ImmutableMap.Builder().putAll(textures).build()); + return model.retexture(ImmutableMap.copyOf(textures)); } } diff --git a/src/main/java/forestry/arboriculture/models/WoodTextureManager.java b/src/main/java/forestry/arboriculture/models/WoodTextureManager.java index 102c15463..319e56bd2 100644 --- a/src/main/java/forestry/arboriculture/models/WoodTextureManager.java +++ b/src/main/java/forestry/arboriculture/models/WoodTextureManager.java @@ -36,6 +36,7 @@ import forestry.api.arboriculture.IWoodType; import forestry.api.arboriculture.WoodBlockKind; import forestry.arboriculture.models.WoodTexture.SimpleTexture; import forestry.arboriculture.models.WoodTexture.TextureMap; +import forestry.core.utils.Log; @SideOnly(Side.CLIENT) public class WoodTextureManager { @@ -44,14 +45,11 @@ public class WoodTextureManager { public static final String LOCATION = "/assets/forestry/textures/wood_textures.json"; public static void parseFile() { - try { - InputStream stream = WoodTextureManager.class.getResourceAsStream(LOCATION); - JsonReader reader = null; - try { - if(stream == null){ - return; - } - reader = new JsonReader(new BufferedReader(new InputStreamReader(stream))); + try (InputStream stream = WoodTextureManager.class.getResourceAsStream(LOCATION)) { + if (stream == null){ + return; + } + try (JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(stream)))){ JsonElement json = Streams.parse(reader); if (json.isJsonObject()) { JsonObject jsonObject = json.getAsJsonObject(); @@ -64,14 +62,10 @@ public class WoodTextureManager { } } } - } finally { - if (reader != null) { - reader.close(); - } } } catch (IOException e) { if (!(e instanceof FileNotFoundException)) { - e.printStackTrace(); + Log.error("Error finding wood textures.", e); } } } @@ -124,11 +118,13 @@ public class WoodTextureManager { return new SimpleTexture(locations.build()); } + @Nullable private static WoodTexture getKindTexture(WoodBlockKind blockKind){ String kindName = blockKind.getName(); return WOOD_TEXTURES.get(kindName); } + @Nullable private static WoodTexture getTexture(IWoodType woodType){ String woodName = woodType.getName(); woodName = woodName.toLowerCase(Locale.ENGLISH); diff --git a/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java b/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java index d85bbe59f..f19d9242a 100644 --- a/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java +++ b/src/main/java/forestry/arboriculture/proxy/ProxyArboricultureClient.java @@ -24,6 +24,7 @@ import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.block.model.multipart.Multipart; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.registry.IRegistry; import net.minecraft.world.ColorizerFoliage; @@ -148,28 +149,27 @@ public class ProxyArboricultureClient extends ProxyArboriculture { ImmutableMap textures, IWoodType woodType, WoodBlockKind woodKind, ItemStack itemStack, IWoodItemMeshDefinition woodDefinition) { if (woodKind != WoodBlockKind.DOOR) { - IModel basicItemModel = ModelLoaderRegistry - .getModelOrMissing(woodDefinition.getDefaultModelLocation(itemStack)); + ResourceLocation defaultModelLocation = woodDefinition.getDefaultModelLocation(itemStack); + IModel basicItemModel = ModelLoaderRegistry.getModelOrMissing(defaultModelLocation); ModelResourceLocation basicItemLocation = woodDefinition.getModelLocation(itemStack); - - registry.putObject(basicItemLocation, - new SimpleRetexturedModel(woodKind.retextureModel(basicItemModel, woodType, textures))); + IModel retextureModel = woodKind.retextureModel(basicItemModel, woodType, textures); + registry.putObject(basicItemLocation, new SimpleRetexturedModel(retextureModel)); } } private void retexturBlockModel(IRegistry registry, ImmutableMap textures, IWoodType woodType, WoodBlockKind woodKind, IBlockState blockState, IWoodStateMapper woodMapper) { - IModel basicModel = ModelLoaderRegistry - .getModelOrMissing(woodMapper.getDefaultModelResourceLocation(blockState)); + ModelResourceLocation defaultModelResourceLocation = woodMapper.getDefaultModelResourceLocation(blockState); + IModel basicModel = ModelLoaderRegistry.getModelOrMissing(defaultModelResourceLocation); if (basicModel instanceof MultipartModel) { MultipartModel multipartModel = (MultipartModel) basicModel; Multipart multipart = multipartModel.getMultipart(); multipart.setStateContainer(blockState.getBlock().getBlockState()); } ModelResourceLocation basicLocation = woodMapper.getModelLocation(blockState); - registry.putObject(basicLocation, - new SimpleRetexturedModel(woodKind.retextureModel(basicModel, woodType, textures))); + IModel retextureModel = woodKind.retextureModel(basicModel, woodType, textures); + registry.putObject(basicLocation, new SimpleRetexturedModel(retextureModel)); }