diff --git a/src/main/java/api/hbm/energy/PowerNet.java b/src/main/java/api/hbm/energy/PowerNet.java index 12012eb1e..2969e9e4d 100644 --- a/src/main/java/api/hbm/energy/PowerNet.java +++ b/src/main/java/api/hbm/energy/PowerNet.java @@ -96,12 +96,18 @@ public class PowerNet implements IPowerNet { return this.valid; } + public long lastCleanup = System.currentTimeMillis(); + @Override public long transferPower(long power) { - this.subscribers.removeIf(x -> - x == null || !(x instanceof TileEntity) || ((TileEntity)x).isInvalid() - ); + if(lastCleanup + 45 < System.currentTimeMillis()) { + this.subscribers.removeIf(x -> + x == null || !(x instanceof TileEntity) || ((TileEntity)x).isInvalid() || !x.isLoaded() + ); + + lastCleanup = System.currentTimeMillis(); + } if(this.subscribers.isEmpty()) return power; diff --git a/src/main/java/com/hbm/blocks/ILookOverlay.java b/src/main/java/com/hbm/blocks/ILookOverlay.java index 47ff64eea..d100ed767 100644 --- a/src/main/java/com/hbm/blocks/ILookOverlay.java +++ b/src/main/java/com/hbm/blocks/ILookOverlay.java @@ -49,6 +49,7 @@ public interface ILookOverlay { } GL11.glDisable(GL11.GL_BLEND); + GL11.glColor3f(1F, 1F, 1F); GL11.glPopMatrix(); Minecraft.getMinecraft().renderEngine.bindTexture(Gui.icons); diff --git a/src/main/java/com/hbm/blocks/ModBlocks.java b/src/main/java/com/hbm/blocks/ModBlocks.java index 5420a428a..4e768e7ed 100644 --- a/src/main/java/com/hbm/blocks/ModBlocks.java +++ b/src/main/java/com/hbm/blocks/ModBlocks.java @@ -83,6 +83,8 @@ public class ModBlocks { public static Block ore_cinnebar; public static Block ore_coltan; public static Block ore_alexandrite; + + public static Block ore_random; public static Block ore_bedrock_coltan; @@ -1342,6 +1344,8 @@ public class ModBlocks { cluster_depth_titanium = new BlockDepthOre().setBlockName("cluster_depth_titanium").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":cluster_depth_titanium"); cluster_depth_tungsten = new BlockDepthOre().setBlockName("cluster_depth_tungsten").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":cluster_depth_tungsten"); ore_alexandrite = new BlockDepthOre().setBlockName("ore_alexandrite").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":ore_alexandrite"); + + ore_random = new BlockMotherOfAllOres().setBlockName("ore_random").setCreativeTab(MainRegistry.blockTab); depth_brick = new BlockDepth().setBlockName("depth_brick").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":depth_brick"); depth_tiles = new BlockDepth().setBlockName("depth_tiles").setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":depth_tiles"); diff --git a/src/main/java/com/hbm/blocks/generic/BlockMotherOfAllOres.java b/src/main/java/com/hbm/blocks/generic/BlockMotherOfAllOres.java new file mode 100644 index 000000000..6a093fe80 --- /dev/null +++ b/src/main/java/com/hbm/blocks/generic/BlockMotherOfAllOres.java @@ -0,0 +1,109 @@ +package com.hbm.blocks.generic; + +import com.hbm.blocks.IBlockMultiPass; +import com.hbm.inventory.RecipesCommon.ComparableStack; +import com.hbm.lib.RefStrings; +import com.hbm.render.block.RenderBlockMultipass; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public class BlockMotherOfAllOres extends BlockContainer implements IBlockMultiPass { + + public BlockMotherOfAllOres() { + super(Material.rock); + this.blockIcon = Blocks.stone.getIcon(0, 0); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileEntityRandomOre(); + } + + @Override + public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { + + TileEntity te = world.getTileEntity(x, y, z); + + if(te instanceof TileEntityRandomOre) { + return ((TileEntityRandomOre) te).getStack().copy(); + } + + return super.getPickBlock(target, world, x, y, z); + } + + @Override + public int getRenderType(){ + return IBlockMultiPass.getRenderType(); + } + + @Override + public int getPasses() { + return 2; + } + + private IIcon[] overlays = new IIcon[10]; + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister reg) { + for(int i = 0; i < overlays.length; i++) { + overlays[i] = reg.registerIcon(RefStrings.MODID + ":ore_random_" + (i + 1)); + } + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + + if(RenderBlockMultipass.currentPass == 0) + return this.blockIcon; + + TileEntity te = world.getTileEntity(x, y, z); + + if(te instanceof TileEntityRandomOre) { + TileEntityRandomOre ore = (TileEntityRandomOre) te; + ItemStack item = ore.getStack(); + + if(item != null) { + ComparableStack stack = new ComparableStack(item); + int index = stack.hashCode() % overlays.length; + return overlays[index]; + } + } + + return this.getIcon(side, world.getBlockMetadata(x, y, z)); + } + + @Override + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess world, int x, int y, int z) { + + if(RenderBlockMultipass.currentPass == 0) + return 0xffffff; + + return super.colorMultiplier(world, x, y, z); + } + + public static class TileEntityRandomOre extends TileEntity { + + public ItemStack getStack() { + return new ItemStack(Blocks.dirt); + } + + @Override + public boolean canUpdate() { + return false; + } + } +} diff --git a/src/main/java/com/hbm/items/machine/ItemChemistryIcon.java b/src/main/java/com/hbm/items/machine/ItemChemistryIcon.java index 6e67efada..f3e190dc5 100644 --- a/src/main/java/com/hbm/items/machine/ItemChemistryIcon.java +++ b/src/main/java/com/hbm/items/machine/ItemChemistryIcon.java @@ -13,7 +13,6 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; public class ItemChemistryIcon extends Item { @@ -59,6 +58,12 @@ public class ItemChemistryIcon extends Item { @SideOnly(Side.CLIENT) public IIcon getIconFromDamage(int i) { - return this.icons[ChemplantRecipes.indexMapping.get(i).listing % this.icons.length]; + ChemRecipe rec = ChemplantRecipes.indexMapping.get(i); + + if(rec != null) { + return this.icons[rec.listing % this.icons.length]; + } else { + return ModItems.nothing.getIconFromDamage(i); + } } } diff --git a/src/main/java/com/hbm/render/block/RenderBlockMultipass.java b/src/main/java/com/hbm/render/block/RenderBlockMultipass.java index bd4090f1e..9a3e26d03 100644 --- a/src/main/java/com/hbm/render/block/RenderBlockMultipass.java +++ b/src/main/java/com/hbm/render/block/RenderBlockMultipass.java @@ -66,7 +66,6 @@ public class RenderBlockMultipass implements ISimpleBlockRenderingHandler { public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { Tessellator tessellator = Tessellator.instance; - //int meta = world.getBlockMetadata(x, y, z); tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); @@ -82,8 +81,6 @@ public class RenderBlockMultipass implements ISimpleBlockRenderingHandler { for(int i = 0; i < passes; i++) { currentPass = i; - //System.out.println(multi.getColorFromPass(world, x, y, z, false)); - //tessellator.setColorOpaque_I(multi.getColorFromPass(world, x, y, z, false)); renderer.renderStandardBlock(block, x, y, z); } diff --git a/src/main/java/com/hbm/render/model/ModelGasMask.java b/src/main/java/com/hbm/render/model/ModelGasMask.java index 3fc9d8bd3..a32833c9b 100644 --- a/src/main/java/com/hbm/render/model/ModelGasMask.java +++ b/src/main/java/com/hbm/render/model/ModelGasMask.java @@ -100,10 +100,20 @@ public class ModelGasMask extends ModelBiped { @Override public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7) { setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity); - GL11.glPushMatrix(); - GL11.glScalef(1.15F, 1.15F, 1.15F); - this.mask.render(par7); - GL11.glPopMatrix(); + + if(this.isChild) { + float f6 = 2.0F; + GL11.glPushMatrix(); + GL11.glScalef(1.5F / f6, 1.5F / f6, 1.5F / f6); + GL11.glTranslatef(0.0F, 16.0F * par7, 0.0F); + this.mask.render(par7); + GL11.glPopMatrix(); + } else { + GL11.glPushMatrix(); + GL11.glScalef(1.15F, 1.15F, 1.15F); + this.mask.render(par7); + GL11.glPopMatrix(); + } } protected void convertToChild(ModelRenderer parParent, ModelRenderer parChild) { diff --git a/src/main/java/com/hbm/util/ColorUtil.java b/src/main/java/com/hbm/util/ColorUtil.java new file mode 100644 index 000000000..60779593e --- /dev/null +++ b/src/main/java/com/hbm/util/ColorUtil.java @@ -0,0 +1,159 @@ +package com.hbm.util; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +import javax.imageio.ImageIO; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +public class ColorUtil { + + @SideOnly(Side.CLIENT) + public static BufferedImage getImageFromStack(ItemStack stack) throws IOException { + String iconName = stack.getItem().getIconFromDamage(stack.getItemDamage()).getIconName(); + String domain = "minecraft"; + + if(iconName.contains(":")) { + String[] parts = iconName.split(":"); + domain = parts[0]; + iconName = parts[1]; + } + + ResourceLocation loc = new ResourceLocation(domain, "textures/items/" + iconName + ".png"); + + return ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream()); + } + + @SideOnly(Side.CLIENT) + public static int getAverageColorFromStack(ItemStack stack) { + + try { + BufferedImage tex = getImageFromStack(stack); + + int r = 0; + int g = 0; + int b = 0; + int pixels = 0; + + for(int i = 0; i < tex.getWidth(); i++) { + for(int j = 0; j < tex.getHeight(); j++) { + + Color pixel = new Color(tex.getRGB(i, j)); + + if(pixel.getAlpha() == 255) { + r += pixel.getRed(); + g += pixel.getGreen(); + b += pixel.getBlue(); + pixels++; + } + } + } + + int avgR = r / pixels; + int avgG = g / pixels; + int avgB = b / pixels; + + return (r << 16) | (g << 8) | b; + + } catch(Exception ex) { + return 0xFFFFFF; + } + } + + @SideOnly(Side.CLIENT) + public static int getMedianBrightnessColorFromStack(ItemStack stack) { + + try { + BufferedImage tex = getImageFromStack(stack); + + HashMap brightMap = new HashMap(); + List brightnesses = new ArrayList(); + + for(int i = 0; i < tex.getWidth(); i++) { + for(int j = 0; j < tex.getHeight(); j++) { + + Color pixel = new Color(tex.getRGB(i, j)); + int brightness = pixel.getRed() * pixel.getRed() + pixel.getGreen() * pixel.getGreen() + pixel.getBlue() * pixel.getBlue(); + brightnesses.add(brightness); + brightMap.put(brightness, pixel); //overlap possible, but we don't differentiate between colors anyway. + } + } + + Collections.sort(brightnesses); + int median = brightnesses.get(brightnesses.size() / 2); + Color medianColor = brightMap.get(median); + + return medianColor.getRGB(); + + } catch(Exception ex) { + return 0xFFFFFF; + } + } + + /** + * Decides whether a color is considered "colorful", i.e. weeds out colors that are too dark or too close to gray. + * @param hex + * @return + */ + public static boolean isColorColorful(int hex) { + Color color = new Color(hex); + + /*double r = color.getRed(); + double g = color.getBlue(); + double b = color.getGreen(); + + if(r < 50 && g < 50 && b < 50) + return false; + + if(r / g > 1.5) return true; + if(r / b > 1.5) return true; + if(g / r > 1.5) return true; + if(g / b > 1.5) return true; + if(b / r > 1.5) return true; + if(b / g > 1.5) return true;*/ + + float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[0]); + + // saturation brightness + return hsb[1] > 0.25 && hsb[2] > 0.25; + } + + /** + * Raises the highest RGB component to the specified limit, scaling the other components with it. + * @param hex + * @param limit + * @return + */ + public static int amplifyColor(int hex, int limit) { + Color color = new Color(hex); + int r = color.getRed(); + int g = color.getGreen(); + int b = color.getBlue(); + int max = Math.max(r, Math.max(g, b)); + + r = r * limit / max; + g = g * limit / max; + b = b * limit / max; + + return new Color(r, g, b).getRGB(); + } + + /** + * Same as the regular amplifyColor but it uses 255 as the limit. + * @param hex + * @return + */ + public static int amplifyColor(int hex) { + return amplifyColor(hex, 255); + } +} diff --git a/src/main/java/com/hbm/world/feature/OreCave.java b/src/main/java/com/hbm/world/feature/OreCave.java index 26a701d02..0dba4397b 100644 --- a/src/main/java/com/hbm/world/feature/OreCave.java +++ b/src/main/java/com/hbm/world/feature/OreCave.java @@ -64,6 +64,7 @@ public class OreCave { return this; } + @SuppressWarnings("incomplete-switch") @SubscribeEvent public void onDecorate(DecorateBiomeEvent.Pre event) { diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_cobalt.png b/src/main/resources/assets/hbm/textures/blocks/ore_cobalt.png index 63c77c56f..2553fad84 100644 Binary files a/src/main/resources/assets/hbm/textures/blocks/ore_cobalt.png and b/src/main/resources/assets/hbm/textures/blocks/ore_cobalt.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_copper.png b/src/main/resources/assets/hbm/textures/blocks/ore_copper.png index fb0dafefb..ae1ff8b0c 100644 Binary files a/src/main/resources/assets/hbm/textures/blocks/ore_copper.png and b/src/main/resources/assets/hbm/textures/blocks/ore_copper.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_1.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_1.png new file mode 100644 index 000000000..4734b44ff Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_1.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_10.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_10.png new file mode 100644 index 000000000..68105a382 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_10.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_2.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_2.png new file mode 100644 index 000000000..20355496d Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_2.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_3.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_3.png new file mode 100644 index 000000000..1ca9e37fc Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_3.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_4.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_4.png new file mode 100644 index 000000000..df4ffe5c1 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_4.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_5.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_5.png new file mode 100644 index 000000000..34b4c9d9a Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_5.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_6.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_6.png new file mode 100644 index 000000000..64be59eba Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_6.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_7.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_7.png new file mode 100644 index 000000000..998362475 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_7.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_8.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_8.png new file mode 100644 index 000000000..39858c8bb Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_8.png differ diff --git a/src/main/resources/assets/hbm/textures/blocks/ore_random_9.png b/src/main/resources/assets/hbm/textures/blocks/ore_random_9.png new file mode 100644 index 000000000..78fb424b2 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/blocks/ore_random_9.png differ