Jump to content

Recommended Posts

Posted

light class

package a.Screens;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class Light extends Block {

 

public Light(int par1, Material par2Material) {

super(par1, par2Material);

 

this.setCreativeTab(CreativeTabs.tabBlock);

this.setHardness(10.0F);

this.setResistance(10.0F);

this.setLightValue(15.0F);}}

 

 

 

Posted

This is both really easy to do and really difficult, due to edge cases and weirdness the player can do if you're not careful.  Namely if someone places this light block on top of another one.

 

Here's some code I have that will steal the texture for the next not-this block in an orthogonal direction (that is, it looks for a not itself block in a direction until it hits air, if it finds air it tries another direction, if it fails it uses grass).

 

Its not the greatest code, but it works.

 

	public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side)
    {
//int mymeta = world.getBlockMetadata(x, y, z);
//if(mymeta == 0) {
int[] id = {world.getBlockId(x, y-1, z),world.getBlockId(x-1, y, z),world.getBlockId(x+1, y, z),world.getBlockId(x, y, z-1),world.getBlockId(x, y, z+1),world.getBlockId(x, y+1, z)};
int[] meta = {world.getBlockMetadata(x, y-1, z),world.getBlockMetadata(x-1, y, z),world.getBlockMetadata(x+1, y, z),world.getBlockMetadata(x, y, z-1),world.getBlockMetadata(x, y, z+1),world.getBlockMetadata(x, y+1, z)};
//.get.getBlockTextureFromSideAndMetadata(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4));
for(int i = 0; i < id.length; i++) {
Block block = Block.blocksList[id[i]];
if(block != null) {
if(block != this && block.isOpaqueCube()) {
Icon icon = block.getIcon(side, meta[i]);
if(icon != null) {
return icon;
}
}
else if(block == this) {
Icon icon = Block.grass.getBlockTextureFromSide(1);
switch(i) {
case 0:
icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y-1, z, side, 0);
break;
case 1:
icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x-1, y, z, side, 2);
break;
case 2:
icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x+1, y, z, side, 3);
break;
case 3:
icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z-1, side, 4);
break;
case 4:
icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z+1, side, 5);
break;
case 5:
icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y+1, z, side, 1);
break;
}
if(icon != null && icon != Block.grass.getBlockTextureFromSide(1)) {
return icon;
}
}
}
}
return Block.grass.getBlockTextureFromSide(1);
/*}
else {
return blockIcon;
}*/
    }

public Icon getBlockTextureDirectional(IBlockAccess world, int x, int y, int z, int side, int direction) {

int id = world.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
Block block = Block.blocksList[id];
if(block != null) {
if(block != this) {
Icon icon = block.getIcon(side, meta);
         if(icon != null) {
         return icon;
         }
}
else {
Icon icon = Block.grass.getBlockTextureFromSide(1);
     switch(direction) {
     case 0:
         icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y-1, z, side, 0);
         break;
     case 1:
         icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y+1, z, side, 1);
         break;
     case 2:
         icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x-1, y, z, side, 2);
         break;
     case 3:
         icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x+1, y, z, side, 3);
         break;
     case 4:
         icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z-1, side, 4);
         break;
     case 5:
         icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z+1, side, 5);
         break;
     }
     return icon;
}
}
return Block.grass.getBlockTextureFromSide(1);
}

 

The cast to BlockIllusionary will need to be replaced with a cast to your block type.

(Bad intenting due to copy/paste from github, original here: https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/block/BlockIllusionary.java )

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

ok the block now captures the other textures, but it won't give out light still and the other mod blocks have washed out colours and are partly transparent. but when a menu/command/chat is open the texture is normal.

 

 

RSemVin.png

 

 

Bqxf3wD.png

 

 

Light Class

 

 

package a.Screens;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.Icon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.common.ForgeDirection;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class Light extends Block {

public static Block instance;

public int renderType = 0;

 

public Light(int par1, Material air) {

super(par1, Material.rock);

setUnlocalizedName("Light");

setResistance(2F);

setStepSound(soundStoneFootstep);

setHardness(0.5F);

        this.setCreativeTab(CreativeTabs.tabBlock);

}

 

@Override

    public void registerIcons(IconRegister iconRegister)

    {

        blockIcon = iconRegister.registerIcon("oomod:Light");

    }

 

@Override

public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side)

    {

return true;

    }

 

