Jump to content

transparent block casting a shadow [solved]


BillTheUnjust

Recommended Posts

I'm working on a mod that has several variations of switchable glass (when the glass has a redstone signal its appearance changes).

 

The first variation is to change from glass to stone when redstone is applied.  Its mostly working but the glass casts a shadow.  I tested skeletons under the glass still burn, and when I switch it on they stop burning (after a few seconds, normal behavior for mobs entering shade).

 

This is my first attempt at a mod, so the code is not clean yet so any and all tips will be helpful.

 

UPDATE: I was able to override the function isBlockSolidOnSide to always return true since my block should be considered solid on all sides.  This allows isOpaqueCube and renderAsNormalBlock to be set to false so that light will pass through them like a normal glass block.

 

 

package Switchable_Glass.common;

import net.minecraft.src.Block;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "BillTheUnjust_Switchable_Glass", name = "switchglass", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Switchable_Glass 
{

public static Block switchglassoff;
@Init
public void load(FMLInitializationEvent event) 
{
	switchglassoff = new Blockswitchglass(250, 49, false).setBlockName("switchglass");
	GameRegistry.registerBlock(switchglassoff);
	LanguageRegistry.addName(switchglassoff, "Switchable Glass");

}
public static Block switchglasson;
{
	switchglasson = new Blockswitchglass(251, 6, true).setBlockName("switchglass (on)");
	GameRegistry.registerBlock(switchglasson);
	LanguageRegistry.addName(switchglasson, "Switchable Glass (on)");

}

}

 

 

package Switchable_Glass.common;

import java.util.Random;

import net.minecraft.src.BlockBreakable;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.IBlockAccess;
import net.minecraft.src.Material;
import net.minecraft.src.World;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;

public class Blockswitchglass extends BlockBreakable
{
/** Whether this switchable glass block is the powered version. */
    private final boolean powered;
    
public Blockswitchglass(int id, int texture, boolean powered)
{

	super(id, texture, Material.ground, powered);
	this.setCreativeTab(CreativeTabs.tabRedstone);
	this.powered = powered;
	if (!powered)
	{
		this.setLightOpacity(0);
		//this.
	}else
		{
			this.setLightOpacity(15);
		}
	setHardness(0.5F);
	setResistance(5.0f);
	setStepSound(soundGlassFootstep);
}




/**
     * Called whenever the block is added into the world. Args: world, x, y, z
     */
    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        if (!par1World.isRemote)
        {
            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 4);
            }
            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlockWithNotify(par2, par3, par4, Switchable_Glass.switchglasson.blockID);
            }
        }
    }

    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor blockID
     */
    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
    {
        if (!par1World.isRemote)
        {
            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, 4);
            }
            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlockWithNotify(par2, par3, par4, Switchable_Glass.switchglasson.blockID);
            }
        }
    }

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (!par1World.isRemote && this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
        {
            par1World.setBlockWithNotify(par2, par3, par4, Switchable_Glass.switchglassoff.blockID);
        }
    }

    /**
     * Returns the ID of the items to drop on destruction.
     */
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Switchable_Glass.switchglassoff.blockID;
    }
    /**
     * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha
     */
    public int getRenderBlockPass()
    {
        return 1;
    }

    @SideOnly(Side.CLIENT)

    /**
     * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
     */
    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        return Switchable_Glass.switchglassoff.blockID;
    }
}

 

Link to comment
Share on other sites

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.