Pouches now look like / are leather-based

This commit is contained in:
oitsjustjose 2015-12-15 07:54:10 -06:00
commit dbd4db3c79
6 changed files with 202 additions and 44 deletions

View file

@ -31,6 +31,7 @@ public class ItemModBuckets extends Item
this.maxStackSize = 1;
this.setCreativeTab(CrissCross.CCTab);
this.setContainerItem(this);
this.setUnlocalizedName(Lib.modid + ".special_bucket");
GameRegistry.registerItem(this, "special_bucket");
Lib.add(this);
}

View file

@ -11,7 +11,10 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
@ -23,18 +26,73 @@ public class ItemPouch extends Item
public ItemPouch()
{
this.setMaxStackSize(1);
this.setHasSubtypes(true);
this.setUnlocalizedName(Lib.modid + ".pouch");
this.setCreativeTab(CrissCross.CCTab);
GameRegistry.registerItem(this, this.getUnlocalizedName());
Lib.add(this);
}
// Dye specific code below: allows for custom pouch colors, not just your standard 16 colors
public boolean hasColor(ItemStack stack)
{
return (!stack.hasTagCompound() ? false : (!stack.getTagCompound().hasKey("display", 10) ? false : stack.getTagCompound().getCompoundTag("display").hasKey("color", 3)));
}
public void setColor(ItemStack stack, int color)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound == null)
{
nbttagcompound = new NBTTagCompound();
stack.setTagCompound(nbttagcompound);
}
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
if (!nbttagcompound.hasKey("display", 10))
nbttagcompound.setTag("display", nbttagcompound1);
nbttagcompound1.setInteger("color", color);
}
public void removeColor(ItemStack stack)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound != null)
{
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
if (nbttagcompound1.hasKey("color"))
nbttagcompound1.removeTag("color");
}
}
public int getColor(ItemStack stack)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound != null)
{
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
if (nbttagcompound1 != null && nbttagcompound1.hasKey("color", 3))
return nbttagcompound1.getInteger("color");
}
return 10511680;
}
// From here down is just back to normal stuff
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int pass)
public int getColorFromItemStack(ItemStack stack, int renderPass)
{
return ColorUtils.getColorMultiplierFromMeta(stack.getMetadata());
int i = this.getColor(stack);
if (i < 0)
i = 16777215;
return i;
}
@Override
@ -44,28 +102,4 @@ public class ItemPouch extends Item
player.openGui(CrissCross.instance, GUIHandler.Pouch, world, player.inventory.currentItem, 0, 0);
return itemstack;
}
@Override
public String getUnlocalizedNameInefficiently(ItemStack itemstack)
{
String unlocName = StatCollector.translateToLocal("item.CrissCross.pouch.name");
String colorName = EnumDyeColor.byDyeDamage(itemstack.getItemDamage()).getUnlocalizedName();
colorName = colorName.substring(0, 1).toUpperCase() + colorName.substring(1, colorName.length());
return ColorUtils.findFormatForMeta(itemstack.getItemDamage()) + colorName + " " + unlocName;
}
@Override
public String getItemStackDisplayName(ItemStack itemstack)
{
return this.getUnlocalizedNameInefficiently(itemstack);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tab, List list)
{
for (int i = 0; i < 16; i++)
list.add(new ItemStack(item, 1, i));
}
}

View file

@ -2,12 +2,11 @@ package com.oitsjustjose.criss_cross.recipes;
import com.oitsjustjose.criss_cross.items.ItemPouch;
import net.minecraft.init.Items;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
@ -36,26 +35,77 @@ public class PouchColorRecipes implements IRecipe
@Override
public ItemStack getCraftingResult(InventoryCrafting invCraft)
{
ItemStack pouch = null;
ItemStack dye = null;
ItemStack newPouch = null;
for (int i = 0; i < invCraft.getSizeInventory(); i++)
ItemStack itemstack = null;
int[] aint = new int[3];
int i = 0;
int j = 0;
ItemPouch pouch = null;
for (int k = 0; k < invCraft.getSizeInventory(); ++k)
{
if (invCraft.getStackInSlot(i) != null)
ItemStack itemstack1 = invCraft.getStackInSlot(k);
if (itemstack1 != null)
{
if (invCraft.getStackInSlot(i).getItem() instanceof ItemPouch)
pouch = invCraft.getStackInSlot(i);
else if (isOreDictDye(invCraft.getStackInSlot(i)))
dye = invCraft.getStackInSlot(i);
if (itemstack1.getItem() instanceof ItemPouch)
{
pouch = (ItemPouch) itemstack1.getItem();
if (itemstack != null)
return null;
itemstack = itemstack1.copy();
itemstack.stackSize = 1;
if (pouch.hasColor(itemstack1))
{
int l = pouch.getColor(itemstack);
float f = (float) (l >> 16 & 255) / 255.0F;
float f1 = (float) (l >> 8 & 255) / 255.0F;
float f2 = (float) (l & 255) / 255.0F;
i = (int) ((float) i + Math.max(f, Math.max(f1, f2)) * 255.0F);
aint[0] = (int) ((float) aint[0] + f * 255.0F);
aint[1] = (int) ((float) aint[1] + f1 * 255.0F);
aint[2] = (int) ((float) aint[2] + f2 * 255.0F);
++j;
}
}
else
{
if (!isOreDictDye(itemstack1))
return null;
float[] afloat = EntitySheep.func_175513_a(EnumDyeColor.byDyeDamage(getDyeMetaFromString(getOreDictNameForDye(itemstack1))));
int l1 = (int) (afloat[0] * 255.0F);
int i2 = (int) (afloat[1] * 255.0F);
int j2 = (int) (afloat[2] * 255.0F);
i += Math.max(l1, Math.max(i2, j2));
aint[0] += l1;
aint[1] += i2;
aint[2] += j2;
++j;
}
}
}
if (pouch == null || dye == null)
if (pouch == null)
return null;
newPouch = pouch.copy();
newPouch.setItemDamage(getDyeMetaFromString(getOreDictNameForDye(dye)));
return newPouch;
else
{
int i1 = aint[0] / j;
int j1 = aint[1] / j;
int k1 = aint[2] / j;
float f3 = (float) i / (float) j;
float f4 = (float) Math.max(i1, Math.max(j1, k1));
i1 = (int) ((float) i1 * f3 / f4);
j1 = (int) ((float) j1 * f3 / f4);
k1 = (int) ((float) k1 * f3 / f4);
int lvt_12_3_ = (i1 << 8) + j1;
lvt_12_3_ = (lvt_12_3_ << 8) + k1;
pouch.setColor(itemstack, lvt_12_3_);
return itemstack;
}
}
@Override

