add item model overrides

This commit is contained in:
HoosierTransfer 2024-07-02 17:33:33 -04:00
parent 80caa21468
commit a863b8a73f
22 changed files with 453 additions and 92 deletions

View File

@ -23,7 +23,7 @@ dependencies {
}
teavm.js {
obfuscated = true
obfuscated = false
sourceMap = true
targetFileName = "../classes.js"
optimization = org.teavm.gradle.api.OptimizationLevel.AGGRESSIVE

Binary file not shown.

Binary file not shown.

View File

@ -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 ]
}
}
}

View File

@ -14,5 +14,13 @@
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
},
"overrides": [
{
"predicate": {
"broken": 1
},
"model": "item/broken_elytra"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

View File

@ -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,14 +41,21 @@ 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.
*
@ -118,7 +126,8 @@ public class JSONTypeProvider {
valid = true;
}
if (!valid) {
throw new IllegalArgumentException("Object " + obj.getClass().getSimpleName() + " is not a JsonSerializer or JsonDeserializer object");
throw new IllegalArgumentException(
"Object " + obj.getClass().getSimpleName() + " is not a JsonSerializer or JsonDeserializer object");
}
}
@ -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());

View File

@ -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());
}
}

View File

@ -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<ResourceLocation, Float> mapResourceValues;
public ItemOverride(ResourceLocation locationIn, Map<ResourceLocation, Float> 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<ResourceLocation, Float> 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<JSONObject, ItemOverride> {
public ItemOverride deserialize(JSONObject jsonObject) throws JSONException {
ResourceLocation resourcelocation = new ResourceLocation(jsonObject.getString("model"));
Map<ResourceLocation, Float> map = this.makeMapResourceValues(jsonObject);
return new ItemOverride(resourcelocation, map);
}
protected Map<ResourceLocation, Float> makeMapResourceValues(JSONObject jsonObject) {
Map<ResourceLocation, Float> map = Maps.<ResourceLocation, Float>newLinkedHashMap();
JSONObject jsonPredicate = jsonObject.getJSONObject("predicate");
for (String key : jsonPredicate.keySet()) {
map.put(new ResourceLocation(key), Float.valueOf(jsonPredicate.getFloat(key)));
}
return map;
}
}
}

View File

@ -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<ItemOverride> overrides = Lists.<ItemOverride>newArrayList();
private ItemOverrideList() {
}
public ItemOverrideList(List<ItemOverride> 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;
}
}

View File

@ -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<ItemOverride> overrides;
public String name;
protected final Map<String, String> textures;
protected ModelBlock parent;
@ -63,18 +69,23 @@ public class ModelBlock {
return (ModelBlock) JSONTypeProvider.deserialize(new JSONObject(parString1), ModelBlock.class);
}
protected ModelBlock(List<BlockPart> parList, Map<String, String> parMap, boolean parFlag, boolean parFlag2,
ItemCameraTransforms parItemCameraTransforms) {
this((ResourceLocation) null, parList, parMap, parFlag, parFlag2, parItemCameraTransforms);
}
// protected ModelBlock(List<BlockPart> parList, Map<String, String> parMap,
// boolean parFlag, boolean parFlag2,
// ItemCameraTransforms parItemCameraTransforms) {
// this((ResourceLocation) null, parList, parMap, parFlag, parFlag2,
// parItemCameraTransforms);
// }
protected ModelBlock(ResourceLocation parResourceLocation, Map<String, String> parMap, boolean parFlag,
boolean parFlag2, ItemCameraTransforms parItemCameraTransforms) {
this(parResourceLocation, Collections.emptyList(), parMap, parFlag, parFlag2, parItemCameraTransforms);
}
// protected ModelBlock(ResourceLocation parResourceLocation, Map<String,
// String> parMap, boolean parFlag,
// boolean parFlag2, ItemCameraTransforms parItemCameraTransforms) {
// this(parResourceLocation, Collections.emptyList(), parMap, parFlag, parFlag2,
// parItemCameraTransforms);
// }
private ModelBlock(ResourceLocation parentLocationIn, List<BlockPart> elementsIn, Map<String, String> texturesIn,
boolean ambientOcclusionIn, boolean gui3dIn, ItemCameraTransforms cameraTransformsIn) {
public ModelBlock(ResourceLocation parentLocationIn, List<BlockPart> elementsIn, Map<String, String> texturesIn,
boolean ambientOcclusionIn, boolean gui3dIn, ItemCameraTransforms cameraTransformsIn,
List<ItemOverride> 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<BlockPart> getElements() {
@ -111,6 +123,24 @@ public class ModelBlock {
}
public Collection<ResourceLocation> getOverrideLocations() {
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (ItemOverride itemoverride : this.overrides) {
set.add(itemoverride.getLocation());
}
return set;
}
protected List<ItemOverride> 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<ItemOverride> 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<ItemOverride> getItemOverrides(JSONObject object) {
List<ItemOverride> 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<String, String> getTextures(JSONObject parJsonObject) {
HashMap hashmap = Maps.newHashMap();
if (parJsonObject.has("textures")) {

View File

@ -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<ResourceLocation> getBlockstateLocations(Block blockIn) {
if (this.setBuiltInBlocks.contains(blockIn)) {
return Collections.<ResourceLocation>emptySet();
} else {
IStateMapper istatemapper = (IStateMapper) this.blockStateMap.get(blockIn);
if (istatemapper == null) {
return Collections.<ResourceLocation>singleton(Block.blockRegistry.getNameForObject(blockIn));
} else {
Set<ResourceLocation> set = Sets.<ResourceLocation>newHashSet();
for (ModelResourceLocation modelresourcelocation : istatemapper.putStateModelLocations(blockIn)
.values()) {
set.add(new ResourceLocation(modelresourcelocation.getResourceDomain(),
modelresourcelocation.getResourcePath()));
}
return set;
}
}
}
public Map<IBlockState, ModelResourceLocation> getVariants(Block blockIn) {
return this.setBuiltInBlocks.contains(blockIn) ? Collections.<IBlockState, ModelResourceLocation>emptyMap()
: ((IStateMapper) Objects.firstNonNull(this.blockStateMap.get(blockIn), new DefaultStateMapper()))
.putStateModelLocations(blockIn);
}
}

View File

@ -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");

View File

@ -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<BakedQuad> getFaceQuads(EnumFacing var1) {
@ -70,4 +73,8 @@ public class BuiltInModel implements IBakedModel {
public ItemCameraTransforms getItemCameraTransforms() {
return this.cameraTransforms;
}
public ItemOverrideList getOverrides() {
return this.overrideList;
}
}

View File

@ -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();
}

View File

@ -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()) {

View File

@ -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<BakedQuad> parList, List<List<BakedQuad>> 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<BakedQuad> 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<BakedQuad> builderGeneralQuads;
private final List<List<BakedQuad>> 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);
}
}
}

View File

@ -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<WeightedBakedModel.MyWeighedRandomItem> listItems = Lists.newArrayList();

View File

@ -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);
}

View File

@ -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<ResourceLocation, Item> 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<ResourceLocation, IItemPropertyGetter> properties = new RegistrySimple();
private static final Map<Block, Item> 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

View File

@ -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;
}

View File

@ -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<K, V> extends Iterable<V> {
* Register an object on this registry.
*/
void putObject(K var1, V var2);
Set<K> getKeys();
}