Skip to content

Commit

Permalink
Add default textures that are used if no proper texture is present. T…
Browse files Browse the repository at this point in the history
…his texture is then colored with the material-color. Furthermore you can now add HandleColor, HeadColor,... tag to change the color of tool parts!
  • Loading branch information
bonii-xx committed Sep 21, 2014
1 parent ab87cc7 commit 8e0cea2
Show file tree
Hide file tree
Showing 119 changed files with 119 additions and 87 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 65 additions & 87 deletions src/main/java/tconstruct/library/tools/ToolCore.java
Expand Up @@ -5,6 +5,7 @@
import cpw.mods.fml.relauncher.*;
import java.util.*;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.*;
Expand All @@ -13,9 +14,12 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*;
import net.minecraft.world.World;
import tconstruct.TConstruct;
import tconstruct.library.*;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.modifier.*;
import tconstruct.library.util.TextureHelper;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.entity.FancyEntityItem;

/**
Expand Down Expand Up @@ -186,63 +190,31 @@ public void registerEffectPath (int index, String location)
@Override
public void registerIcons (IIconRegister iconRegister)
{
headIcons.clear();
brokenIcons.clear();
handleIcons.clear();
accessoryIcons.clear();
extraIcons.clear();
effectIcons.clear();
Iterator iter = headStrings.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry pairs = (Map.Entry) iter.next();
headIcons.put((Integer) pairs.getKey(), iconRegister.registerIcon((String) pairs.getValue()));
}
addIcons(headStrings, headIcons, iconRegister, getIconSuffix(0));
addIcons(brokenPartStrings, brokenIcons, iconRegister, getIconSuffix(1));
addIcons(handleStrings, handleIcons, iconRegister, getIconSuffix(2));
addIcons(accessoryStrings, accessoryIcons, iconRegister, getIconSuffix(3));
addIcons(extraStrings, extraIcons, iconRegister, getIconSuffix(4));

iter = brokenPartStrings.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry pairs = (Map.Entry) iter.next();
brokenIcons.put((Integer) pairs.getKey(), iconRegister.registerIcon((String) pairs.getValue()));
}

iter = handleStrings.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry pairs = (Map.Entry) iter.next();
handleIcons.put((Integer) pairs.getKey(), iconRegister.registerIcon((String) pairs.getValue()));
}

if (getPartAmount() > 2)
{
iter = accessoryStrings.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry pairs = (Map.Entry) iter.next();
accessoryIcons.put((Integer) pairs.getKey(), iconRegister.registerIcon((String) pairs.getValue()));
}
}
emptyIcon = iconRegister.registerIcon("tinker:blankface");
}

if (getPartAmount() > 3)
private void addIcons(HashMap<Integer, String> textures, HashMap<Integer, IIcon> icons, IIconRegister iconRegister, String standard)
{
icons.clear();
for(Map.Entry<Integer, String> entry : textures.entrySet())
{
iter = extraStrings.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry pairs = (Map.Entry) iter.next();
extraIcons.put((Integer) pairs.getKey(), iconRegister.registerIcon((String) pairs.getValue()));
}
if(TextureHelper.itemTextureExists(entry.getValue()))
icons.put(entry.getKey(), iconRegister.registerIcon(entry.getValue()));
}

iter = effectStrings.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry pairs = (Map.Entry) iter.next();
effectIcons.put((Integer) pairs.getKey(), iconRegister.registerIcon((String) pairs.getValue()));
if(standard != null && !standard.isEmpty()) {
standard = "tinker:" + getDefaultFolder() + "/" + standard;
icons.put(-1, iconRegister.registerIcon(standard));
}

emptyIcon = iconRegister.registerIcon("tinker:blankface");
}


@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage (int meta)
Expand All @@ -261,30 +233,25 @@ public IIcon getIcon (ItemStack stack, int renderPass)
tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (renderPass < getPartAmount())
{
if (renderPass == 0) // Handle
{
return handleIcons.get(tags.getInteger("RenderHandle"));
}

else if (renderPass == 1) // Head
// Handle
if (renderPass == 0)
return getCorrectIcon(handleIcons, tags.getInteger("RenderHandle"));
// Head
else if (renderPass == 1)
{
if (tags.getBoolean("Broken"))
return (brokenIcons.get(tags.getInteger("RenderHead")));
return getCorrectIcon(brokenIcons, tags.getInteger("RenderHead"));
else
return (headIcons.get(tags.getInteger("RenderHead")));
}

else if (renderPass == 2) // Accessory
{
return (accessoryIcons.get(tags.getInteger("RenderAccessory")));
}

else if (renderPass == 3) // Extra
{
return (extraIcons.get(tags.getInteger("RenderExtra")));
return getCorrectIcon(headIcons, tags.getInteger("RenderHead"));
}
// Accessory
else if (renderPass == 2)
return getCorrectIcon(accessoryIcons, tags.getInteger("RenderAccessory"));
// Extra
else if (renderPass == 3)
return getCorrectIcon(extraIcons, tags.getInteger("RenderExtra"));
}

// Effects
else
{
if (renderPass == getPartAmount())
Expand Down Expand Up @@ -328,6 +295,15 @@ else if (renderPass == getPartAmount() + 5)
return emptyIcon;
}

protected IIcon getCorrectIcon(Map<Integer, IIcon> icons, int id)
{
if(icons.containsKey(id))
return icons.get(id);

// default icon
return icons.get(-1);
}

/* Tags and information about the tool */
@Override
@SideOnly(Side.CLIENT)
Expand Down Expand Up @@ -565,7 +541,7 @@ public Item getExtraItem ()

