| 1 | package net.minecraft.client.resources;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import com.google.gson.JsonObject;
|
| 5 | import com.google.gson.JsonParser;
|
| 6 | import java.io.BufferedReader;
|
| 7 | import java.io.InputStream;
|
| 8 | import java.io.InputStreamReader;
|
| 9 | import java.io.Reader;
|
| 10 | import java.util.Map;
|
| 11 | import net.minecraft.client.resources.data.IMetadataSection;
|
| 12 | import net.minecraft.client.resources.data.IMetadataSerializer;
|
| 13 | import net.minecraft.util.ResourceLocation;
|
| 14 | import org.apache.commons.io.IOUtils;
|
| 15 |
|
| 16 | public class SimpleResource implements IResource
|
| 17 | {
|
| 18 | private final Map<String, IMetadataSection> mapMetadataSections = Maps.<String, IMetadataSection>newHashMap();
|
| 19 | private final String resourcePackName;
|
| 20 | private final ResourceLocation srResourceLocation;
|
| 21 | private final InputStream resourceInputStream;
|
| 22 | private final InputStream mcmetaInputStream;
|
| 23 | private final IMetadataSerializer srMetadataSerializer;
|
| 24 | private boolean mcmetaJsonChecked;
|
| 25 | private JsonObject mcmetaJson;
|
| 26 |
|
| 27 | public SimpleResource(String resourcePackNameIn, ResourceLocation srResourceLocationIn, InputStream resourceInputStreamIn, InputStream mcmetaInputStreamIn, IMetadataSerializer srMetadataSerializerIn)
|
| 28 | {
|
| 29 | this.resourcePackName = resourcePackNameIn;
|
| 30 | this.srResourceLocation = srResourceLocationIn;
|
| 31 | this.resourceInputStream = resourceInputStreamIn;
|
| 32 | this.mcmetaInputStream = mcmetaInputStreamIn;
|
| 33 | this.srMetadataSerializer = srMetadataSerializerIn;
|
| 34 | }
|
| 35 |
|
| 36 | public ResourceLocation getResourceLocation()
|
| 37 | {
|
| 38 | return this.srResourceLocation;
|
| 39 | }
|
| 40 |
|
| 41 | public InputStream getInputStream()
|
| 42 | {
|
| 43 | return this.resourceInputStream;
|
| 44 | }
|
| 45 |
|
| 46 | public boolean hasMetadata()
|
| 47 | {
|
| 48 | return this.mcmetaInputStream != null;
|
| 49 | }
|
| 50 |
|
| 51 | public <T extends IMetadataSection> T getMetadata(String p_110526_1_)
|
| 52 | {
|
| 53 | if (!this.hasMetadata())
|
| 54 | {
|
| 55 | return (T)null;
|
| 56 | }
|
| 57 | else
|
| 58 | {
|
| 59 | if (this.mcmetaJson == null && !this.mcmetaJsonChecked)
|
| 60 | {
|
| 61 | this.mcmetaJsonChecked = true;
|
| 62 | BufferedReader bufferedreader = null;
|
| 63 |
|
| 64 | try
|
| 65 | {
|
| 66 | bufferedreader = new BufferedReader(new InputStreamReader(this.mcmetaInputStream));
|
| 67 | this.mcmetaJson = (new JsonParser()).parse((Reader)bufferedreader).getAsJsonObject();
|
| 68 | }
|
| 69 | finally
|
| 70 | {
|
| 71 | IOUtils.closeQuietly((Reader)bufferedreader);
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | T t = (T)this.mapMetadataSections.get(p_110526_1_);
|
| 76 |
|
| 77 | if (t == null)
|
| 78 | {
|
| 79 | t = this.srMetadataSerializer.parseMetadataSection(p_110526_1_, this.mcmetaJson);
|
| 80 | }
|
| 81 |
|
| 82 | return t;
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | public String getResourcePackName()
|
| 87 | {
|
| 88 | return this.resourcePackName;
|
| 89 | }
|
| 90 |
|
| 91 | public boolean equals(Object p_equals_1_)
|
| 92 | {
|
| 93 | if (this == p_equals_1_)
|
| 94 | {
|
| 95 | return true;
|
| 96 | }
|
| 97 | else if (!(p_equals_1_ instanceof SimpleResource))
|
| 98 | {
|
| 99 | return false;
|
| 100 | }
|
| 101 | else
|
| 102 | {
|
| 103 | SimpleResource simpleresource = (SimpleResource)p_equals_1_;
|
| 104 |
|
| 105 | if (this.srResourceLocation != null)
|
| 106 | {
|
| 107 | if (!this.srResourceLocation.equals(simpleresource.srResourceLocation))
|
| 108 | {
|
| 109 | return false;
|
| 110 | }
|
| 111 | }
|
| 112 | else if (simpleresource.srResourceLocation != null)
|
| 113 | {
|
| 114 | return false;
|
| 115 | }
|
| 116 |
|
| 117 | if (this.resourcePackName != null)
|
| 118 | {
|
| 119 | if (!this.resourcePackName.equals(simpleresource.resourcePackName))
|
| 120 | {
|
| 121 | return false;
|
| 122 | }
|
| 123 | }
|
| 124 | else if (simpleresource.resourcePackName != null)
|
| 125 | {
|
| 126 | return false;
|
| 127 | }
|
| 128 |
|
| 129 | return true;
|
| 130 | }
|
| 131 | }
|
| 132 |
|
| 133 | public int hashCode()
|
| 134 | {
|
| 135 | int i = this.resourcePackName != null ? this.resourcePackName.hashCode() : 0;
|
| 136 | i = 31 * i + (this.srResourceLocation != null ? this.srResourceLocation.hashCode() : 0);
|
| 137 | return i;
|
| 138 | }
|
| 139 | }
|
| 140 |
|