View file

@ -0,0 +1,77 @@
package com.oitsjustjose.criss_cross.recipes;
import com.oitsjustjose.criss_cross.items.ItemPouch;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class PouchRollbackRecipes implements IRecipe
{
@Override
public boolean matches(InventoryCrafting invCraft, World world)
{
boolean pouchItem = false;
for (int i = 0; i < invCraft.getSizeInventory(); i++)
{
ItemStack stack = invCraft.getStackInSlot(i);
if (stack != null)
if (stack.getItem() instanceof ItemPouch && !pouchItem)
pouchItem = true;
else
return false;
}
return pouchItem;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting invCraft)
{
ItemStack pouch = null;
ItemStack newPouch = null;
for (int i = 0; i < invCraft.getSizeInventory(); i++)
{
if (invCraft.getStackInSlot(i) != null)
{
if (invCraft.getStackInSlot(i).getItem() instanceof ItemPouch)
pouch = invCraft.getStackInSlot(i);
}
}
if (pouch == null || pouch.getItemDamage() == 0)
return null;
newPouch = pouch.copy();
newPouch.setItemDamage(0);
return newPouch;
}
@Override
public int getRecipeSize()
{
return 10;
}
@Override
public ItemStack getRecipeOutput()
{
return null;
}
@Override
public ItemStack[] getRemainingItems(InventoryCrafting invCraft)
{
ItemStack[] ret = new ItemStack[9];
ItemStack stackToClear = null;
for (int i = 0; i < invCraft.getSizeInventory(); i++)
if (invCraft.getStackInSlot(i) != null)
if (!(invCraft.getStackInSlot(i).getItem() instanceof ItemPouch))
ret[i] = invCraft.getStackInSlot(i);
return ret;
}
}

View file

@ -22,11 +22,11 @@ public class VanillaRecipes
woodChipperRecipe();
initOthers();
CraftingManager.getInstance().getRecipeList().add(new PouchColorRecipes());
CraftingManager.getInstance().getRecipeList().add(new PouchRollbackRecipes());
}
static void initOthers()
{
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibBlocks.cobblegen), "CPC", "#$#", "CPC", '$', "blockIron", 'C', "cobblestone", 'P', Blocks.piston, '#', Items.stone_pickaxe));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibBlocks.stonegen), "CPC", "#$#", "CPC", '$', "blockIron", 'C', "stone", 'P', Blocks.piston, '#', Items.stone_pickaxe));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibBlocks.scribe), "BWB", "FES", "BWB", 'B', Items.book, 'W', "plankWood", 'F', Items.feather, 'S', "dyeBlack", 'E', Blocks.enchanting_table));
@ -35,8 +35,7 @@ public class VanillaRecipes
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibItems.infiniApple, 1, 0), "###", "#N#", "###", '#', new ItemStack(Items.golden_apple, 1, 1), 'N', Items.nether_star));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibItems.mantleSmasherMkI), "## ", "#PI", " II", '#', "blockEmerald", 'I', "blockIron", 'P', Items.diamond_pickaxe));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibItems.mantleSmasherMkII), "## ", "#PI", " IN", '#', "blockDiamond", 'I', "blockGold", 'P', LibItems.mantleSmasherMkI, 'N', Items.nether_star));
for (int i = 0; i < 16; i++)
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibItems.pouch, 1, i), "SDS", "WCW", "BWB", 'W', new ItemStack(Blocks.wool, 1, Short.MAX_VALUE), 'S', Items.string, 'D', ColorUtils.getOreDictFromMeta(i), 'C', Blocks.chest, 'B', Items.diamond));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(LibItems.pouch), "SDS", "LCL", "LLL", 'S', Items.string, 'D', "gemDiamond", 'L', Items.leather, 'C', Blocks.chest));
}
static void woodChipperRecipe()

View file

@ -17,7 +17,6 @@ public class ItemHelper
{
public static ItemStack cloneStack(Item item, int stackSize)
{
if (item == null)
{
return null;
@ -66,13 +65,11 @@ public class ItemHelper
public static int getItemDamage(ItemStack stack)
{
return Items.diamond.getDamage(stack);
}
public static ItemStack findMatchingRecipe(InventoryCrafting inv, World world)
{
ItemStack[] dmgItems = new ItemStack[2];
for (int i = 0; i < inv.getSizeInventory(); i++)
{