public Item getHandleItem ()
{
return TConstructRegistry.getItem("toolRod");// TContent.toolRod;
return TinkerTools.toolRod;
}

/* Updating */
Expand Down Expand Up @@ -664,38 +640,40 @@ public float getDamageModifier ()

@Override
public int getColorFromItemStack(ItemStack stack, int renderPass) {

NBTTagCompound tags = stack.getTagCompound();

if (tags != null)
{
tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (renderPass < getPartAmount())
{
if (renderPass == 0 && tags.hasKey("HandleColor")) // Handle
switch(renderPass)
{
return tags.getInteger("HandleColor");
}

else if (renderPass == 1 && tags.hasKey("HeadColor")) // Head
{
return tags.getInteger("HeadColor");
}

else if (renderPass == 2 && tags.hasKey("AccessoryColor")) // Accessory
{
return tags.getInteger("AccessoryColor");
}

else if (renderPass == 3 && tags.hasKey("ExtraColor")) // Extra
{
return tags.getInteger("ExtraColor");
case 0: return getCorrectColor(stack, renderPass, tags, "Handle", handleIcons);
case 1: return getCorrectColor(stack, renderPass, tags, "Head", headIcons);
case 2: return getCorrectColor(stack, renderPass, tags, "Accessory", accessoryIcons);
case 3: return getCorrectColor(stack, renderPass, tags, "Extra", extraIcons);
}
}
}
return super.getColorFromItemStack(stack, renderPass);
}

private int getCorrectColor(ItemStack stack, int renderPass, NBTTagCompound tags, String key, Map<Integer, IIcon> map)
{
// custom coloring
if(tags.hasKey(key + "Color"))
return tags.getInteger(key + "Color");

// custom texture?
Integer matId = tags.getInteger("Render" + key);
if(map.containsKey(matId))
return super.getColorFromItemStack(stack, renderPass);

// color default texture with material color
return TConstructRegistry.getMaterial(matId).primaryColor();
}

@Override
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
{
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/tconstruct/library/util/TextureHelper.java
@@ -0,0 +1,54 @@
package tconstruct.library.util;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;

// Stolen from CofHLib RegistryUtil
public final class TextureHelper {
private TextureHelper() {}

@SideOnly(Side.CLIENT)
public static boolean textureExists(ResourceLocation texture) {

try {
Minecraft.getMinecraft().getResourceManager().getAllResources(texture);
return true;
} catch (Throwable t) { // pokemon!
return false;
}
}

@SideOnly(Side.CLIENT)
public static boolean textureExists(String texture) {

return textureExists(new ResourceLocation(texture));
}

@SideOnly(Side.CLIENT)
public static boolean blockTextureExists(String texture) {

int i = texture.indexOf(':');

if (i > 0) {
texture = texture.substring(0, i) + ":textures/blocks/" + texture.substring(i + 1, texture.length());
} else {
texture = "textures/blocks/" + texture;
}
return textureExists(texture + ".png");
}

@SideOnly(Side.CLIENT)
public static boolean itemTextureExists(String texture) {

int i = texture.indexOf(':');

if (i > 0) {
texture = texture.substring(0, i) + ":textures/items/" + texture.substring(i + 1, texture.length());
} else {
texture = "textures/items/" + texture;
}
return textureExists(texture + ".png");
}
}

0 comments on commit 8e0cea2

Please sign in to comment.