some small fixes, ore rendering with layers

This commit is contained in:
Boblet 2022-03-31 16:36:26 +02:00
parent c1b9ef3e17
commit 6af5a8eb35
21 changed files with 304 additions and 12 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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");

View File

@ -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;
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -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<Integer, Color> brightMap = new HashMap();
List<Integer> 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);
}
}

View File

@ -64,6 +64,7 @@ public class OreCave {
return this;
}
@SuppressWarnings("incomplete-switch")
@SubscribeEvent
public void onDecorate(DecorateBiomeEvent.Pre event) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B