public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side)

    {

//int mymeta = world.getBlockMetadata(x, y, z);

//if(mymeta == 0) {

int[] id = {world.getBlockId(x, y-1, z),world.getBlockId(x-1, y, z),world.getBlockId(x+1, y, z),world.getBlockId(x, y, z-1),world.getBlockId(x, y, z+1),world.getBlockId(x, y+1, z)};

int[] meta = {world.getBlockMetadata(x, y-1, z),world.getBlockMetadata(x-1, y, z),world.getBlockMetadata(x+1, y, z),world.getBlockMetadata(x, y, z-1),world.getBlockMetadata(x, y, z+1),world.getBlockMetadata(x, y+1, z)};

//.get.getBlockTextureFromSideAndMetadata(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4));

for(int i = 0; i < id.length; i++) {

Block block = Block.blocksList[id];

if(block != null) {

if(block != this && block.isOpaqueCube()) {

Icon icon = block.getIcon(side, meta);

if(icon != null) {

return icon;

}

}

else if(block == this) {

Icon icon = Block.grass.getBlockTextureFromSide(1);

switch(i) {

case 0:

icon = ((Light)block).getBlockTextureDirectional(world, x, y-1, z, side, 0);

break;

case 1:

icon = ((Light)block).getBlockTextureDirectional(world, x-1, y, z, side, 2);

break;

case 2:

icon = ((Light)block).getBlockTextureDirectional(world, x+1, y, z, side, 3);

break;

case 3:

icon = ((Light)block).getBlockTextureDirectional(world, x, y, z-1, side, 4);

break;

case 4:

icon = ((Light)block).getBlockTextureDirectional(world, x, y, z+1, side, 5);

break;

case 5:

icon = ((Light)block).getBlockTextureDirectional(world, x, y+1, z, side, 1);

break;

}

if(icon != null && icon != Block.grass.getBlockTextureFromSide(1)) {

return icon;

}

}

}

}

return Block.grass.getBlockTextureFromSide(1);

/*}

else {

return blockIcon;

}*/

    }

 

public Icon getBlockTextureDirectional(IBlockAccess world, int x, int y, int z, int side, int direction) {

 

int id = world.getBlockId(x, y, z);

int meta = world.getBlockMetadata(x, y, z);

Block block = Block.blocksList[id];

if(block != null) {

if(block != this) {

Icon icon = block.getIcon(side, meta);

        if(icon != null) {

        return icon;

        }

}

else {

Icon icon = Block.grass.getBlockTextureFromSide(1);

    switch(direction) {

    case 0:

        icon = ((Light)block).getBlockTextureDirectional(world, x, y-1, z, side, 0);

        break;

    case 1:

        icon = ((Light)block).getBlockTextureDirectional(world, x, y+1, z, side, 1);

        break;

    case 2:

        icon = ((Light)block).getBlockTextureDirectional(world, x-1, y, z, side, 2);

        break;

    case 3:

        icon = ((Light)block).getBlockTextureDirectional(world, x+1, y, z, side, 3);

        break;

    case 4:

        icon = ((Light)block).getBlockTextureDirectional(world, x, y, z-1, side, 4);

        break;

    case 5:

        icon = ((Light)block).getBlockTextureDirectional(world, x, y, z+1, side, 5);

        break;

    }

    return icon;

}

}

return Block.grass.getBlockTextureFromSide(1);

}

 

public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)

    {

return null;

    }

 

public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {

this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);

}

 

public boolean isOpaqueCube()

    {

        return false;

    }

 

public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)

    {

        return false;

    }

 

/**

* Returns which pass should this block be rendered on. 0 for solids and 1 for alpha

*/

    public int getRenderBlockPass()

    {

        return 1;

    }

   

    public boolean renderAsNormalBlock()

    {

        return false;

    }

   

    @Override

    public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side)

    {

    if(world.getBlockId(x, y, z) == blockID || world.isBlockOpaqueCube(x, y, z))

    return false;

        return true;

    }

   

    @Override

    public int getRenderType() {

    return renderType;

    }

 

@Override

public int quantityDropped(Random par1Random)

    {

        return 0;

    }

}

 

 

 

 

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.