diff --git a/build.gradle b/build.gradle index 29ef225..76af709 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ dependencies { } teavm.js { - obfuscated = true + obfuscated = false sourceMap = true targetFileName = "../classes.js" optimization = org.teavm.gradle.api.OptimizationLevel.AGGRESSIVE diff --git a/javascript/v0.6.1.zip b/javascript/v0.6.1.zip deleted file mode 100644 index 6be87ac..0000000 Binary files a/javascript/v0.6.1.zip and /dev/null differ diff --git a/javascript/web.zip b/javascript/web.zip deleted file mode 100644 index 678c2cd..0000000 Binary files a/javascript/web.zip and /dev/null differ diff --git a/resources/resources/assets/minecraft/models/item/broken_elytra.json b/resources/resources/assets/minecraft/models/item/broken_elytra.json new file mode 100644 index 0000000..9b2d114 --- /dev/null +++ b/resources/resources/assets/minecraft/models/item/broken_elytra.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "items/broken_elytra" + }, + "display": { + "thirdperson": { + "rotation": [ -90, 0, 0 ], + "translation": [ 0, 1, -3 ], + "scale": [ 0.55, 0.55, 0.55 ] + }, + "firstperson": { + "rotation": [ 0, -135, 25 ], + "translation": [ 0, 4, 2 ], + "scale": [ 1.7, 1.7, 1.7 ] + } + } +} diff --git a/resources/resources/assets/minecraft/models/item/elytra.json b/resources/resources/assets/minecraft/models/item/elytra.json index 1045058..3a78598 100644 --- a/resources/resources/assets/minecraft/models/item/elytra.json +++ b/resources/resources/assets/minecraft/models/item/elytra.json @@ -14,5 +14,13 @@ "translation": [ 0, 4, 2 ], "scale": [ 1.7, 1.7, 1.7 ] } - } + }, + "overrides": [ + { + "predicate": { + "broken": 1 + }, + "model": "item/broken_elytra" + } + ] } diff --git a/resources/resources/assets/minecraft/textures/items/broken_elytra.png b/resources/resources/assets/minecraft/textures/items/broken_elytra.png new file mode 100644 index 0000000..dd92e7f Binary files /dev/null and b/resources/resources/assets/minecraft/textures/items/broken_elytra.png differ diff --git a/src/main/java/net/lax1dude/eaglercraft/v1_8/json/JSONTypeProvider.java b/src/main/java/net/lax1dude/eaglercraft/v1_8/json/JSONTypeProvider.java index 8549dff..7a1d10b 100644 --- a/src/main/java/net/lax1dude/eaglercraft/v1_8/json/JSONTypeProvider.java +++ b/src/main/java/net/lax1dude/eaglercraft/v1_8/json/JSONTypeProvider.java @@ -19,6 +19,7 @@ import net.minecraft.client.renderer.block.model.BlockFaceUV; import net.minecraft.client.renderer.block.model.BlockPart; import net.minecraft.client.renderer.block.model.BlockPartFace; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverride; import net.minecraft.client.renderer.block.model.ItemTransformVec3f; import net.minecraft.client.renderer.block.model.ModelBlock; import net.minecraft.client.renderer.block.model.ModelBlockDefinition; @@ -40,38 +41,45 @@ import net.minecraft.world.gen.ChunkProviderSettings; /** * Copyright (c) 2022 lax1dude. All Rights Reserved. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ public class JSONTypeProvider { - private static final Map,JSONTypeSerializer> serializers = new HashMap(); - private static final Map,JSONTypeDeserializer> deserializers = new HashMap(); - + private static final Map, JSONTypeSerializer> serializers = new HashMap(); + private static final Map, JSONTypeDeserializer> deserializers = new HashMap(); + private static final List parsers = new ArrayList(); public static J serialize(Object object) throws JSONException { - JSONTypeSerializer ser = (JSONTypeSerializer) serializers.get(object.getClass()); - if(ser == null) { - for(Entry,JSONTypeSerializer> etr : serializers.entrySet()) { - if(etr.getKey().isInstance(object)) { - ser = (JSONTypeSerializer)etr.getValue(); + JSONTypeSerializer ser = (JSONTypeSerializer) serializers.get(object.getClass()); + if (ser == null) { + for (Entry, JSONTypeSerializer> etr : serializers.entrySet()) { + if (etr.getKey().isInstance(object)) { + ser = (JSONTypeSerializer) etr.getValue(); break; } } } - if(ser != null) { + if (ser != null) { return ser.serializeToJson(object); - }else { + } else { throw new JSONException("Could not find a serializer for " + object.getClass().getSimpleName()); } } @@ -81,53 +89,54 @@ public class JSONTypeProvider { } public static O deserializeNoCast(Object object, Class clazz) throws JSONException { - JSONTypeDeserializer ser = (JSONTypeDeserializer) deserializers.get(clazz); - if(ser != null) { - return (O)ser.deserializeFromJson(object); - }else { + JSONTypeDeserializer ser = (JSONTypeDeserializer) deserializers.get(clazz); + if (ser != null) { + return (O) ser.deserializeFromJson(object); + } else { throw new JSONException("Could not find a deserializer for " + object.getClass().getSimpleName()); } } - - public static JSONTypeSerializer getSerializer(Class object) { - return (JSONTypeSerializer)serializers.get(object); + + public static JSONTypeSerializer getSerializer(Class object) { + return (JSONTypeSerializer) serializers.get(object); } - - public static JSONTypeDeserializer getDeserializer(Class object) { - return (JSONTypeDeserializer)deserializers.get(object); + + public static JSONTypeDeserializer getDeserializer(Class object) { + return (JSONTypeDeserializer) deserializers.get(object); } - + public static Object parse(Object object) { - for(int i = 0, l = parsers.size(); i < l; ++i) { + for (int i = 0, l = parsers.size(); i < l; ++i) { JSONDataParserImpl parser = parsers.get(i); - if(parser.accepts(object)) { + if (parser.accepts(object)) { return parser.parse(object); } } return object; } - + public static void registerType(Class clazz, Object obj) { boolean valid = false; - if(obj instanceof JSONTypeSerializer) { - serializers.put(clazz, (JSONTypeSerializer)obj); + if (obj instanceof JSONTypeSerializer) { + serializers.put(clazz, (JSONTypeSerializer) obj); valid = true; } - if(obj instanceof JSONTypeDeserializer) { - deserializers.put(clazz, (JSONTypeDeserializer)obj); + if (obj instanceof JSONTypeDeserializer) { + deserializers.put(clazz, (JSONTypeDeserializer) obj); valid = true; } - if(!valid) { - throw new IllegalArgumentException("Object " + obj.getClass().getSimpleName() + " is not a JsonSerializer or JsonDeserializer object"); + if (!valid) { + throw new IllegalArgumentException( + "Object " + obj.getClass().getSimpleName() + " is not a JsonSerializer or JsonDeserializer object"); } } - + public static void registerParser(JSONDataParserImpl obj) { parsers.add(obj); } - + static { - + registerType(IChatComponent.class, new IChatComponent.Serializer()); registerType(ChatStyle.class, new ChatStyle.Serializer()); registerType(ServerStatusResponse.class, new ServerStatusResponse.Serializer()); @@ -143,6 +152,8 @@ public class JSONTypeProvider { registerType(ItemCameraTransforms.class, new ItemCameraTransforms.Deserializer()); registerType(ModelBlockDefinition.class, new ModelBlockDefinition.Deserializer()); registerType(ModelBlockDefinition.Variant.class, new ModelBlockDefinition.Variant.Deserializer()); + registerType(ItemOverride.class, new ItemOverride.Deserializer()); + registerType(SoundList.class, new SoundListSerializer()); registerType(SoundMap.class, new SoundMapDeserializer()); registerType(TextureMetadataSection.class, new TextureMetadataSectionSerializer()); @@ -155,7 +166,7 @@ public class JSONTypeProvider { registerParser(new JSONDataParserString()); registerParser(new JSONDataParserReader()); registerParser(new JSONDataParserStream()); - + } } diff --git a/src/main/java/net/minecraft/client/renderer/block/model/ItemModelGenerator.java b/src/main/java/net/minecraft/client/renderer/block/model/ItemModelGenerator.java index 959eb05..7c50f94 100644 --- a/src/main/java/net/minecraft/client/renderer/block/model/ItemModelGenerator.java +++ b/src/main/java/net/minecraft/client/renderer/block/model/ItemModelGenerator.java @@ -68,7 +68,8 @@ public class ItemModelGenerator { } else { hashmap.put("particle", blockModel.isTexturePresent("particle") ? blockModel.resolveTextureName("particle") : (String) hashmap.get("layer0")); - return new ModelBlock(arraylist, hashmap, false, false, blockModel.func_181682_g()); + return new ModelBlock((ResourceLocation) null, arraylist, hashmap, false, false, + blockModel.func_181682_g(), blockModel.getOverrides()); } } diff --git a/src/main/java/net/minecraft/client/renderer/block/model/ItemOverride.java b/src/main/java/net/minecraft/client/renderer/block/model/ItemOverride.java new file mode 100644 index 0000000..14b4144 --- /dev/null +++ b/src/main/java/net/minecraft/client/renderer/block/model/ItemOverride.java @@ -0,0 +1,70 @@ +package net.minecraft.client.renderer.block.model; + +import com.google.common.collect.Maps; +import java.util.Map; +import java.util.Map.Entry; +import javax.annotation.Nullable; + +import org.json.JSONException; +import org.json.JSONObject; + +import net.lax1dude.eaglercraft.v1_8.json.JSONTypeDeserializer; +import net.lax1dude.eaglercraft.v1_8.json.JSONTypeProvider; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.IItemPropertyGetter; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +public class ItemOverride { + private final ResourceLocation location; + private final Map mapResourceValues; + + public ItemOverride(ResourceLocation locationIn, Map p_i46571_2_) { + this.location = locationIn; + this.mapResourceValues = p_i46571_2_; + } + + public ResourceLocation getLocation() { + return this.location; + } + + boolean matchesItemStack(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase livingEntity) { + Item item = stack.getItem(); + + for (Entry entry : this.mapResourceValues.entrySet()) { + IItemPropertyGetter iitempropertygetter = item.getPropertyGetter((ResourceLocation) entry.getKey()); + + if (iitempropertygetter == null || iitempropertygetter.apply(stack, worldIn, + livingEntity) < ((Float) entry.getValue()).floatValue()) { + return false; + } + } + + return true; + } + + public static ItemOverride deserialize(String json) { + return (ItemOverride) JSONTypeProvider.deserialize(new JSONObject(json), ItemOverride.class); + } + + public static class Deserializer implements JSONTypeDeserializer { + public ItemOverride deserialize(JSONObject jsonObject) throws JSONException { + ResourceLocation resourcelocation = new ResourceLocation(jsonObject.getString("model")); + Map map = this.makeMapResourceValues(jsonObject); + return new ItemOverride(resourcelocation, map); + } + + protected Map makeMapResourceValues(JSONObject jsonObject) { + Map map = Maps.newLinkedHashMap(); + JSONObject jsonPredicate = jsonObject.getJSONObject("predicate"); + + for (String key : jsonPredicate.keySet()) { + map.put(new ResourceLocation(key), Float.valueOf(jsonPredicate.getFloat(key))); + } + + return map; + } + } +} diff --git a/src/main/java/net/minecraft/client/renderer/block/model/ItemOverrideList.java b/src/main/java/net/minecraft/client/renderer/block/model/ItemOverrideList.java new file mode 100644 index 0000000..3a71069 --- /dev/null +++ b/src/main/java/net/minecraft/client/renderer/block/model/ItemOverrideList.java @@ -0,0 +1,37 @@ +package net.minecraft.client.renderer.block.model; + +import com.google.common.collect.Lists; +import java.util.List; +import javax.annotation.Nullable; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +public class ItemOverrideList { + public static final ItemOverrideList NONE = new ItemOverrideList(); + private final List overrides = Lists.newArrayList(); + + private ItemOverrideList() { + } + + public ItemOverrideList(List overridesIn) { + for (int i = overridesIn.size() - 1; i >= 0; --i) { + this.overrides.add(overridesIn.get(i)); + } + } + + @Nullable + public ResourceLocation applyOverride(ItemStack stack, @Nullable World worldIn, + @Nullable EntityLivingBase entityIn) { + if (!this.overrides.isEmpty()) { + for (ItemOverride itemoverride : this.overrides) { + if (itemoverride.matchesItemStack(stack, worldIn, entityIn)) { + return itemoverride.getLocation(); + } + } + } + + return null; + } +} diff --git a/src/main/java/net/minecraft/client/renderer/block/model/ModelBlock.java b/src/main/java/net/minecraft/client/renderer/block/model/ModelBlock.java index c853e36..61d2c75 100644 --- a/src/main/java/net/minecraft/client/renderer/block/model/ModelBlock.java +++ b/src/main/java/net/minecraft/client/renderer/block/model/ModelBlock.java @@ -1,16 +1,21 @@ package net.minecraft.client.renderer.block.model; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; + import org.apache.commons.lang3.StringUtils; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import net.lax1dude.eaglercraft.v1_8.json.JSONTypeDeserializer; import net.lax1dude.eaglercraft.v1_8.json.JSONTypeProvider; @@ -54,6 +59,7 @@ public class ModelBlock { private final boolean gui3d; private final boolean ambientOcclusion; private ItemCameraTransforms cameraTransforms; + private final List overrides; public String name; protected final Map textures; protected ModelBlock parent; @@ -63,18 +69,23 @@ public class ModelBlock { return (ModelBlock) JSONTypeProvider.deserialize(new JSONObject(parString1), ModelBlock.class); } - protected ModelBlock(List parList, Map parMap, boolean parFlag, boolean parFlag2, - ItemCameraTransforms parItemCameraTransforms) { - this((ResourceLocation) null, parList, parMap, parFlag, parFlag2, parItemCameraTransforms); - } + // protected ModelBlock(List parList, Map parMap, + // boolean parFlag, boolean parFlag2, + // ItemCameraTransforms parItemCameraTransforms) { + // this((ResourceLocation) null, parList, parMap, parFlag, parFlag2, + // parItemCameraTransforms); + // } - protected ModelBlock(ResourceLocation parResourceLocation, Map parMap, boolean parFlag, - boolean parFlag2, ItemCameraTransforms parItemCameraTransforms) { - this(parResourceLocation, Collections.emptyList(), parMap, parFlag, parFlag2, parItemCameraTransforms); - } + // protected ModelBlock(ResourceLocation parResourceLocation, Map parMap, boolean parFlag, + // boolean parFlag2, ItemCameraTransforms parItemCameraTransforms) { + // this(parResourceLocation, Collections.emptyList(), parMap, parFlag, parFlag2, + // parItemCameraTransforms); + // } - private ModelBlock(ResourceLocation parentLocationIn, List elementsIn, Map texturesIn, - boolean ambientOcclusionIn, boolean gui3dIn, ItemCameraTransforms cameraTransformsIn) { + public ModelBlock(ResourceLocation parentLocationIn, List elementsIn, Map texturesIn, + boolean ambientOcclusionIn, boolean gui3dIn, ItemCameraTransforms cameraTransformsIn, + List overridesIn) { this.name = ""; this.elements = elementsIn; this.ambientOcclusion = ambientOcclusionIn; @@ -82,6 +93,7 @@ public class ModelBlock { this.textures = texturesIn; this.parentLocation = parentLocationIn; this.cameraTransforms = cameraTransformsIn; + this.overrides = overridesIn; } public List getElements() { @@ -111,6 +123,24 @@ public class ModelBlock { } + public Collection getOverrideLocations() { + Set set = Sets.newHashSet(); + + for (ItemOverride itemoverride : this.overrides) { + set.add(itemoverride.getLocation()); + } + + return set; + } + + protected List getOverrides() { + return this.overrides; + } + + public ItemOverrideList createOverrides() { + return this.overrides.isEmpty() ? ItemOverrideList.NONE : new ItemOverrideList(this.overrides); + } + public boolean isTexturePresent(String textureName) { return !"missingno".equals(this.resolveTextureName(textureName)); } @@ -221,12 +251,30 @@ public class ModelBlock { JSONObject jsonobject1 = jsonobject.getJSONObject("display"); itemcameratransforms = JSONTypeProvider.deserialize(jsonobject1, ItemCameraTransforms.class); } + List list1 = this.getItemOverrides(jsonobject); - return flag1 ? new ModelBlock(new ResourceLocation(s), map, flag2, true, itemcameratransforms) - : new ModelBlock(list, map, flag2, true, itemcameratransforms); + ResourceLocation resourcelocation = s.isEmpty() ? null : new ResourceLocation(s); + return new ModelBlock(resourcelocation, list, map, flag2, true, itemcameratransforms, list1); } } + protected List getItemOverrides(JSONObject object) { + List list = new ArrayList<>(); + + if (object.has("overrides")) { + JSONArray overrides = object.getJSONArray("overrides"); + for (int i = 0; i < overrides.length(); i++) { + JSONObject overrideObject = overrides.getJSONObject(i); + // Assuming there's a method in ItemOverride or elsewhere for deserializing a + // single JSONObject to an ItemOverride instance + ItemOverride itemOverride = ItemOverride.deserialize(overrideObject.toString()); + list.add(itemOverride); + } + } + + return list; + } + private Map getTextures(JSONObject parJsonObject) { HashMap hashmap = Maps.newHashMap(); if (parJsonObject.has("textures")) { diff --git a/src/main/java/net/minecraft/client/renderer/block/statemap/BlockStateMapper.java b/src/main/java/net/minecraft/client/renderer/block/statemap/BlockStateMapper.java index 807c62b..c4b6cc7 100644 --- a/src/main/java/net/minecraft/client/renderer/block/statemap/BlockStateMapper.java +++ b/src/main/java/net/minecraft/client/renderer/block/statemap/BlockStateMapper.java @@ -12,6 +12,7 @@ import com.google.common.collect.Sets; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.util.ResourceLocation; /** * + @@ -67,4 +68,32 @@ public class BlockStateMapper { return identityhashmap; } + + public Set getBlockstateLocations(Block blockIn) { + if (this.setBuiltInBlocks.contains(blockIn)) { + return Collections.emptySet(); + } else { + IStateMapper istatemapper = (IStateMapper) this.blockStateMap.get(blockIn); + + if (istatemapper == null) { + return Collections.singleton(Block.blockRegistry.getNameForObject(blockIn)); + } else { + Set set = Sets.newHashSet(); + + for (ModelResourceLocation modelresourcelocation : istatemapper.putStateModelLocations(blockIn) + .values()) { + set.add(new ResourceLocation(modelresourcelocation.getResourceDomain(), + modelresourcelocation.getResourcePath())); + } + + return set; + } + } + } + + public Map getVariants(Block blockIn) { + return this.setBuiltInBlocks.contains(blockIn) ? Collections.emptyMap() + : ((IStateMapper) Objects.firstNonNull(this.blockStateMap.get(blockIn), new DefaultStateMapper())) + .putStateModelLocations(blockIn); + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/client/renderer/entity/RenderItem.java b/src/main/java/net/minecraft/client/renderer/entity/RenderItem.java index bf43191..2fa30e1 100644 --- a/src/main/java/net/minecraft/client/renderer/entity/RenderItem.java +++ b/src/main/java/net/minecraft/client/renderer/entity/RenderItem.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; +import javax.annotation.Nullable; + import net.hoosiertransfer.EaglerCustomBlock; import net.hoosiertransfer.EaglerItems; import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager; @@ -72,6 +74,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3i; +import net.minecraft.world.World; /** * + @@ -343,15 +346,33 @@ public class RenderItem implements IResourceManagerReloadListener { public void func_181564_a(ItemStack parItemStack, ItemCameraTransforms.TransformType parTransformType) { if (parItemStack != null) { - IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(parItemStack); + IBakedModel ibakedmodel = this.getItemModelWithOverrides(parItemStack, (World) null, + (EntityLivingBase) null); this.renderItemModelTransform(parItemStack, ibakedmodel, parTransformType); } } + public IBakedModel getItemModelWithOverrides(ItemStack stack, @Nullable World worldIn, + @Nullable EntityLivingBase entitylivingbaseIn) { + IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + Item item = stack.getItem(); + + if (item != null && item.hasCustomProperties()) { + ResourceLocation resourcelocation = ibakedmodel.getOverrides().applyOverride(stack, worldIn, + entitylivingbaseIn); + return resourcelocation == null ? ibakedmodel + : this.itemModelMesher.getModelManager() + .getModel(new ModelResourceLocation(resourcelocation, "inventory")); + } else { + return ibakedmodel; + } + } + public void renderItemModelForEntity(ItemStack stack, EntityLivingBase entityToRenderFor, ItemCameraTransforms.TransformType cameraTransformType) { if (stack != null && entityToRenderFor != null) { - IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + IBakedModel ibakedmodel = this.getItemModelWithOverrides(stack, entityToRenderFor.worldObj, + entityToRenderFor); if (entityToRenderFor instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) entityToRenderFor; Item item = stack.getItem(); @@ -410,7 +431,11 @@ public class RenderItem implements IResourceManagerReloadListener { } public void renderItemIntoGUI(ItemStack stack, int x, int y) { - IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack); + this.renderItemModelIntoGUI(stack, x, y, + this.getItemModelWithOverrides(stack, (World) null, (EntityLivingBase) null)); + } + + public void renderItemModelIntoGUI(ItemStack stack, int x, int y, IBakedModel ibakedmodel) { GlStateManager.pushMatrix(); this.textureManager.bindTexture(TextureMap.locationBlocksTexture); this.textureManager.getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false, false); @@ -449,12 +474,18 @@ public class RenderItem implements IResourceManagerReloadListener { } - public void renderItemAndEffectIntoGUI(final ItemStack stack, int xPosition, int yPosition) { + public void renderItemAndEffectIntoGUI(ItemStack stack, int xPosition, int yPosition) { + this.renderItemAndEffectIntoGUI(Minecraft.getMinecraft().thePlayer, stack, xPosition, yPosition); + } + + public void renderItemAndEffectIntoGUI(@Nullable EntityLivingBase p_184391_1_, final ItemStack stack, int xPosition, + int yPosition) { if (stack != null && stack.getItem() != null) { this.zLevel += 50.0F; try { - this.renderItemIntoGUI(stack, xPosition, yPosition); + this.renderItemModelIntoGUI(stack, xPosition, yPosition, + this.getItemModelWithOverrides(stack, (World) null, p_184391_1_)); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Rendering item"); CrashReportCategory crashreportcategory = crashreport.makeCategory("Item being rendered"); diff --git a/src/main/java/net/minecraft/client/resources/model/BuiltInModel.java b/src/main/java/net/minecraft/client/resources/model/BuiltInModel.java index 541ea89..3e3b4a4 100644 --- a/src/main/java/net/minecraft/client/resources/model/BuiltInModel.java +++ b/src/main/java/net/minecraft/client/resources/model/BuiltInModel.java @@ -5,6 +5,7 @@ import java.util.List; import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.util.EnumFacing; /** @@ -38,9 +39,11 @@ import net.minecraft.util.EnumFacing; */ public class BuiltInModel implements IBakedModel { private ItemCameraTransforms cameraTransforms; + private final ItemOverrideList overrideList; - public BuiltInModel(ItemCameraTransforms parItemCameraTransforms) { + public BuiltInModel(ItemCameraTransforms parItemCameraTransforms, ItemOverrideList itemOverrides) { this.cameraTransforms = parItemCameraTransforms; + this.overrideList = itemOverrides; } public List getFaceQuads(EnumFacing var1) { @@ -70,4 +73,8 @@ public class BuiltInModel implements IBakedModel { public ItemCameraTransforms getItemCameraTransforms() { return this.cameraTransforms; } + + public ItemOverrideList getOverrides() { + return this.overrideList; + } } \ No newline at end of file diff --git a/src/main/java/net/minecraft/client/resources/model/IBakedModel.java b/src/main/java/net/minecraft/client/resources/model/IBakedModel.java index dee8d95..173243e 100644 --- a/src/main/java/net/minecraft/client/resources/model/IBakedModel.java +++ b/src/main/java/net/minecraft/client/resources/model/IBakedModel.java @@ -5,6 +5,7 @@ import java.util.List; import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.util.EnumFacing; /** @@ -50,4 +51,7 @@ public interface IBakedModel { EaglerTextureAtlasSprite getParticleTexture(); ItemCameraTransforms getItemCameraTransforms(); + + ItemOverrideList getOverrides(); + } \ No newline at end of file diff --git a/src/main/java/net/minecraft/client/resources/model/ModelBakery.java b/src/main/java/net/minecraft/client/resources/model/ModelBakery.java index d97e740..f53bfca 100644 --- a/src/main/java/net/minecraft/client/resources/model/ModelBakery.java +++ b/src/main/java/net/minecraft/client/resources/model/ModelBakery.java @@ -282,20 +282,34 @@ public class ModelBakery { for (Item item : Item.itemRegistry) { for (String s : this.getVariantNames(item)) { ResourceLocation resourcelocation = this.getItemLocation(s); - this.itemLocations.put(s, resourcelocation); - if (this.models.get(resourcelocation) == null) { - try { - ModelBlock modelblock = this.loadModel(resourcelocation); - this.models.put(resourcelocation, modelblock); - } catch (Exception exception) { - LOGGER.warn("Unable to load item model: \'" + resourcelocation + "\' for item: \'" - + Item.itemRegistry.getNameForObject(item) + "\'"); - LOGGER.warn(exception); + ResourceLocation resourcelocation1 = (ResourceLocation) Item.itemRegistry.getNameForObject(item); + this.loadItemModel(s, resourcelocation, resourcelocation1); + + if (item.hasCustomProperties()) { + ModelBlock modelblock = (ModelBlock) this.models.get(resourcelocation); + + if (modelblock != null) { + for (ResourceLocation resourcelocation2 : modelblock.getOverrideLocations()) { + this.loadItemModel(resourcelocation2.toString(), resourcelocation2, resourcelocation1); + } } } } } + } + private void loadItemModel(String p_188634_1_, ResourceLocation p_188634_2_, ResourceLocation p_188634_3_) { + this.itemLocations.put(p_188634_1_, p_188634_2_); + + if (this.models.get(p_188634_2_) == null) { + try { + ModelBlock modelblock = this.loadModel(p_188634_2_); + this.models.put(p_188634_2_, modelblock); + } catch (Exception exception) { + LOGGER.warn((String) ("Unable to load item model: \'" + p_188634_2_ + "\' for item: \'" + p_188634_3_ + + "\'"), (Throwable) exception); + } + } } private void registerVariantNames() { @@ -491,7 +505,8 @@ public class ModelBakery { ModelBlock modelblock1 = (ModelBlock) this.models.get(resourcelocation); if (modelblock1 != null && modelblock1.isResolved()) { if (this.isCustomRenderer(modelblock1)) { - this.bakedRegistry.putObject(modelresourcelocation1, new BuiltInModel(modelblock1.func_181682_g())); + this.bakedRegistry.putObject(modelresourcelocation1, + new BuiltInModel(modelblock1.func_181682_g(), modelblock1.createOverrides())); } else { this.bakedRegistry.putObject(modelresourcelocation1, this.bakeModel(modelblock1, ModelRotation.X0_Y0, false)); @@ -535,7 +550,8 @@ public class ModelBakery { private IBakedModel bakeModel(ModelBlock modelBlockIn, ModelRotation modelRotationIn, boolean uvLocked) { EaglerTextureAtlasSprite textureatlassprite = (EaglerTextureAtlasSprite) this.sprites .get(new ResourceLocation(modelBlockIn.resolveTextureName("particle"))); - SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn)) + SimpleBakedModel.Builder simplebakedmodel$builder = (new SimpleBakedModel.Builder(modelBlockIn, + modelBlockIn.createOverrides())) .setTexture(textureatlassprite); for (BlockPart blockpart : modelBlockIn.getElements()) { diff --git a/src/main/java/net/minecraft/client/resources/model/SimpleBakedModel.java b/src/main/java/net/minecraft/client/resources/model/SimpleBakedModel.java index 29c2414..4bdb008 100644 --- a/src/main/java/net/minecraft/client/resources/model/SimpleBakedModel.java +++ b/src/main/java/net/minecraft/client/resources/model/SimpleBakedModel.java @@ -8,6 +8,7 @@ import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BreakingFour; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.block.model.ModelBlock; import net.minecraft.util.EnumFacing; @@ -47,15 +48,18 @@ public class SimpleBakedModel implements IBakedModel { protected final boolean gui3d; protected final EaglerTextureAtlasSprite texture; protected final ItemCameraTransforms cameraTransforms; + protected final ItemOverrideList itemOverrideList; public SimpleBakedModel(List parList, List> parList2, boolean parFlag, boolean parFlag2, - EaglerTextureAtlasSprite parTextureAtlasSprite, ItemCameraTransforms parItemCameraTransforms) { + EaglerTextureAtlasSprite parTextureAtlasSprite, ItemCameraTransforms parItemCameraTransforms, + ItemOverrideList itemOverrideListIn) { this.generalQuads = parList; this.faceQuads = parList2; this.ambientOcclusion = parFlag; this.gui3d = parFlag2; this.texture = parTextureAtlasSprite; this.cameraTransforms = parItemCameraTransforms; + this.itemOverrideList = itemOverrideListIn; } public List getFaceQuads(EnumFacing enumfacing) { @@ -86,21 +90,27 @@ public class SimpleBakedModel implements IBakedModel { return this.cameraTransforms; } + public ItemOverrideList getOverrides() { + return this.itemOverrideList; + } + public static class Builder { private final List builderGeneralQuads; private final List> builderFaceQuads; + private final ItemOverrideList builderItemOverrideList; private final boolean builderAmbientOcclusion; private EaglerTextureAtlasSprite builderTexture; private boolean builderGui3d; private ItemCameraTransforms builderCameraTransforms; - public Builder(ModelBlock parModelBlock) { - this(parModelBlock.isAmbientOcclusion(), parModelBlock.isGui3d(), parModelBlock.func_181682_g()); + public Builder(ModelBlock parModelBlock, ItemOverrideList p_i46988_2_) { + this(parModelBlock.isAmbientOcclusion(), parModelBlock.isGui3d(), parModelBlock.func_181682_g(), + p_i46988_2_); } public Builder(IBakedModel parIBakedModel, EaglerTextureAtlasSprite parTextureAtlasSprite) { this(parIBakedModel.isAmbientOcclusion(), parIBakedModel.isGui3d(), - parIBakedModel.getItemCameraTransforms()); + parIBakedModel.getItemCameraTransforms(), parIBakedModel.getOverrides()); this.builderTexture = parIBakedModel.getParticleTexture(); EnumFacing[] facings = EnumFacing._VALUES; @@ -129,7 +139,8 @@ public class SimpleBakedModel implements IBakedModel { } - private Builder(boolean parFlag, boolean parFlag2, ItemCameraTransforms parItemCameraTransforms) { + private Builder(boolean parFlag, boolean parFlag2, ItemCameraTransforms parItemCameraTransforms, + ItemOverrideList p_i46990_4_) { this.builderGeneralQuads = Lists.newArrayList(); this.builderFaceQuads = Lists.newArrayListWithCapacity(6); @@ -137,6 +148,7 @@ public class SimpleBakedModel implements IBakedModel { this.builderFaceQuads.add(Lists.newArrayList()); } + this.builderItemOverrideList = p_i46990_4_; this.builderAmbientOcclusion = parFlag; this.builderGui3d = parFlag2; this.builderCameraTransforms = parItemCameraTransforms; @@ -163,7 +175,7 @@ public class SimpleBakedModel implements IBakedModel { } else { return new SimpleBakedModel(this.builderGeneralQuads, this.builderFaceQuads, this.builderAmbientOcclusion, this.builderGui3d, this.builderTexture, - this.builderCameraTransforms); + this.builderCameraTransforms, this.builderItemOverrideList); } } } diff --git a/src/main/java/net/minecraft/client/resources/model/WeightedBakedModel.java b/src/main/java/net/minecraft/client/resources/model/WeightedBakedModel.java index 6c6052e..e4f6ff8 100644 --- a/src/main/java/net/minecraft/client/resources/model/WeightedBakedModel.java +++ b/src/main/java/net/minecraft/client/resources/model/WeightedBakedModel.java @@ -9,6 +9,7 @@ import com.google.common.collect.Lists; import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.util.EnumFacing; import net.minecraft.util.WeightedRandom; @@ -85,6 +86,10 @@ public class WeightedBakedModel implements IBakedModel { Math.abs((int) parLong1 >> 16) % this.totalWeight)).model; } + public ItemOverrideList getOverrides() { + return this.baseModel.getOverrides(); + } + public static class Builder { private List listItems = Lists.newArrayList(); diff --git a/src/main/java/net/minecraft/item/IItemPropertyGetter.java b/src/main/java/net/minecraft/item/IItemPropertyGetter.java new file mode 100644 index 0000000..82620fc --- /dev/null +++ b/src/main/java/net/minecraft/item/IItemPropertyGetter.java @@ -0,0 +1,9 @@ +package net.minecraft.item; + +import javax.annotation.Nullable; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.world.World; + +public interface IItemPropertyGetter { + float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn); +} diff --git a/src/main/java/net/minecraft/item/Item.java b/src/main/java/net/minecraft/item/Item.java index 25066af..644f370 100644 --- a/src/main/java/net/minecraft/item/Item.java +++ b/src/main/java/net/minecraft/item/Item.java @@ -3,6 +3,8 @@ package net.minecraft.item; import java.util.List; import java.util.Map; +import javax.annotation.Nullable; + import net.hoosiertransfer.EaglerCustomBlock; import net.hoosiertransfer.EaglerItems; import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom; @@ -42,9 +44,11 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionHelper; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; +import net.minecraft.util.IRegistry; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.RegistryNamespaced; +import net.minecraft.util.RegistrySimple; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.util.Vec3; @@ -82,10 +86,38 @@ import net.minecraft.world.World; */ public class Item { public static final RegistryNamespaced itemRegistry = new RegistryNamespaced(); + private static final IItemPropertyGetter DAMAGED_GETTER = new IItemPropertyGetter() { + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { + return stack.isItemDamaged() ? 1.0F : 0.0F; + } + }; + private static final IItemPropertyGetter DAMAGE_GETTER = new IItemPropertyGetter() { + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { + return MathHelper.clamp_float((float) stack.getItemDamage() / (float) stack.getMaxDamage(), 0.0F, 1.0F); + } + }; + private static final IItemPropertyGetter LEFTHANDED_GETTER = new IItemPropertyGetter() { + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { + // return entityIn != null && entityIn.getPrimaryHand() != EnumHandSide.RIGHT ? + // 1.0F : 0.0F; + return 0.0F; + } + }; + private static final IItemPropertyGetter COOLDOWN_GETTER = new IItemPropertyGetter() { + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { + return entityIn instanceof EntityPlayer + ? ((EntityPlayer) entityIn).getCooldownTracker().getCooldown(stack.getItem(), 0.0F) + : 0.0F; + } + }; + + private final IRegistry properties = new RegistrySimple(); + private static final Map BLOCK_TO_ITEM = Maps.newHashMap(); protected static final EaglercraftUUID ATTACK_DAMAGE_MODIFIER = EaglercraftUUID .fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF"); - protected static final EaglercraftUUID ATTACK_SPEED_MODIFIER = EaglercraftUUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"); + protected static final EaglercraftUUID ATTACK_SPEED_MODIFIER = EaglercraftUUID + .fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"); private CreativeTabs tabToDisplayOn; /** * + @@ -135,6 +167,23 @@ public class Item { return item; } + /** + * Creates a new override param for item models. See usage in clock, compass, + * elytra, etc. + */ + public final void addPropertyOverride(ResourceLocation key, IItemPropertyGetter getter) { + this.properties.putObject(key, getter); + } + + @Nullable + public IItemPropertyGetter getPropertyGetter(ResourceLocation key) { + return (IItemPropertyGetter) this.properties.getObject(key); + } + + public boolean hasCustomProperties() { + return !this.properties.getKeys().isEmpty(); + } + /** * + * Called when an ItemStack with NBT data is read to potentially @@ -1147,10 +1196,10 @@ public class Item { public static enum ToolMaterial { WOOD(0, 59, 2.0F, 0.0F, 15), - STONE(1, 131, 4.0F, 1.0F, 5), - IRON(2, 250, 6.0F, 2.0F, 14), - EMERALD(3, 1561, 8.0F, 3.0F, 10), - GOLD(0, 32, 12.0F, 0.0F, 22); + STONE(1, 131, 4.0F, 1.0F, 5), + IRON(2, 250, 6.0F, 2.0F, 14), + EMERALD(3, 1561, 8.0F, 3.0F, 10), + GOLD(0, 32, 12.0F, 0.0F, 22); private final int harvestLevel; private final int maxUses; diff --git a/src/main/java/net/minecraft/item/ItemElytra.java b/src/main/java/net/minecraft/item/ItemElytra.java index 103f07f..abf43ca 100644 --- a/src/main/java/net/minecraft/item/ItemElytra.java +++ b/src/main/java/net/minecraft/item/ItemElytra.java @@ -1,9 +1,13 @@ package net.minecraft.item; +import javax.annotation.Nullable; + import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; public class ItemElytra extends Item { @@ -11,16 +15,14 @@ public class ItemElytra extends Item { this.maxStackSize = 1; this.setMaxDamage(432); this.setCreativeTab(CreativeTabs.tabTransport); - // this.addPropertyOverride(new ResourceLocation("broken"), new - // IItemPropertyGetter() { - // public float apply(ItemStack stack, @Nullable World worldIn, @Nullable - // EntityLivingBase entityIn) { - // return ItemElytra.isBroken(stack) ? 0.0F : 1.0F; - // } - // }); + this.addPropertyOverride(new ResourceLocation("broken"), new IItemPropertyGetter() { + public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) { + return ItemElytra.isBroken(stack) ? 0.0F : 1.0F; + } + }); } - public boolean isBroken(ItemStack stack) { + public static boolean isBroken(ItemStack stack) { return stack.getItemDamage() < stack.getMaxDamage() - 1; } diff --git a/src/main/java/net/minecraft/util/IRegistry.java b/src/main/java/net/minecraft/util/IRegistry.java index dc4d7e3..5272a6e 100644 --- a/src/main/java/net/minecraft/util/IRegistry.java +++ b/src/main/java/net/minecraft/util/IRegistry.java @@ -1,5 +1,7 @@ package net.minecraft.util; +import java.util.Set; + /** * + * This portion of EaglercraftX contains deobfuscated Minecraft 1.8 source code. @@ -37,4 +39,6 @@ public interface IRegistry extends Iterable { * Register an object on this registry. */ void putObject(K var1, V var2); + + Set getKeys(); } \ No newline at end of file