mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 17:47:32 +00:00
More Edits to Image Buffer and Renderer
This commit is contained in:
1 parent
8f040b7501
commit
c60cf023c0
3 files changed
+86
-233
No files matched your search
@@ -7,47 +7,39 @@ import java.awt.image.ImageObserver;
|
||||
|
||||
import net.minecraft.client.renderer.ImageBufferDownload;
|
||||
|
||||
public class ImageBufferDownloadAlt extends ImageBufferDownload
|
||||
{
|
||||
public class ImageBufferDownloadAlt extends ImageBufferDownload {
|
||||
private int imageData[];
|
||||
private int imageWidth;
|
||||
private int imageHeight;
|
||||
private boolean NPC64;
|
||||
|
||||
public ImageBufferDownloadAlt(){
|
||||
public ImageBufferDownloadAlt() {
|
||||
NPC64 = false;
|
||||
}
|
||||
|
||||
public ImageBufferDownloadAlt(boolean value){
|
||||
public ImageBufferDownloadAlt(boolean value) {
|
||||
NPC64 = value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BufferedImage parseUserSkin(BufferedImage bufferedimage)
|
||||
{
|
||||
public BufferedImage parseUserSkin(BufferedImage bufferedimage) {
|
||||
|
||||
imageWidth = bufferedimage.getWidth(null);
|
||||
|
||||
if(NPC64){
|
||||
imageHeight = bufferedimage.getHeight(null);
|
||||
}
|
||||
else{
|
||||
imageHeight = imageWidth / 2;
|
||||
}
|
||||
imageHeight = bufferedimage.getHeight(null);
|
||||
// } else {
|
||||
// imageHeight = imageWidth / 2;
|
||||
// }
|
||||
|
||||
BufferedImage bufferedimage1 = new BufferedImage(imageWidth, imageHeight, 2);
|
||||
Graphics g = bufferedimage1.getGraphics();
|
||||
g.drawImage(bufferedimage, 0, 0, null);
|
||||
g.dispose();
|
||||
imageData = ((DataBufferInt)bufferedimage1.getRaster().getDataBuffer()).getData();
|
||||
|
||||
if(NPC64){
|
||||
setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 4);
|
||||
}
|
||||
else{
|
||||
setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 2);
|
||||
}
|
||||
imageData = ((DataBufferInt) bufferedimage1.getRaster().getDataBuffer()).getData();
|
||||
setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 4);
|
||||
// } else {
|
||||
// setAreaTransparent(imageWidth / 2, 0, imageWidth, imageHeight / 2);
|
||||
// }
|
||||
|
||||
|
||||
return bufferedimage1;
|
||||
@@ -58,14 +50,10 @@ public class ImageBufferDownloadAlt extends ImageBufferDownload
|
||||
* layer of a skin around the head if it was saved all opaque; this would be redundant so it's assumed that the skin
|
||||
* maker is just using an image editor without an alpha channel)
|
||||
*/
|
||||
private void setAreaTransparent(int par1, int par2, int par3, int par4)
|
||||
{
|
||||
if (!this.hasTransparency(par1, par2, par3, par4))
|
||||
{
|
||||
for (int i1 = par1; i1 < par3; ++i1)
|
||||
{
|
||||
for (int j1 = par2; j1 < par4; ++j1)
|
||||
{
|
||||
private void setAreaTransparent(int par1, int par2, int par3, int par4) {
|
||||
if (!this.hasTransparency(par1, par2, par3, par4)) {
|
||||
for (int i1 = par1; i1 < par3; ++i1) {
|
||||
for (int j1 = par2; j1 < par4; ++j1) {
|
||||
this.imageData[i1 + j1 * this.imageWidth] &= 16777215;
|
||||
}
|
||||
}
|
||||
@@ -75,16 +63,12 @@ public class ImageBufferDownloadAlt extends ImageBufferDownload
|
||||
/**
|
||||
* Returns true if the given area of the image contains transparent pixels
|
||||
*/
|
||||
private boolean hasTransparency(int par1, int par2, int par3, int par4)
|
||||
{
|
||||
for (int i1 = par1; i1 < par3; ++i1)
|
||||
{
|
||||
for (int j1 = par2; j1 < par4; ++j1)
|
||||
{
|
||||
private boolean hasTransparency(int par1, int par2, int par3, int par4) {
|
||||
for (int i1 = par1; i1 < par3; ++i1) {
|
||||
for (int j1 = par2; j1 < par4; ++j1) {
|
||||
int k1 = this.imageData[i1 + j1 * this.imageWidth];
|
||||
|
||||
if ((k1 >> 24 & 255) < 128)
|
||||
{
|
||||
if ((k1 >> 24 & 255) < 128) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -92,191 +76,4 @@ public class ImageBufferDownloadAlt extends ImageBufferDownload
|
||||
|
||||
return false;
|
||||
}
|
||||
//
|
||||
// private boolean loadPlayerData(BufferedImage bufferedimage,EntityPlayer player) {
|
||||
// if(player == null)
|
||||
// return false;
|
||||
// PlayerData data = RenderMorePlayer.getPlayerData(player);
|
||||
// data.setPlayerModel(checkSkin(bufferedimage,player.username));
|
||||
// data.isChanged = true;
|
||||
// return data.model != null;
|
||||
// }
|
||||
// public static ModelData checkSkin(BufferedImage bufferedimage,String player){
|
||||
// if(bufferedimage == null)
|
||||
// return null;
|
||||
//
|
||||
// if (!new Color(bufferedimage.getRGB(0, 0), true).equals(new Color(128, 128, 128, 255))) {
|
||||
// return null;
|
||||
// }
|
||||
// ModelData data = new ModelData();
|
||||
// Color type = new Color(bufferedimage.getRGB(1, 0), true);
|
||||
// if (type.equals(new Color(255, 0, 255, 255))) {
|
||||
// data.type = EnumPlayerModelType.HUMANFEMALE;
|
||||
// data.mainModel = new ModelHumanFemale(data,0);
|
||||
// data.modelArmor = new ModelHumanFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelHumanFemale(data,0.8f);
|
||||
// data.scaleX = 0.9075f;
|
||||
// data.scaleY = 0.9075f;
|
||||
// data.scaleZ = 0.9075f;
|
||||
// } else if (type.equals(new Color(128, 0, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.DWARFMALE;
|
||||
// data.mainModel = new ModelDwarfMale(data,0);
|
||||
// data.modelArmor = new ModelDwarfMale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelDwarfMale(data,0.8f);
|
||||
// data.scaleX = 0.85f;
|
||||
// data.scaleY = 0.6875f;
|
||||
// data.scaleZ = 0.85f;
|
||||
// } else if (type.equals(new Color(255, 0, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.DWARFFEMALE;
|
||||
// data.mainModel = new ModelDwarfFemale(data,0);
|
||||
// data.modelArmor = new ModelDwarfFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelDwarfFemale(data,0.8f);
|
||||
// data.scaleX = 0.75f;
|
||||
// data.scaleY = 0.6275f;
|
||||
// data.scaleZ = 0.75f;
|
||||
// } else if (type.equals(new Color(0, 128, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.ORCMALE;
|
||||
// data.mainModel = new ModelOrcMale(data,0);
|
||||
// data.modelArmor = new ModelOrcMale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelOrcMale(data,0.8f);
|
||||
// data.scaleX = 1.2f;
|
||||
// data.scaleY = 1f;
|
||||
// data.scaleZ = 1.2f;
|
||||
// } else if (type.equals(new Color(0, 255, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.ORCFEMALE;
|
||||
// data.mainModel = new ModelOrcFemale(data,0);
|
||||
// data.modelArmor = new ModelOrcFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelOrcFemale(data,0.8f);
|
||||
// } else if (type.equals(new Color(0, 0, 128, 255))) {
|
||||
// data.type = EnumPlayerModelType.FURRYMALE;
|
||||
// data.mainModel = new ModelFurryMale(data,0);
|
||||
// data.modelArmor = new ModelFurryMale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelFurryMale(data,0.8f);
|
||||
// } else if (type.equals(new Color(0, 0, 255, 255))) {
|
||||
// data.type = EnumPlayerModelType.FURRYFEMALE;
|
||||
// data.mainModel = new ModelFurryFemale(data,0);
|
||||
// data.modelArmor = new ModelFurryFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelFurryFemale(data,0.8f);
|
||||
// data.scaleX = 0.9075f;
|
||||
// data.scaleY = 0.9075f;
|
||||
// data.scaleZ = 0.9075f;
|
||||
// }else if (type.equals(new Color(255, 128, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.MONSTERMALE;
|
||||
// data.mainModel = new ModelMonsterMale(data,0);
|
||||
// data.modelArmor = new ModelMonsterMale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelMonsterMale(data,0.8f);
|
||||
// } else if (type.equals(new Color(255, 255, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.MONSTERFEMALE;
|
||||
// data.mainModel = new ModelMonsterFemale(data,0);
|
||||
// data.modelArmor = new ModelMonsterFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelMonsterFemale(data,0.8f);
|
||||
// data.scaleX = 0.9075f;
|
||||
// data.scaleY = 0.9075f;
|
||||
// data.scaleZ = 0.9075f;
|
||||
// }else if (type.equals(new Color(0,255, 128, 255))) {
|
||||
// data.type = EnumPlayerModelType.ELFMALE;
|
||||
// data.mainModel = new ModelElfMale(data,0);
|
||||
// data.modelArmor = new ModelElfMale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelElfMale(data,0.8f);
|
||||
// data.scaleX = 0.85f;
|
||||
// data.scaleY = 1.07f;
|
||||
// data.scaleZ = 0.85f;
|
||||
// } else if (type.equals(new Color(0, 255, 255, 255))) {
|
||||
// data.type = EnumPlayerModelType.ELFFEMALE;
|
||||
// data.mainModel = new ModelElfFemale(data,0);
|
||||
// data.modelArmor = new ModelElfFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelElfFemale(data,0.8f);
|
||||
// data.scaleX = 0.8f;
|
||||
// data.scaleY = 1f;
|
||||
// data.scaleZ = 0.8f;
|
||||
// } else if (type.equals(new Color(32, 32, 32, 255))) {
|
||||
// data.type = EnumPlayerModelType.ENDER;
|
||||
// data.mainModel = new ModelEnderChibi(data,0);
|
||||
// data.modelArmor = new ModelEnderChibi(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelEnderChibi(data,0.8f);
|
||||
// }
|
||||
// else if (type.equals(new Color(128, 255, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.NAGAMALE;
|
||||
// data.mainModel = new ModelNagaMale(data,0);
|
||||
// data.modelArmor = new ModelNagaMale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelNagaMale(data,0.8f);
|
||||
// }
|
||||
// else if (type.equals(new Color(128, 128, 0, 255))) {
|
||||
// data.type = EnumPlayerModelType.NAGAFEMALE;
|
||||
// data.mainModel = new ModelNagaFemale(data,0);
|
||||
// data.modelArmor = new ModelNagaFemale(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelNagaFemale(data,0.8f);
|
||||
// }
|
||||
// else if(RenderMorePlayer.superUsers.contains(player)){
|
||||
// if (type.equals(new Color(66, 66, 66, 255))){
|
||||
// data.mainModel = new ModelCrystal(data,0);
|
||||
// data.modelArmor = new ModelCrystal(data,0.3f);
|
||||
// data.modelArmorChestplate = new ModelCrystal(data,0.8f);
|
||||
// }
|
||||
// else if (type.equals(new Color(13, 13, 13, 255))){
|
||||
// data.mainModel = new ModelFail(data);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Color sizeColor = new Color(bufferedimage.getRGB(2, 0), true);
|
||||
// int size = 3;
|
||||
// if (sizeColor.equals(new Color(255, 0, 0, 255)))
|
||||
// size = 4;
|
||||
// else if (sizeColor.equals(new Color(0, 255, 0, 255)))
|
||||
// size = 2;
|
||||
// else if (sizeColor.equals(new Color(0, 0, 255, 255)))
|
||||
// size = 1;
|
||||
// else if (sizeColor.equals(new Color(255, 0, 255, 255)))
|
||||
// size = 0;
|
||||
// data.size = size;
|
||||
//
|
||||
// Color headVissible = new Color(bufferedimage.getRGB(3, 0), true);
|
||||
// if (headVissible.equals(new Color(255, 0, 0, 255)))
|
||||
// data.showHelmet = false;
|
||||
// else if (headVissible.equals(new Color(0, 255, 0, 255)))
|
||||
// data.showHeadwear = false;
|
||||
// else if (headVissible.equals(new Color(255, 255, 0, 255))){
|
||||
// data.showHeadwear = false;
|
||||
// data.showHelmet = false;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// int extraOption1 = getValue(new Color(bufferedimage.getRGB(7, 0), true));
|
||||
// data.mainModel.setExtraOption1(extraOption1);
|
||||
// data.modelArmorChestplate.setExtraOption1(extraOption1);
|
||||
// data.modelArmor.setExtraOption1(extraOption1);
|
||||
//
|
||||
// int extraOption2 = getValue(new Color(bufferedimage.getRGB(7, 1), true));
|
||||
// data.mainModel.setExtraOption2(extraOption2);
|
||||
// data.modelArmorChestplate.setExtraOption2(extraOption2);
|
||||
// data.modelArmor.setExtraOption2(extraOption2);
|
||||
//
|
||||
// int extraOption3 = getValue(new Color(bufferedimage.getRGB(7, 2), true));
|
||||
// data.mainModel.setExtraOption3(extraOption3);
|
||||
// data.modelArmorChestplate.setExtraOption3(extraOption3);
|
||||
// data.modelArmor.setExtraOption3(extraOption3);
|
||||
//
|
||||
// Color color = new Color(bufferedimage.getRGB(7, 3), true);
|
||||
// data.mainModel.setExtraColor(color);
|
||||
//
|
||||
// Color claws = new Color(bufferedimage.getRGB(0, 1), true);
|
||||
// if (claws.equals(new Color(255, 0, 0, 255)))
|
||||
// ((ModelInterface)data.mainModel).addClaws();
|
||||
//
|
||||
// data.headSize = getValue(new Color(bufferedimage.getRGB(1, 1), true));
|
||||
//
|
||||
// data.bellySize = getValue(new Color(bufferedimage.getRGB(2, 1), true));
|
||||
// return data;
|
||||
// }
|
||||
// private static int getValue(Color color){
|
||||
// if (color.equals(new Color(255, 0, 0, 255)))
|
||||
// return 1;
|
||||
// else if (color.equals(new Color(0, 255, 0, 255)))
|
||||
// return 2;
|
||||
// else if (color.equals(new Color(0, 0, 255, 255)))
|
||||
// return 3;
|
||||
// else if (color.equals(new Color(255, 0, 255, 255)))
|
||||
// return 4;
|
||||
// return 0;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,19 @@ package noppes.npcs.client.renderer;
|
||||
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED;
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.BLOCK_3D;
|
||||
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.entity.RenderBiped;
|
||||
import net.minecraft.client.renderer.texture.ITextureObject;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.SkinManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -21,16 +28,26 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
import net.minecraftforge.client.MinecraftForgeClient;
|
||||
import noppes.npcs.client.ImageDownloadAlt;
|
||||
import noppes.npcs.client.model.ModelMPM;
|
||||
import noppes.npcs.client.model.ModelNPCMale;
|
||||
import noppes.npcs.constants.EnumAnimation;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.entity.EntityNpcPony;
|
||||
import noppes.npcs.items.ItemClaw;
|
||||
import noppes.npcs.items.ItemShield;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Map;
|
||||
|
||||
public class RenderNPCHumanMale extends RenderNPCInterface
|
||||
{
|
||||
|
||||
@@ -415,6 +432,49 @@ public class RenderNPCHumanMale extends RenderNPCInterface
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getEntityTexture(Entity entity) {
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
|
||||
if (npc.textureLocation == null) {
|
||||
if (npc.display.skinType == 0)
|
||||
npc.textureLocation = new ResourceLocation(npc.display.texture);
|
||||
else if (LastTextureTick < 5) { //fixes request flood somewhat
|
||||
return AbstractClientPlayer.locationStevePng;
|
||||
} else if (npc.display.skinType == 1 && npc.display.playerProfile != null) {
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
Map map = minecraft.func_152342_ad().func_152788_a(npc.display.playerProfile);
|
||||
if (map.containsKey(MinecraftProfileTexture.Type.SKIN)) {
|
||||
npc.textureLocation = minecraft.func_152342_ad().func_152792_a((MinecraftProfileTexture) map.get(MinecraftProfileTexture.Type.SKIN), MinecraftProfileTexture.Type.SKIN);
|
||||
}
|
||||
LastTextureTick = 0;
|
||||
} else if (npc.display.skinType == 2) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
byte[] hash = digest.digest(npc.display.url.getBytes("UTF-8"));
|
||||
StringBuilder sb = new StringBuilder(2 * hash.length);
|
||||
for (byte b : hash) {
|
||||
sb.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
npc.textureLocation = new ResourceLocation("skins/" + sb.toString());
|
||||
loadSkin(null, npc.textureLocation, npc.display.url, false);
|
||||
LastTextureTick = 0;
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(npc.textureLocation == null)
|
||||
return AbstractClientPlayer.locationStevePng;
|
||||
return npc.textureLocation;
|
||||
}
|
||||
|
||||
private void loadSkin(File file, ResourceLocation resource, String par1Str, boolean value){
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
ITextureObject object = new ImageDownloadAlt(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownloadAlt(value));
|
||||
texturemanager.loadTexture(resource, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderEquippedItems(EntityLivingBase entityliving, float f){
|
||||
renderSpecials((EntityNPCInterface)entityliving, f);
|
||||
|
||||
@@ -267,7 +267,6 @@ public class RenderNPCInterface extends RenderLiving{
|
||||
public ResourceLocation getEntityTexture(Entity entity) {
|
||||
|
||||
EntityNPCInterface npc = (EntityNPCInterface) entity;
|
||||
boolean versionModel = false; // Square Texture
|
||||
if(npc.textureLocation == null){
|
||||
if(npc.display.skinType == 0)
|
||||
npc.textureLocation = new ResourceLocation(npc.display.texture);
|
||||
@@ -291,14 +290,11 @@ public class RenderNPCInterface extends RenderLiving{
|
||||
sb.append(String.format("%02x", b&0xff));
|
||||
}
|
||||
npc.textureLocation = new ResourceLocation("skins/" + sb.toString());
|
||||
|
||||
// if(npc.display.squareTexture == 1){ versionModel = true; }
|
||||
|
||||
loadSkin(null, npc.textureLocation, npc.display.url, versionModel);
|
||||
loadSkin(null, npc.textureLocation, npc.display.url);
|
||||
LastTextureTick = 0;
|
||||
}
|
||||
catch(Exception ex){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,9 +304,9 @@ public class RenderNPCInterface extends RenderLiving{
|
||||
}
|
||||
|
||||
// True = 64x64 Skin
|
||||
private void loadSkin(File file, ResourceLocation resource, String par1Str, boolean value){
|
||||
private void loadSkin(File file, ResourceLocation resource, String par1Str){
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
ITextureObject object = new ImageDownloadAlt(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownloadAlt(value));
|
||||
ITextureObject object = new ImageDownloadAlt(file, par1Str, SkinManager.field_152793_a, new ImageBufferDownloadAlt());
|
||||
texturemanager.loadTexture(resource, object);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user