Improve butterfly item texture atlas and model, Fix #1312

This commit is contained in:
Nedelosk committed 2016-11-05 02:26:59 +01:00
1 parent 53a9bf458e
commit 844aea7431
40 files changed
+102 -167

No files matched your search

@@ -37,7 +37,6 @@ import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.Attributes;
import net.minecraftforge.client.model.ICustomModelLoader;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.IRetexturableModel;
@@ -19,6 +19,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
@@ -199,7 +200,7 @@ public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButt
public void registerSprites() {
String spriteName = getItemTexture();
TextureMap textureMap = Minecraft.getMinecraft().getTextureMapBlocks();
textureMap.setTextureEntry(spriteName, new TextureAtlasButterfly(spriteName));
textureMap.registerSprite(new ResourceLocation(spriteName));
}
@Override
@@ -33,8 +33,8 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.ModelProcessingHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.lepidopterology.ButterflyManager;
import forestry.api.lepidopterology.IAlleleButterflySpecies;
import forestry.api.lepidopterology.IButterfly;
import forestry.core.models.BlankModel;
import forestry.core.models.DefaultTextureGetter;
@@ -46,7 +46,7 @@ public class ModelButterflyItem extends BlankModel {
@SideOnly(Side.CLIENT)
private static IModel modelButterfly;
private static final Cache<IButterfly, IBakedModel> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build();
private static final Cache<IAlleleButterflySpecies, IBakedModel> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES).build();
public static void onModelBake(ModelBakeEvent event){
modelButterfly = null;
@@ -73,7 +73,7 @@ public class ModelButterflyItem extends BlankModel {
}
}
IModel retexturedModel = ModelProcessingHelper.retexture(modelButterfly, textures.build());
return new TRSRBakedModel(retexturedModel.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, textureGetter), -0.03125F, 0.5F, -0.03125F, butterfly.getSize() * 1.5F);
return new TRSRBakedModel(retexturedModel.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, textureGetter), -0.03125F, 0.25F - butterfly.getSize() * 0.37F, -0.03125F, butterfly.getSize() * 1.5F);
}
private class ButterflyItemOverrideList extends ItemOverrideList {
@@ -87,10 +87,13 @@ public class ModelButterflyItem extends BlankModel {
if (butterfly == null) {
butterfly = ButterflyManager.butterflyRoot.templateAsIndividual(ButterflyManager.butterflyRoot.getDefaultTemplate());
}
if(cache.getIfPresent(butterfly) == null){
cache.put(butterfly, bakeModel(butterfly));
IAlleleButterflySpecies primary = butterfly.getGenome().getPrimary();
IBakedModel bakedModel = cache.getIfPresent(primary);
if(bakedModel == null){
bakedModel = bakeModel(butterfly);
cache.put(primary, bakedModel);
}
return cache.getIfPresent(butterfly);
return bakedModel;
}
}
}
@@ -1,59 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.lepidopterology.render;
import com.google.common.collect.Lists;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
public class TextureAtlasButterfly extends TextureAtlasSprite {
public TextureAtlasButterfly(String spriteName) {
super(spriteName);
}
// TODO: fix butterfly sprite
// @Override
// public void loadSprite(BufferedImage[] images, AnimationMetadataSection meta) throws IOException {
// this.resetSprite();
// int i = images[0].getWidth();
// int j = images[0].getHeight();
// this.width = i;
// this.height = j;
// int[][] aint = new int[images.length][];
//
// for (int k = 0; k < images.length; ++k) {
// BufferedImage bufferedimage = images[k];
//
// if (bufferedimage != null) {
// if (k > 0 && (bufferedimage.getWidth() != i >> k || bufferedimage.getHeight() != j >> k)) {
// throw new RuntimeException(String.format("Unable to load miplevel: %d, image is size: %dx%d, expected %dx%d", new Object[]{Integer.valueOf(k), Integer.valueOf(bufferedimage.getWidth()), Integer.valueOf(bufferedimage.getHeight()), Integer.valueOf(i >> k), Integer.valueOf(j >> k)}));
// }
//
// aint[k] = new int[bufferedimage.getWidth() * bufferedimage.getHeight()];
// bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), aint[k], 0, bufferedimage.getWidth());
// }
// }
// this.framesTextureData.add(aint);
// }
private void resetSprite() {
this.setFramesTextureData(Lists.newArrayList());
this.frameCounter = 0;
this.tickCounter = 0;
}
@Override
public boolean hasAnimationMetadata() {
return false;
}
}