public EntityLivingBase getEntity(ItemStack stack) { if(stack.getItem() == Item.getItemFromBlock(Blocks.AIR) || stack.equals(ItemStack.EMPTY)) { this.entity = null; return null; } try { this.entity = (EntityLivingBase) ForgeRegistries.ENTITIES.getValue((ItemMonsterPlacer.getNamedIdFrom(stack))).newInstance(world); } catch (NullPointerException e) { } return this.entity; }
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId()) { int i = pos.getY(); BlockPos blockpos; for (blockpos = pos; !World.doesBlockHaveSolidTopSurface(worldIn, blockpos) && blockpos.getY() > 0; blockpos = blockpos.down()) { ; } if (i > 0 && !worldIn.getBlockState(blockpos.up()).getBlock().isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, 57, (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
private static int getSpawnEggColor(ItemMonsterPlacer p_getSpawnEggColor_0_, ItemStack p_getSpawnEggColor_1_, int p_getSpawnEggColor_2_, int p_getSpawnEggColor_3_) { int i = p_getSpawnEggColor_1_.getMetadata(); int[] aint = p_getSpawnEggColor_2_ == 0 ? spawnEggPrimaryColors : spawnEggSecondaryColors; if (aint == null) { return p_getSpawnEggColor_3_; } else if (i >= 0 && i < aint.length) { int j = aint[i]; return j < 0 ? p_getSpawnEggColor_3_ : j; } else { return p_getSpawnEggColor_3_; } }
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId()) { int i = pos.getY(); BlockPos blockpos; for (blockpos = pos; !worldIn.getBlockState(blockpos).isFullyOpaque() && blockpos.getY() > 0; blockpos = blockpos.down()) { ; } if (i > 0 && !worldIn.getBlockState(blockpos.up()).isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, EntityList.func_191306_a(EntityPigZombie.class), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId()) { int i = pos.getY(); BlockPos blockpos; for (blockpos = pos; !worldIn.getBlockState(blockpos).isFullyOpaque() && blockpos.getY() > 0; blockpos = blockpos.down()) { ; } if (i > 0 && !worldIn.getBlockState(blockpos.up()).isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, EntityList.getEntityStringFromClass(EntityPigZombie.class), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
/** * Ticks the block if it's been scheduled */ public void updateTick(World world, int x, int y, int z, Random random) { super.updateTick(world, x, y, z, random); if (world.provider.isSurfaceWorld() && world.getGameRules().getGameRuleBooleanValue("doMobSpawning") && random.nextInt(2000) < world.difficultySetting.getDifficultyId()) { int l; for (l = y; !World.doesBlockHaveSolidTopSurface(world, x, l, z) && l > 0; --l) { ; } if (l > 0 && !world.getBlock(x, l + 1, z).isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(world, 57, (double)x + 0.5D, (double)l + 1.1D, (double)z + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
/** * Ticks the block if it's been scheduled */ public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) { super.updateTick(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_5_); if (p_149674_1_.provider.isSurfaceWorld() && p_149674_1_.getGameRules().getGameRuleBooleanValue("doMobSpawning") && p_149674_5_.nextInt(2000) < p_149674_1_.difficultySetting.getDifficultyId()) { int var6; for (var6 = p_149674_3_; !World.doesBlockHaveSolidTopSurface(p_149674_1_, p_149674_2_, var6, p_149674_4_) && var6 > 0; --var6) { ; } if (var6 > 0 && !p_149674_1_.getBlock(p_149674_2_, var6 + 1, p_149674_4_).isNormalCube()) { Entity var7 = ItemMonsterPlacer.spawnCreature(p_149674_1_, 57, (double)p_149674_2_ + 0.5D, (double)var6 + 1.1D, (double)p_149674_4_ + 0.5D); if (var7 != null) { var7.timeUntilPortal = var7.getPortalCooldown(); } } } }
public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) { super.updateTick(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_5_); if (p_149674_1_.getSpigotConfig().enableZombiePigmenPortalSpawns && p_149674_1_.provider.isSurfaceWorld() && p_149674_1_.getGameRules().getGameRuleBooleanValue("doMobSpawning") && p_149674_5_.nextInt(2000) < p_149674_1_.difficultySetting.getDifficultyId()) // Spigot // Cauldron { int l; for (l = p_149674_3_; !World.doesBlockHaveSolidTopSurface(p_149674_1_, p_149674_2_, l, p_149674_4_) && l > 0; --l) { ; } if (l > 0 && !p_149674_1_.getBlock(p_149674_2_, l + 1, p_149674_4_).isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(p_149674_1_, 57, (double)p_149674_2_ + 0.5D, (double)l + 1.1D, (double)p_149674_4_ + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) { super.updateTick(p_149674_1_, p_149674_2_, p_149674_3_, p_149674_4_, p_149674_5_); if (p_149674_1_.provider.isSurfaceWorld() && p_149674_1_.getGameRules().getGameRuleBooleanValue("doMobSpawning") && p_149674_5_.nextInt(2000) < p_149674_1_.difficultySetting.getDifficultyId()) { int l; for (l = p_149674_3_; !World.doesBlockHaveSolidTopSurface(p_149674_1_, p_149674_2_, l, p_149674_4_) && l > 0; --l) { ; } if (l > 0 && !p_149674_1_.getBlock(p_149674_2_, l + 1, p_149674_4_).isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(p_149674_1_, 57, (double)p_149674_2_ + 0.5D, (double)l + 1.1D, (double)p_149674_4_ + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
public void func_71847_b(World p_71847_1_, int p_71847_2_, int p_71847_3_, int p_71847_4_, Random p_71847_5_) { super.func_71847_b(p_71847_1_, p_71847_2_, p_71847_3_, p_71847_4_, p_71847_5_); if(p_71847_1_.field_73011_w.func_76569_d() && p_71847_5_.nextInt(2000) < p_71847_1_.field_73013_u) { int var6; for(var6 = p_71847_3_; !p_71847_1_.func_72797_t(p_71847_2_, var6, p_71847_4_) && var6 > 0; --var6) { ; } if(var6 > 0 && !p_71847_1_.func_72809_s(p_71847_2_, var6 + 1, p_71847_4_)) { Entity var7 = ItemMonsterPlacer.func_77840_a(p_71847_1_, 57, (double)p_71847_2_ + 0.5D, (double)var6 + 1.1D, (double)p_71847_4_ + 0.5D); if(var7 != null) { var7.field_71088_bW = var7.func_82147_ab(); } } } }
/** * Ticks the block if it's been scheduled */ public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { super.updateTick(par1World, par2, par3, par4, par5Random); if (par1World.provider.isSurfaceWorld() && par5Random.nextInt(2000) < par1World.difficultySetting) { int l; for (l = par3; !par1World.doesBlockHaveSolidTopSurface(par2, l, par4) && l > 0; --l) { ; } if (l > 0 && !par1World.isBlockNormalCube(par2, l + 1, par4)) { Entity entity = ItemMonsterPlacer.spawnCreature(par1World, 57, (double)par2 + 0.5D, (double)l + 1.1D, (double)par4 + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
/** * Dispense the specified stack, play the dispense sound and spawn particles. */ public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing enumfacing = BlockDispenser.getFacing(par1IBlockSource.getBlockMetadata()); double d0 = par1IBlockSource.getX() + (double)enumfacing.getFrontOffsetX(); double d1 = (double)((float)par1IBlockSource.getYInt() + 0.2F); double d2 = par1IBlockSource.getZ() + (double)enumfacing.getFrontOffsetZ(); Entity entity = ItemMonsterPlacer.spawnCreature(par1IBlockSource.getWorld(), par2ItemStack.getItemDamage(), d0, d1, d2); if (entity instanceof EntityLivingBase && par2ItemStack.hasDisplayName()) { ((EntityLiving)entity).setCustomNameTag(par2ItemStack.getDisplayName()); } par2ItemStack.splitStack(1); return par2ItemStack; }
@Override public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { super.updateTick(par1World, par2, par3, par4, par5Random); if (par1World.provider.isSurfaceWorld() && par5Random.nextInt(2000) < par1World.difficultySetting) { int l; for (l = par3; !par1World.doesBlockHaveSolidTopSurface(par2, l, par4) && l > 0; --l) { ; } if (l > 0 && !par1World.isBlockNormalCube(par2, l + 1, par4)) { Entity entity = ItemMonsterPlacer.spawnCreature(par1World, 57, par2 + 0.5D, l + 1.1D, par4 + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
/** * Checks to see if this location is valid to create a portal and will * return True if it does. Args: world, x, y, z */ @Override public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) { super.updateTick(par1World, par2, par3, par4, par5Random); if (par1World.provider.isSurfaceWorld() && (par5Random.nextInt(2000) < par1World.difficultySetting)){ int l; for (l = par3; !par1World.doesBlockHaveSolidTopSurface(par2, l, par4) && (l > 0); --l){ ; } if ((l > 0) && !par1World.isBlockNormalCube(par2, l + 1, par4)){ Entity entity = ItemMonsterPlacer.spawnCreature(par1World, 57, par2 + 0.5D, l + 1.1D, par4 + 0.5D); if (entity != null){ entity.timeUntilPortal = entity.getPortalCooldown(); } } } }
/** * Dispense the specified stack, play the dispense sound and spawn particles. */ public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing enumfacing = BlockDispenser.func_149937_b/*getFacing*/(par1IBlockSource.getBlockMetadata()); double d0 = par1IBlockSource.getX() + (double)enumfacing.getFrontOffsetX(); double d1 = (double)((float)par1IBlockSource.getYInt() + 0.2F) + enumfacing.getFrontOffsetY(); double d2 = par1IBlockSource.getZ() + (double)enumfacing.getFrontOffsetZ(); Entity entity = ItemMonsterPlacer.spawnCreature(par1IBlockSource.getWorld(), par2ItemStack.getItemDamage(), d0, d1, d2); if (entity instanceof EntityLiving && par2ItemStack.hasDisplayName()) { ((EntityLiving)entity).setCustomNameTag(par2ItemStack.getDisplayName()); } par2ItemStack.splitStack(1); return par2ItemStack; }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(playerIn.getHeldItem(hand).getItem() instanceof ItemMonsterPlacer || playerIn.getHeldItem(hand).getItem() == Item.getItemFromBlock(Blocks.AIR)) super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); return playerIn.capabilities.isCreativeMode; }
public static int getColorFromItemStack(ItemStack p_getColorFromItemStack_0_, int p_getColorFromItemStack_1_, int p_getColorFromItemStack_2_) { if (p_getColorFromItemStack_0_ == null) { return p_getColorFromItemStack_2_; } else { Item item = p_getColorFromItemStack_0_.getItem(); return item == null ? p_getColorFromItemStack_2_ : (item instanceof ItemMonsterPlacer ? getSpawnEggColor((ItemMonsterPlacer)item, p_getColorFromItemStack_0_, p_getColorFromItemStack_1_, p_getColorFromItemStack_2_) : p_getColorFromItemStack_2_); } }
public boolean processInteract(EntityPlayer player, EnumHand hand) { ItemStack itemstack = player.getHeldItem(hand); if (itemstack.getItem() == Items.SPAWN_EGG) { if (!this.world.isRemote) { Class <? extends Entity > oclass = (Class)EntityList.field_191308_b.getObject(ItemMonsterPlacer.func_190908_h(itemstack)); if (oclass != null && this.getClass() == oclass) { EntityAgeable entityageable = this.createChild(this); if (entityageable != null) { entityageable.setGrowingAge(-24000); entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F); this.world.spawnEntityInWorld(entityageable); if (itemstack.hasDisplayName()) { entityageable.setCustomNameTag(itemstack.getDisplayName()); } if (!player.capabilities.isCreativeMode) { itemstack.func_190918_g(1); } } } } return true; } else { return false; } }
protected boolean func_190669_a(ItemStack p_190669_1_, Class <? extends Entity > p_190669_2_) { if (p_190669_1_.getItem() != Items.SPAWN_EGG) { return false; } else { Class <? extends Entity > oclass = (Class)EntityList.field_191308_b.getObject(ItemMonsterPlacer.func_190908_h(p_190669_1_)); return oclass != null && p_190669_2_ == oclass; } }
public boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack) { if (stack != null && stack.getItem() == Items.SPAWN_EGG) { if (!this.worldObj.isRemote) { Class <? extends Entity > oclass = EntityList.NAME_TO_CLASS.get(ItemMonsterPlacer.getEntityIdFromItem(stack)); if (oclass != null && this.getClass() == oclass) { EntityAgeable entityageable = this.createChild(this); if (entityageable != null) { entityageable.setGrowingAge(-24000); entityageable.setLocationAndAngles(this.posX, this.posY, this.posZ, 0.0F, 0.0F); this.worldObj.spawnEntityInWorld(entityageable); if (stack.hasDisplayName()) { entityageable.setCustomNameTag(stack.getDisplayName()); } if (!player.capabilities.isCreativeMode) { --stack.stackSize; } } } } return true; } else { return false; } }
/** * Display all items and also an actor egg */ @Override @SideOnly(Side.CLIENT) public void displayAllRelevantItems(java.util.List<net.minecraft.item.ItemStack> items) { super.displayAllRelevantItems(items); ItemStack stack = new ItemStack(Items.SPAWN_EGG); ItemMonsterPlacer.applyEntityIdToItemStack(stack, "blockbuster.Actor"); items.add(stack); }
public ItemStack func_82487_b(IBlockSource p_82487_1_, ItemStack p_82487_2_) { EnumFacing var3 = BlockDispenser.func_100009_j_(p_82487_1_.func_82620_h()); double var4 = p_82487_1_.func_82615_a() + (double)var3.func_82601_c(); double var6 = (double)((float)p_82487_1_.func_82622_e() + 0.2F); double var8 = p_82487_1_.func_82616_c() + (double)var3.func_82599_e(); Entity var10 = ItemMonsterPlacer.func_77840_a(p_82487_1_.func_82618_k(), p_82487_2_.func_77960_j(), var4, var6, var8); if(var10 instanceof EntityLivingBase && p_82487_2_.func_82837_s()) { ((EntityLiving)var10).func_94058_c(p_82487_2_.func_82833_r()); } p_82487_2_.func_77979_a(1); return p_82487_2_; }
/** Attempt to break the item on this itemstack into a type/variant/colour which we can use for communication with the Malmo platform. * @param is the ItemStack containing the item we are attempting to deconstruct. * @return an XML DrawItem object containing the item's type, variant, colour etc. */ public static DrawItem getDrawItemFromItemStack(ItemStack is) { if (is == null) return null; DrawItem di = new DrawItem(); String name = is.getUnlocalizedName(); // Get unlocalised name from the stack, not the stack's item - this ensures we keep the metadata. if (is.getHasSubtypes()) { // If the item has subtypes, then there are varieties - eg different colours, types, etc. // Attempt to map from these subtypes back to variant/colour. // Do this by decomposing the unlocalised name: List<String> itemParts = new ArrayList<String>(Arrays.asList(name.split("\\."))); if (is.getItem() instanceof ItemMonsterPlacer) { // Special case for eggs: itemParts.add(ItemMonsterPlacer.getEntityName(is)); } // First part will be "tile" or "item". // Second part will be the item itself (eg "dyePowder" or "stainedGlass" etc). // Third part will be the variant, colour etc. Colour col = null; Variation var = null; for (int part = 2; part < itemParts.size(); part++) { String section = itemParts.get(part); // First see if this matches a colour: if (col == null) { col = attemptToGetAsColour(section); if (col == null && var == null) // If it wasn't a colour, check to see if it was a variant: var = attemptToGetAsVariant(section, is); } else if (var == null) var = attemptToGetAsVariant(section, is); } di.setColour(col); di.setVariant(var); } // Use the item registry name for the item - this is what we use in Types.XSD Object obj = Item.itemRegistry.getNameForObject(is.getItem()); String publicName; if (obj instanceof ResourceLocation) publicName = ((ResourceLocation)obj).getResourcePath(); else publicName = obj.toString(); di.setType(publicName); return di; }
private static int getSpawnEggColor(ItemMonsterPlacer p_getSpawnEggColor_0_, ItemStack p_getSpawnEggColor_1_, int p_getSpawnEggColor_2_, int p_getSpawnEggColor_3_) { if (spawnEggPrimaryColors == null && spawnEggSecondaryColors == null) { return p_getSpawnEggColor_3_; } else { NBTTagCompound nbttagcompound = p_getSpawnEggColor_1_.getTagCompound(); if (nbttagcompound == null) { return p_getSpawnEggColor_3_; } else { NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("EntityTag"); if (nbttagcompound1 == null) { return p_getSpawnEggColor_3_; } else { String s = nbttagcompound1.getString("id"); int i = EntityUtils.getEntityIdByLocation(s); int[] aint = p_getSpawnEggColor_2_ == 0 ? spawnEggPrimaryColors : spawnEggSecondaryColors; if (aint == null) { return p_getSpawnEggColor_3_; } else if (i >= 0 && i < aint.length) { int j = aint[i]; return j < 0 ? p_getSpawnEggColor_3_ : j; } else { return p_getSpawnEggColor_3_; } } } } }
/** Attempt to break the item on this itemstack into a type/variant/colour which we can use for communication with the Malmo platform. * @param is the ItemStack containing the item we are attempting to deconstruct. * @return an XML DrawItem object containing the item's type, variant, colour etc. */ public static DrawItem getDrawItemFromItemStack(ItemStack is) { if (is == null) return null; DrawItem di = new DrawItem(); String name = is.getUnlocalizedName(); // Get unlocalised name from the stack, not the stack's item - this ensures we keep the metadata. if (is.getHasSubtypes()) { // If the item has subtypes, then there are varieties - eg different colours, types, etc. // Attempt to map from these subtypes back to variant/colour. // Do this by decomposing the unlocalised name: List<String> itemParts = new ArrayList<String>(Arrays.asList(name.split("\\."))); if (is.getItem() instanceof ItemMonsterPlacer) { // Special case for eggs: itemParts.add(ItemMonsterPlacer.getNamedIdFrom(is).toString()); } // First part will be "tile" or "item". // Second part will be the item itself (eg "dyePowder" or "stainedGlass" etc). // Third part will be the variant, colour etc. Colour col = null; Variation var = null; for (int part = 2; part < itemParts.size(); part++) { String section = itemParts.get(part); // First see if this matches a colour: if (col == null) { col = attemptToGetAsColour(section); if (col == null && var == null) // If it wasn't a colour, check to see if it was a variant: var = attemptToGetAsVariant(section, is); } else if (var == null) var = attemptToGetAsVariant(section, is); } di.setColour(col); di.setVariant(var); } // Use the item registry name for the item - this is what we use in Types.XSD Object obj = Item.REGISTRY.getNameForObject(is.getItem()); String publicName; if (obj instanceof ResourceLocation) publicName = ((ResourceLocation)obj).getResourcePath(); else publicName = obj.toString(); di.setType(publicName); return di; }
public static ItemStack getItemStackFromDrawItem(DrawItem i) { ItemStack itemStack = null; // First see if this is an item: Item item = MinecraftTypeHelper.ParseItemType(i.getType(), false); if (item == null) { // No, so is it a block type? IBlockState block = MinecraftTypeHelper.ParseBlockType(i.getType()); if (block != null) { // It is - apply the modifications: block = BlockDrawingHelper.applyModifications(block, i.getColour(), i.getFace(), i.getVariant()); // And try to return as an item: if (block != null && block.getBlock() != null && Item.getItemFromBlock(block.getBlock()) != null) { itemStack = new ItemStack(block.getBlock(), 1, block.getBlock().getMetaFromState(block)); } } } else { if (item.getHasSubtypes() && (i.getColour() != null || i.getVariant() != null)) { // Attempt to find the subtype for this colour/variant - made tricky // because Items don't provide any nice property stuff like Blocks do... NonNullList<ItemStack> subItems = NonNullList.create(); item.getSubItems(item, null, subItems); for (ItemStack is : subItems) { String fullName = is.getUnlocalizedName(); if (is.getItem() instanceof ItemMonsterPlacer) { fullName += "." + ItemMonsterPlacer.getNamedIdFrom(is).toString(); // Special handling for eggs } String[] parts = fullName.split("\\."); for (int p = 0; p < parts.length; p++) { Variation v = attemptToGetAsVariant(parts[p], is); Colour c = attemptToGetAsColour(parts[p]); if ((v != null && i.getVariant() != null && v.getValue().equals(i.getVariant().getValue())) || (c != null && i.getColour() != null && c == i.getColour())) { // This is it?? return is; } } } } itemStack = new ItemStack(item); } return itemStack; }
/** Find the average color of an item */ public static int getAverageColorUnbounded(ItemStack stack) { ItemColors cols = Minecraft.getMinecraft().getItemColors(); // null -> return white if(stack == null) return DEFAULT_COLOR; ItemStack nStack = stack.copy(); nStack.stackSize = 1; // constant size (for counting / caching) Item item = nStack.getItem(); // this stack overrides all color calculations if(item instanceof IOverrideEBColor) { return ((IOverrideEBColor)item).getEverythingBlockColor(nStack); } // non-overridden calculations cached for performance if(itemColorCache.containsKey(item.toString())) { return itemColorCache.get(item.toString()); } else if(stackColorCache.containsKey(nStack.toString())) { return stackColorCache.get(nStack.toString()); } // the color of potion stacks is their liquid color if(item instanceof ItemPotion) { return addStackToColorCache(nStack, cols.getColorFromItemstack(stack, 0)); } // the color of spawn egg blocks is the average of their layers if(item instanceof ItemMonsterPlacer) { IntList colList = (IntList) new IntList().join(cols.getColorFromItemstack(stack, 0)).join(cols.getColorFromItemstack(stack, 1)); return addStackToColorCache(nStack, ColorHelper.averageColors(colList)); } // dyeable armor returns a slightly darkened dye color if(item instanceof ItemArmor && ((ItemArmor)item).getColor(stack) > -1) { return addStackToColorCache(nStack, ColorHelper.averageColors(((ItemArmor)item).getColor(stack), 0, 0.75)); } // sensitive code try { // get the texture from the ItemStack (IN GAME, not in init methods or events!) TextureAtlasSprite sprite = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(nStack).getParticleTexture(); if(sprite == null) return addStackToColorCache(nStack, cols.getColorFromItemstack(stack, 0)); // default to item stack color int w = sprite.getIconWidth(); int h = sprite.getIconHeight(); // now look at the pixels IntList colors = new IntList(); int[] aint = sprite.getFrameTextureData(0)[0]; for(int x = 0; x < w; x++) { for(int y = 0; y < h; y++) { int c = aint[x + y * h]; if(c == 0) continue; // skip alpha pixels colors.add(c); } } // this is the base color int baseColor = ColorHelper.averageColors(colors); // now get the defined item stack color int stackColor = cols.getColorFromItemstack(stack, 0); // get the subtractive mix, add it to the cache, and return! return addStackToColorCache(nStack, ColorHelper.subtractMixColors(baseColor, stackColor)); } catch (Exception e) { Log.logger.warn("Exception caught getting color from ItemStack " + nStack.toString()); return addStackToColorCache(nStack, DEFAULT_COLOR); } }