inital connected textures, still needs some work.
This commit is contained in:
parent
628fb11961
commit
fcec162559
3 changed files with 634 additions and 65 deletions
|
@ -3,7 +3,7 @@ package techreborn.blocks;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import erogenousbeef.coreTR.multiblock.BlockMultiblockBase;
|
||||
import forestry.core.render.TextureManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
|
@ -13,10 +13,10 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.client.texture.ConnectedTexture;
|
||||
import techreborn.client.texture.ConnectedTextureGenerator;
|
||||
import techreborn.tiles.TileMachineCasing;
|
||||
|
||||
|
@ -27,7 +27,7 @@ public class BlockMachineCasing extends BlockMultiblockBase {
|
|||
|
||||
public static final String[] types = new String[]
|
||||
{"standard", "reinforced", "advanced"};
|
||||
private IIcon[] textures;
|
||||
public IIcon[][] icons;
|
||||
|
||||
public BlockMachineCasing(Material material) {
|
||||
super(material);
|
||||
|
@ -54,47 +54,56 @@ public class BlockMachineCasing extends BlockMultiblockBase {
|
|||
return metaData;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
// this.textures = new IIcon[types.length];
|
||||
//
|
||||
// for (int i = 0; i < types.length; i++) {
|
||||
// textures[i] = iconRegister.registerIcon("techreborn:"
|
||||
// + "machine/casing" + types[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
this.textures = new IIcon[types.length];
|
||||
this.icons = new IIcon[types.length][16];
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
// up down left right
|
||||
icons[i][0] = genIcon(new ConnectedTexture(true, true, true, true), iconRegister, 0, i);
|
||||
icons[i][1] = genIcon(new ConnectedTexture(true, false, true, true), iconRegister, 1, i);
|
||||
icons[i][2] = genIcon(new ConnectedTexture(false, true, true, true), iconRegister, 2, i);
|
||||
icons[i][3] = genIcon(new ConnectedTexture(true, true, true, false), iconRegister, 3, i);
|
||||
icons[i][4] = genIcon(new ConnectedTexture(true, true, false, true), iconRegister, 4, i);
|
||||
icons[i][5] = genIcon(new ConnectedTexture(true, true, false, false), iconRegister, 5, i);
|
||||
icons[i][6] = genIcon(new ConnectedTexture(false, false, true, true), iconRegister, 6, i);
|
||||
icons[i][7] = genIcon(new ConnectedTexture(true, false, false, true), iconRegister, 7, i);
|
||||
icons[i][8] = genIcon(new ConnectedTexture(true, false, true, false), iconRegister, 8, i);
|
||||
icons[i][9] = genIcon(new ConnectedTexture(false, true, false, true), iconRegister, 9, i);
|
||||
icons[i][10] = genIcon(new ConnectedTexture(false, true, true, false), iconRegister, 9, i);
|
||||
icons[i][11] = genIcon(new ConnectedTexture(false, true, false, false), iconRegister, 9, i);
|
||||
icons[i][12] = genIcon(new ConnectedTexture(true, false, false, false), iconRegister, 9, i);
|
||||
icons[i][13] = genIcon(new ConnectedTexture(true, false, false, false), iconRegister, 9, i);
|
||||
icons[i][14] = genIcon(new ConnectedTexture(false, false, true, false), iconRegister, 9, i);
|
||||
icons[i][15] = genIcon(new ConnectedTexture(false, false, false, false), iconRegister, 9, i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public IIcon genIcon(ConnectedTexture connectedTexture, IIconRegister iconRegister, int texNum, int meta){
|
||||
if(iconRegister instanceof TextureMap){
|
||||
TextureMap map = (TextureMap) iconRegister;
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
String name = ConnectedTextureGenerator.getDerivedName(types[i]);
|
||||
System.out.println(name);
|
||||
TextureAtlasSprite texture = map.getTextureExtry(name);
|
||||
if(texture == null){
|
||||
texture = new ConnectedTextureGenerator(name, types[i]);
|
||||
map.setTextureEntry(name, texture);
|
||||
}
|
||||
textures[i] = map.getTextureExtry(name);
|
||||
String name = ConnectedTextureGenerator.getDerivedName(types[meta] + "." + texNum);
|
||||
TextureAtlasSprite texture = map.getTextureExtry(name);
|
||||
if(texture == null){
|
||||
texture = new ConnectedTextureGenerator(name, types[meta], connectedTexture);
|
||||
map.setTextureEntry(name, texture);
|
||||
}
|
||||
return map.getTextureExtry(name);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int metaData) {
|
||||
metaData = MathHelper.clamp_int(metaData, 0, types.length - 1);
|
||||
|
||||
if (ForgeDirection.getOrientation(side) == ForgeDirection.UP
|
||||
|| ForgeDirection.getOrientation(side) == ForgeDirection.DOWN) {
|
||||
return textures[metaData];
|
||||
} else {
|
||||
return textures[metaData];
|
||||
public IIcon getIcon(IBlockAccess blockAccess, int x, int y, int z, int side) {
|
||||
int meta = blockAccess.getBlockMetadata(x, y, z);
|
||||
if(meta > types.length){
|
||||
return getConnectedBlockTexture(blockAccess, x, y, z, meta, icons[0]);
|
||||
}
|
||||
return getConnectedBlockTexture(blockAccess, x, y, z, meta, icons[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,4 +122,523 @@ public class BlockMachineCasing extends BlockMultiblockBase {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This is taken from https://github.com/SlimeKnights/TinkersConstruct/blob/a7405a3d10318bb5c486ec75fb62897a8149d1a6/src/main/java/tconstruct/smeltery/blocks/GlassBlockConnected.java
|
||||
*
|
||||
* @param par1IBlockAccess
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param meta
|
||||
* @param icons
|
||||
* @return
|
||||
*/
|
||||
public IIcon getConnectedBlockTexture (IBlockAccess par1IBlockAccess, int x, int y, int z, int meta, IIcon[] icons)
|
||||
{
|
||||
boolean isOpenUp = false, isOpenDown = false, isOpenLeft = false, isOpenRight = false;
|
||||
switch (meta)
|
||||
{
|
||||
case 0:
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x - 1, y, z), par1IBlockAccess.getBlockMetadata(x - 1, y, z)))
|
||||
{
|
||||
isOpenDown = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x + 1, y, z), par1IBlockAccess.getBlockMetadata(x + 1, y, z)))
|
||||
{
|
||||
isOpenUp = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z - 1), par1IBlockAccess.getBlockMetadata(x, y, z - 1)))
|
||||
{
|
||||
isOpenLeft = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z + 1), par1IBlockAccess.getBlockMetadata(x, y, z + 1)))
|
||||
{
|
||||
isOpenRight = true;
|
||||
}
|
||||
|
||||
if (isOpenUp && isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[15];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[11];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[12];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[13];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[14];
|
||||
}
|
||||
else if (isOpenDown && isOpenUp)
|
||||
{
|
||||
return icons[5];
|
||||
}
|
||||
else if (isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[6];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[8];
|
||||
}
|
||||
else if (isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[10];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft)
|
||||
{
|
||||
return icons[7];
|
||||
}
|
||||
else if (isOpenUp && isOpenRight)
|
||||
{
|
||||
return icons[9];
|
||||
}
|
||||
else if (isOpenDown)
|
||||
{
|
||||
return icons[3];
|
||||
}
|
||||
else if (isOpenUp)
|
||||
{
|
||||
return icons[4];
|
||||
}
|
||||
else if (isOpenLeft)
|
||||
{
|
||||
return icons[2];
|
||||
}
|
||||
else if (isOpenRight)
|
||||
{
|
||||
return icons[1];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x - 1, y, z), par1IBlockAccess.getBlockMetadata(x - 1, y, z)))
|
||||
{
|
||||
isOpenDown = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x + 1, y, z), par1IBlockAccess.getBlockMetadata(x + 1, y, z)))
|
||||
{
|
||||
isOpenUp = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z - 1), par1IBlockAccess.getBlockMetadata(x, y, z - 1)))
|
||||
{
|
||||
isOpenLeft = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z + 1), par1IBlockAccess.getBlockMetadata(x, y, z + 1)))
|
||||
{
|
||||
isOpenRight = true;
|
||||
}
|
||||
|
||||
if (isOpenUp && isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[15];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[11];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[12];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[13];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[14];
|
||||
}
|
||||
else if (isOpenDown && isOpenUp)
|
||||
{
|
||||
return icons[5];
|
||||
}
|
||||
else if (isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[6];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[8];
|
||||
}
|
||||
else if (isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[10];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft)
|
||||
{
|
||||
return icons[7];
|
||||
}
|
||||
else if (isOpenUp && isOpenRight)
|
||||
{
|
||||
return icons[9];
|
||||
}
|
||||
else if (isOpenDown)
|
||||
{
|
||||
return icons[3];
|
||||
}
|
||||
else if (isOpenUp)
|
||||
{
|
||||
return icons[4];
|
||||
}
|
||||
else if (isOpenLeft)
|
||||
{
|
||||
return icons[2];
|
||||
}
|
||||
else if (isOpenRight)
|
||||
{
|
||||
return icons[1];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y - 1, z), par1IBlockAccess.getBlockMetadata(x, y - 1, z)))
|
||||
{
|
||||
isOpenDown = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y + 1, z), par1IBlockAccess.getBlockMetadata(x, y + 1, z)))
|
||||
{
|
||||
isOpenUp = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x - 1, y, z), par1IBlockAccess.getBlockMetadata(x - 1, y, z)))
|
||||
{
|
||||
isOpenLeft = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x + 1, y, z), par1IBlockAccess.getBlockMetadata(x + 1, y, z)))
|
||||
{
|
||||
isOpenRight = true;
|
||||
}
|
||||
|
||||
if (isOpenUp && isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[15];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[13];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[14];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[11];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[12];
|
||||
}
|
||||
else if (isOpenDown && isOpenUp)
|
||||
{
|
||||
return icons[6];
|
||||
}
|
||||
else if (isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[5];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[9];
|
||||
}
|
||||
else if (isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[10];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft)
|
||||
{
|
||||
return icons[7];
|
||||
}
|
||||
else if (isOpenUp && isOpenRight)
|
||||
{
|
||||
return icons[8];
|
||||
}
|
||||
else if (isOpenDown)
|
||||
{
|
||||
return icons[1];
|
||||
}
|
||||
else if (isOpenUp)
|
||||
{
|
||||
return icons[2];
|
||||
}
|
||||
else if (isOpenLeft)
|
||||
{
|
||||
return icons[4];
|
||||
}
|
||||
else if (isOpenRight)
|
||||
{
|
||||
return icons[3];
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y - 1, z), par1IBlockAccess.getBlockMetadata(x, y - 1, z)))
|
||||
{
|
||||
isOpenDown = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y + 1, z), par1IBlockAccess.getBlockMetadata(x, y + 1, z)))
|
||||
{
|
||||
isOpenUp = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x - 1, y, z), par1IBlockAccess.getBlockMetadata(x - 1, y, z)))
|
||||
{
|
||||
isOpenLeft = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x + 1, y, z), par1IBlockAccess.getBlockMetadata(x + 1, y, z)))
|
||||
{
|
||||
isOpenRight = true;
|
||||
}
|
||||
|
||||
if (isOpenUp && isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[15];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[14];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[13];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[11];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[12];
|
||||
}
|
||||
else if (isOpenDown && isOpenUp)
|
||||
{
|
||||
return icons[6];
|
||||
}
|
||||
else if (isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[5];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[10];
|
||||
}
|
||||
else if (isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[9];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft)
|
||||
{
|
||||
return icons[8];
|
||||
}
|
||||
else if (isOpenUp && isOpenRight)
|
||||
{
|
||||
return icons[7];
|
||||
}
|
||||
else if (isOpenDown)
|
||||
{
|
||||
return icons[1];
|
||||
}
|
||||
else if (isOpenUp)
|
||||
{
|
||||
return icons[2];
|
||||
}
|
||||
else if (isOpenLeft)
|
||||
{
|
||||
return icons[3];
|
||||
}
|
||||
else if (isOpenRight)
|
||||
{
|
||||
return icons[4];
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y - 1, z), par1IBlockAccess.getBlockMetadata(x, y - 1, z)))
|
||||
{
|
||||
isOpenDown = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y + 1, z), par1IBlockAccess.getBlockMetadata(x, y + 1, z)))
|
||||
{
|
||||
isOpenUp = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z - 1), par1IBlockAccess.getBlockMetadata(x, y, z - 1)))
|
||||
{
|
||||
isOpenLeft = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z + 1), par1IBlockAccess.getBlockMetadata(x, y, z + 1)))
|
||||
{
|
||||
isOpenRight = true;
|
||||
}
|
||||
|
||||
if (isOpenUp && isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[15];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[14];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[13];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[11];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[12];
|
||||
}
|
||||
else if (isOpenDown && isOpenUp)
|
||||
{
|
||||
return icons[6];
|
||||
}
|
||||
else if (isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[5];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[10];
|
||||
}
|
||||
else if (isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[9];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft)
|
||||
{
|
||||
return icons[8];
|
||||
}
|
||||
else if (isOpenUp && isOpenRight)
|
||||
{
|
||||
return icons[7];
|
||||
}
|
||||
else if (isOpenDown)
|
||||
{
|
||||
return icons[1];
|
||||
}
|
||||
else if (isOpenUp)
|
||||
{
|
||||
return icons[2];
|
||||
}
|
||||
else if (isOpenLeft)
|
||||
{
|
||||
return icons[3];
|
||||
}
|
||||
else if (isOpenRight)
|
||||
{
|
||||
return icons[4];
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y - 1, z), par1IBlockAccess.getBlockMetadata(x, y - 1, z)))
|
||||
{
|
||||
isOpenDown = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y + 1, z), par1IBlockAccess.getBlockMetadata(x, y + 1, z)))
|
||||
{
|
||||
isOpenUp = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z - 1), par1IBlockAccess.getBlockMetadata(x, y, z - 1)))
|
||||
{
|
||||
isOpenLeft = true;
|
||||
}
|
||||
|
||||
if (shouldConnectToBlock(par1IBlockAccess, x, y, z, par1IBlockAccess.getBlock(x, y, z + 1), par1IBlockAccess.getBlockMetadata(x, y, z + 1)))
|
||||
{
|
||||
isOpenRight = true;
|
||||
}
|
||||
|
||||
if (isOpenUp && isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[15];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[13];
|
||||
}
|
||||
else if (isOpenUp && isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[14];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[11];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[12];
|
||||
}
|
||||
else if (isOpenDown && isOpenUp)
|
||||
{
|
||||
return icons[6];
|
||||
}
|
||||
else if (isOpenLeft && isOpenRight)
|
||||
{
|
||||
return icons[5];
|
||||
}
|
||||
else if (isOpenDown && isOpenLeft)
|
||||
{
|
||||
return icons[9];
|
||||
}
|
||||
else if (isOpenDown && isOpenRight)
|
||||
{
|
||||
return icons[10];
|
||||
}
|
||||
else if (isOpenUp && isOpenLeft)
|
||||
{
|
||||
return icons[7];
|
||||
}
|
||||
else if (isOpenUp && isOpenRight)
|
||||
{
|
||||
return icons[8];
|
||||
}
|
||||
else if (isOpenDown)
|
||||
{
|
||||
return icons[1];
|
||||
}
|
||||
else if (isOpenUp)
|
||||
{
|
||||
return icons[2];
|
||||
}
|
||||
else if (isOpenLeft)
|
||||
{
|
||||
return icons[4];
|
||||
}
|
||||
else if (isOpenRight)
|
||||
{
|
||||
return icons[3];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return icons[0];
|
||||
}
|
||||
|
||||
public boolean shouldConnectToBlock (IBlockAccess blockAccess, int x, int y, int z, Block block, int meta)
|
||||
{
|
||||
return block == (Block) this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package techreborn.client.texture;
|
||||
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class ConnectedTexture {
|
||||
|
||||
private boolean up, down, left, right;
|
||||
|
||||
|
||||
public ConnectedTexture(boolean up, boolean down, boolean left, boolean right) {
|
||||
this.up = up;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public boolean isUp() {
|
||||
return up;
|
||||
}
|
||||
|
||||
public void setUp(boolean up) {
|
||||
this.up = up;
|
||||
}
|
||||
|
||||
public boolean isDown() {
|
||||
return down;
|
||||
}
|
||||
|
||||
public void setDown(boolean down) {
|
||||
this.down = down;
|
||||
}
|
||||
|
||||
public boolean isLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setLeft(boolean left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public boolean isRight() {
|
||||
return right;
|
||||
}
|
||||
|
||||
public void setRight(boolean right) {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,16 +11,17 @@ import techreborn.lib.ModInfo;
|
|||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class ConnectedTextureGenerator extends TextureAtlasSprite {
|
||||
|
||||
public BufferedImage output_image = null;
|
||||
String type;
|
||||
ConnectedTexture connectedTexture;
|
||||
|
||||
public ConnectedTextureGenerator(String name, String type) {
|
||||
public ConnectedTextureGenerator(String name, String type, ConnectedTexture connectedTexture) {
|
||||
super(name);
|
||||
this.type = type;
|
||||
this.connectedTexture = connectedTexture;
|
||||
}
|
||||
|
||||
public static String getDerivedName(String s2) {
|
||||
|
@ -31,38 +32,24 @@ public class ConnectedTextureGenerator extends TextureAtlasSprite {
|
|||
return new ResourceLocation("techreborn", "textures/blocks/machine/casing" + type + ".png");
|
||||
}
|
||||
|
||||
private static int[] createTexture(int w, int[] type_data) {
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
int blue = 0;
|
||||
int alpha = 0;
|
||||
int count = 0;
|
||||
for (int i = 0; i < type_data.length; i++) {
|
||||
int x = (i % w);
|
||||
int y = (i - x) / w;
|
||||
if (y >= 1 || y <= 14 || x >= 1 || x <= 14) {
|
||||
red += getRed(type_data[i]);
|
||||
green += getGreen(type_data[i]);
|
||||
blue += getBlue(type_data[i]);
|
||||
alpha += getAlpha(type_data[i]);
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
red = red / count;
|
||||
green = green / count;
|
||||
blue = blue / count;
|
||||
alpha = alpha / count;
|
||||
|
||||
|
||||
private static int[] createTexture(int w, int[] type_data, int[] edge_data, ConnectedTexture connectedTexture) {
|
||||
int[] new_data = type_data;
|
||||
|
||||
Random generator = new Random();
|
||||
for (int i = 0; i < type_data.length; i += 1) {
|
||||
int x = (i % w);
|
||||
int y = (i - x) / w;
|
||||
|
||||
if (y <= 1 || y >= 14 || x <= 1 || x >= 14) {
|
||||
new_data[i] = makeCol(red + (generator.nextInt(3) - 5), green + (generator.nextInt(3) - 5), blue + 5, alpha);
|
||||
if(getAlpha(edge_data[i]) != 0){
|
||||
if(y <= 1 && connectedTexture.isUp()){
|
||||
new_data[i] = edge_data[i];
|
||||
}
|
||||
if(y >= 14 && connectedTexture.isDown()){
|
||||
new_data[i] = edge_data[i];
|
||||
}
|
||||
if(x <= 1 && connectedTexture.isLeft()){
|
||||
new_data[i] = edge_data[i];
|
||||
}
|
||||
if(x >= 14 && connectedTexture.isRight()){
|
||||
new_data[i] = edge_data[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return new_data;
|
||||
|
@ -97,6 +84,7 @@ public class ConnectedTextureGenerator extends TextureAtlasSprite {
|
|||
public boolean load(IResourceManager manager, ResourceLocation location) {
|
||||
int mp = Minecraft.getMinecraft().gameSettings.mipmapLevels;
|
||||
BufferedImage[] type_image = new BufferedImage[1 + mp];
|
||||
BufferedImage[] edge_image = new BufferedImage[1 + mp];
|
||||
|
||||
AnimationMetadataSection animation = null;
|
||||
|
||||
|
@ -104,6 +92,9 @@ public class ConnectedTextureGenerator extends TextureAtlasSprite {
|
|||
IResource typeResource = manager.getResource(getTypeResource(type));
|
||||
type_image[0] = ImageIO.read(typeResource.getInputStream());
|
||||
animation = (AnimationMetadataSection) typeResource.getMetadata("animation");
|
||||
|
||||
IResource edgeResource = manager.getResource(getTypeResource(type + "_edge"));
|
||||
edge_image[0] = ImageIO.read(edgeResource.getInputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -112,16 +103,17 @@ public class ConnectedTextureGenerator extends TextureAtlasSprite {
|
|||
|
||||
output_image = new BufferedImage(w, h, 2);
|
||||
int[] type_data = new int[w * w];
|
||||
int[] edge_data = new int[w * w];
|
||||
|
||||
for (int y = 0; y < h; y += w) {
|
||||
type_image[0].getRGB(0, y, w, w, type_data, 0, w);
|
||||
int[] new_data = createTexture(w, type_data);
|
||||
edge_image[0].getRGB(0, y, w, w, edge_data, 0, w);
|
||||
int[] new_data = createTexture(w, type_data, edge_data, connectedTexture);
|
||||
output_image.setRGB(0, y, w, w, new_data, 0, w);
|
||||
}
|
||||
|
||||
type_image[0] = output_image;
|
||||
this.loadSprite(type_image, animation, (float) Minecraft.getMinecraft().gameSettings.anisotropicFiltering > 1.0F);
|
||||
System.out.println("Loaded texture!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue