Jump to content

Recommended Posts

Posted

Hey guys,

 

I have two different questions regarding the use of Redstone.

 

 

1.

I'm making a set of blocks which work just like redstone wire, but it's a physical block that can be placed anywhere. It's all worked except one thing; the redstone wont transmit vertically. Anyone know how I might achieve that? Here's the block's class file:

 

package co.uk.silvania.roads.block;

import java.util.List;
import java.util.Random;

import co.uk.silvania.roads.Roads;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Direction;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class PowerPoleBlock extends BlockRedstoneWire {

private Material material;

public PowerPoleBlock(int id) {
	super(id);
	this.setCreativeTab(Roads.tabRoads);
        //this.setBlockBounds(0.4F, 0.0F, 0.4F, 0.6F, 1.0F, 0.6F);
}

    public void registerIcons(IconRegister iconRegister) {
        blockIcon = iconRegister.registerIcon("Roads:CementBlock");
    }
    
    @Override
    public int getRenderType()
    {
        return 0;
    }
    
    public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
    {
        return AxisAlignedBB.getAABBPool().getAABB((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)par3 + this.maxY, (double)par4 + this.maxZ);
    }
    
    @Override
    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) {
    	this.setBlockBounds(0.4F, 0.0F, 0.4F, 0.6F, 1.0F, 0.6F);
    	super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
    }
    @Override
    public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
    {
	return true;
    }
    
    @Override
    public int idDropped(int par1, Random par2Random, int par3)
    {
        return Roads.powerPole.blockID;
    }
    
    public static boolean isPowerProviderOrWire(IBlockAccess par0IBlockAccess, int par1, int par2, int par3, int par4)
    {
        int i1 = par0IBlockAccess.getBlockId(par1, par2, par3);

        if (i1 == Roads.powerPole.blockID)
        {
            return true;
        }
        else if (i1 == 0)
        {
            return false;
        }
        else
        {
            int j1 = par0IBlockAccess.getBlockMetadata(par1, par2, par3);
            return par4 == (j1 & 3) || par4 == Direction.rotateOpposite[j1 & 3];
        }
    }

    
    @Override
    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
    	//Remove here to end of constructor - Only kept in for testing to see when the current is active.
        int l = par1World.getBlockMetadata(par2, par3, par4);

        if (l > 0)
        {
            double d0 = (double)par2 + 0.5D + ((double)par5Random.nextFloat() - 0.5D) * 0.2D;
            double d1 = (double)((float)par3 + 0.0625F);
            double d2 = (double)par4 + 0.5D + ((double)par5Random.nextFloat() - 0.5D) * 0.2D;
            float f = (float)l / 15.0F;
            float f1 = f * 0.6F + 0.4F;

            if (l == 0)
            {
                f1 = 0.0F;
            }

            float f2 = f * f * 0.7F - 0.5F;
            float f3 = f * f * 0.6F - 0.7F;

            if (f2 < 0.0F)
            {
                f2 = 0.0F;
            }

            if (f3 < 0.0F)
            {
                f3 = 0.0F;
            }

            par1World.spawnParticle("reddust", d0, d1, d2, (double)f1, (double)f2, (double)f3);
        }
    }
    
    public int idPicked(World par1World, int par2, int par3, int par4)
    {
        return Roads.powerPole.blockID;
    }

}

 

 

2.

Is it possible to change the texture of a tile entity, using redstone? Here's my Renderer class, the if function takes no effect right now so what do I need to change?

 

package co.uk.silvania.roads.tileentities;

import org.lwjgl.opengl.GL11;


import co.uk.silvania.roads.Roads;
import co.uk.silvania.roads.client.TrafficLightModel;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;


public class TileEntityTrafficLightRenderer extends TileEntitySpecialRenderer {

private final TrafficLightModel model;

    private final boolean powered;

public TileEntityTrafficLightRenderer(boolean par2) {
	this.model = new TrafficLightModel();
    this.powered = par2;
}

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
	GL11.glPushMatrix();
	GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
	if (this.powered) {
		bindTextureByName("/mods/roads/textures/blocks/TrafficLightPoleGreen.png");
	} else {
		bindTextureByName("/mods/roads/textures/blocks/TrafficLightPoleRed.png");			
	}
	GL11.glPushMatrix();
	GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
	this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
	GL11.glPopMatrix();
	GL11.glPopMatrix();
}

private void adjustRotatePivotViaMeta(World world, int x, int y, int z) {
	int meta = world.getBlockMetadata(x, y, z);
	GL11.glPushMatrix();
	GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
	GL11.glPopMatrix();
}

private void adjustLightFixture(World world, int i, int j, int k, Block block) {
	Tessellator tess = Tessellator.instance;
	float brightness = block.getBlockBrightness(world, i, j, k);
	int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
	int modulousModifier = skyLight % 65536;
	int divModifier = skyLight / 65536;
	tess.setColorOpaque_F(brightness, brightness, brightness);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
}
}

 

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

1) I did it once.  It was a bitch.  I'll dig up my code.  I will note, however, that it only went up not down.  I do have another block that could take input signals from redstone and "do stuff" by propagating the signal, but it didn't turn off instantly (also redstone didn't see it as transmitting power).

 

2) Yes.  Just set up the block to have an isPowered function determine if it is powered, then send that flag into the TE.  I did something similar with my spikes, only it was based on having hurt an entity.

 

Edit:

Redstone fence (upward redstone signal transmission)

Note: this block was intended to ONLY take a signal from a solid block or itself from below itself.  It was not meant for any kind of horizontal transmission.

 

package draco18s.redstone;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Direction;
import net.minecraft.util.Icon;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class RedstoneFencing extends BlockFence {

private final String field_94464_a;
/** Whether the redstone torch is currently active or not. */
    private boolean wiresProvidePower = true;
    protected Icon textureOn;

    /** Map of ArrayLists of RedstoneUpdateInfo. Key of map is World. */
    private static Map redstoneUpdateInfoCache = new HashMap();
    private Set blocksNeedingUpdate = new HashSet();

public RedstoneFencing(int par1, String par2Str, Material par2Material) {
	super(par1, par2Str, par2Material);
	this.field_94464_a = par2Str;
        this.setCreativeTab(CreativeTabs.tabDecorations);
}

/**
     * Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if they intersect the
     * mask.) Parameters: World, X, Y, Z, mask, list, colliding entity
     */
    public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
    {
        boolean flag = this.canConnectFenceTo(par1World, par2, par3, par4 - 1);
        boolean flag1 = this.canConnectFenceTo(par1World, par2, par3, par4 + 1);
        boolean flag2 = this.canConnectFenceTo(par1World, par2 - 1, par3, par4);
        boolean flag3 = this.canConnectFenceTo(par1World, par2 + 1, par3, par4);
        float f = 0.375F;
        float f1 = 0.625F;
        float f2 = 0.375F;
        float f3 = 0.625F;

        if (flag)
        {
            f2 = 0.0F;
        }

        if (flag1)
        {
            f3 = 1.0F;
        }

        if (flag || flag1)
        {
            this.setBlockBounds(f, 0.0F, f2, f1, 1.5F, f3);
            super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        }

        f2 = 0.375F;
        f3 = 0.625F;

        if (flag2)
        {
            f = 0.0F;
        }

        if (flag3)
        {
            f1 = 1.0F;
        }

        if (flag2 || flag3 || !flag && !flag1)
        {
            this.setBlockBounds(f, 0.0F, f2, f1, 1.5F, f3);
            super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
        }

        if (flag)
        {
            f2 = 0.0F;
        }

        if (flag1)
        {
            f3 = 1.0F;
        }

        this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
    }

    /**
     * Updates the blocks bounds based on its current state. Args: world, x, y, z
     */
    public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        boolean flag = this.canConnectFenceTo(par1IBlockAccess, par2, par3, par4 - 1);
        boolean flag1 = this.canConnectFenceTo(par1IBlockAccess, par2, par3, par4 + 1);
        boolean flag2 = this.canConnectFenceTo(par1IBlockAccess, par2 - 1, par3, par4);
        boolean flag3 = this.canConnectFenceTo(par1IBlockAccess, par2 + 1, par3, par4);
        float f = 0.375F;
        float f1 = 0.625F;
        float f2 = 0.375F;
        float f3 = 0.625F;

        if (flag)
        {
            f2 = 0.0F;
        }

        if (flag1)
        {
            f3 = 1.0F;
        }

        if (flag2)
        {
            f = 0.0F;
        }

        if (flag3)
        {
            f1 = 1.0F;
        }

        this.setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
    }

    /**
     * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
     * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
     */
    public boolean isOpaqueCube()
    {
        return false;
    }

    /**
     * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
     */
    public boolean renderAsNormalBlock()
    {
        return false;
    }

    public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        return false;
    }

    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 11;
    }

    /**
     * Returns true if the specified block can be connected by a fence
     */
    public boolean canConnectFenceTo(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
        int l = par1IBlockAccess.getBlockId(par2, par3, par4);

        if (l != this.blockID && l != Block.fenceGate.blockID)
        {
            Block block = Block.blocksList[l];
            return block != null && block.blockMaterial.isOpaque() && block.renderAsNormalBlock() ? block.blockMaterial != Material.pumpkin : false;
        }
        else
        {
            return true;
        }
    }

    public static boolean isIdAFence(int par0)
    {
        return par0 == Block.fence.blockID || par0 == Block.netherFence.blockID;
    }

    @SideOnly(Side.CLIENT)

    /**
     * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
     * coordinates.  Args: blockAccess, x, y, z, side
     */
    public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        return true;
    }

    @SideOnly(Side.CLIENT)
    public void func_94332_a(IconRegister iconRegister)
    {
        //this.field_94336_cN = par1IconRegister.func_94245_a(this.field_94464_a);
        //this.textureOn = par1IconRegister.func_94245_a("Redstone:rsfence-on");
        blockIcon = iconRegister.registerIcon("Redstone:rsfence");
        textureOn = iconRegister.registerIcon("Redstone:rsfence-on");
    }
    
    public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
    {
    	if(par2 == 0)
    		return this.blockIcon;
    	else
    		return this.textureOn;
    }
    
    public int tickRate(World par1World)
    {
        return 2;
    }
    
    /**
     * Returns true if the block is emitting direct/strong redstone power on the specified side. Args: World, X, Y, Z,
     * side. Note that the side is reversed - eg it is 1 (up) when checking the bottom of the block.
     */
    public int isProvidingStrongPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
        return !this.wiresProvidePower ? 0 : this.isProvidingWeakPower(par1IBlockAccess, par2, par3, par4, par5);
    }
    
    /**
     * Returns true if the block is emitting indirect/weak redstone power on the specified side. If isBlockNormalCube
     * returns true, standard redstone propagation rules will apply instead and this will not be called. Args: World, X,
     * Y, Z, side. Note that the side is reversed - eg it is 1 (up) when checking the bottom of the block.
     */
    public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int x, int y, int z, int side)
    {
    	//System.out.println("Checking providing weak power");
    	if (!this.wiresProvidePower || side != 0)
        {
    		System.out.println("Side !0| " + x + "," + y + "," + z + ";" + side);
            return 0;
        }
        else
        {
        	int i1 = par1IBlockAccess.getBlockMetadata(x, y, z);
        	System.out.println(x + "," + y + "," + z);
        	System.out.println("i1: " + i1);
        	//System.out.println("si: " + side);
            if (i1 == 0)
            {
                return 0;
            }
            else
            {
            	boolean flag = isPoweredOrRepeater(par1IBlockAccess, x, y-1, z, -1);
          		boolean flag2 = par1IBlockAccess.isBlockNormalCube(x, y - 1, z);
          		System.out.println("flag 1: " + flag);
          		System.out.println("flag 2: " + flag2);
                if(!flag)
                	return i1;
                else
                	return 0;
            }
        }
    }

    private boolean isPoweredOrRepeater(IBlockAccess par1iBlockAccess, int x, int y, int z, int side) {
    	if (isPowerProviderOrWire(par1iBlockAccess, x, y, z, side))
        {
    		System.out.println("side: " + side);
            return true;
        }
	return false;
}
    
    public static boolean isPowerProviderOrWire(IBlockAccess par0IBlockAccess, int par1, int par2, int par3, int par4)
    {
        int i1 = par0IBlockAccess.getBlockId(par1, par2, par3);

        if (i1 == Block.redstoneWire.blockID)
        {
            return true;
        }
        else if (i1 == 0)
        {
            return false;
        }
        else if (!Block.redstoneRepeaterIdle.func_94487_f(i1))
        {
            return (Block.blocksList[i1] != null && Block.blocksList[i1].canConnectRedstone(par0IBlockAccess, par1, par2, par3, par4));
        }
        else
        {
            int j1 = par0IBlockAccess.getBlockMetadata(par1, par2, par3);
            return par4 == (j1 & 3) || par4 == Direction.footInvisibleFaceRemap[j1 & 3];
            //return false?
        }
    }

/**
     * Returns true or false based on whether the block the torch is attached to is providing indirect power.
     */
    private boolean isIndirectlyPowered(World par1World, int par2, int par3, int par4)
    {
    	return par1World.isBlockProvidingPowerTo(par2, par3 - 1, par4, 0) > 0;
        //int l = par1World.getBlockMetadata(par2, par3, par4);
        //return l == 5 && par1World.func_94574_k(par2, par3 - 1, par4, 0) ? true : (l == 3 && par1World.func_94574_k(par2, par3, par4 - 1, 2) ? true : (l == 4 && par1World.func_94574_k(par2, par3, par4 + 1, 3) ? true : (l == 1 && par1World.func_94574_k(par2 - 1, par3, par4, 4) ? true : l == 2 && par1World.func_94574_k(par2 + 1, par3, par4, 5))));
    }
    
    /**
     * Sets the strength of the wire current (0-15) for this block based on neighboring blocks and propagates to
     * neighboring redstone wires
     */
    private void updateAndPropagateCurrentStrength(World par1World, int par2, int par3, int par4)
    {
        this.calculateCurrentChanges(par1World, par2, par3, par4, par2, par3, par4);
        ArrayList arraylist = new ArrayList(this.blocksNeedingUpdate);
        this.blocksNeedingUpdate.clear();

        for (int l = 0; l < arraylist.size(); ++l)
        {
            ChunkPosition chunkposition = (ChunkPosition)arraylist.get(l);
            par1World.notifyBlocksOfNeighborChange(chunkposition.x, chunkposition.y, chunkposition.z, this.blockID);
        }
    }

    private void calculateCurrentChanges(World par1World, int par2, int par3, int par4, int par5, int par6, int par7)
    {
        int k1 = par1World.getBlockMetadata(par2, par3, par4);
        byte b0 = 0;
        int l1 = this.getMaxCurrentStrength(par1World, par5, par6, par7, b0);
        this.wiresProvidePower = false;
        int i2 = par1World.getStrongestIndirectPower(par2, par3, par4);
        this.wiresProvidePower = true;

        if (i2 > 0 && i2 > l1 - BaseRedstone.rsDecauVal)
        {
            l1 = i2;
        }

        int j2 = 0;

        j2 = this.getMaxCurrentStrength(par1World, par2, par3 - 1, par4, j2);

        if (j2 > l1)
        {
            l1 = j2 - BaseRedstone.rsDecauVal;
        }
        else if (l1 > BaseRedstone.rsDecauVal)
        {
            l1 -= BaseRedstone.rsDecauVal;
        }
        else
        {
            l1 = 0;
        }

        if (i2 > l1 - BaseRedstone.rsDecauVal)
        {
            l1 = i2;
        }
        if(l1 < 0)
        	l1 = 0;

        if (k1 != l1)
        {
        	//System.out.println("Updating self strenght: " + l1);
            par1World.setBlockMetadataWithNotify(par2, par3, par4, l1, 2);
            this.blocksNeedingUpdate.add(new ChunkPosition(par2, par3, par4));
            this.blocksNeedingUpdate.add(new ChunkPosition(par2, par3 + 1, par4));
        }
    }

    /**
     * Calls World.notifyBlocksOfNeighborChange() for all neighboring blocks, but only if the given block is a redstone
     * wire.
     */
    private void notifyWireNeighborsOfNeighborChange(World par1World, int par2, int par3, int par4)
    {
        if (par1World.getBlockId(par2, par3, par4) == this.blockID)
        {
            par1World.notifyBlocksOfNeighborChange(par2, par3, par4, this.blockID);
            par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + 1, this.blockID);
        }
    }

    /**
     * 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)
    {
        super.onBlockAdded(par1World, par2, par3, par4);

        if (!par1World.isRemote)
        {
            this.updateAndPropagateCurrentStrength(par1World, par2, par3, par4);
            this.notifyWireNeighborsOfNeighborChange(par1World, par2 + 1, par3, par4);
            this.notifyWireNeighborsOfNeighborChange(par1World, par2 - 1, par3, par4);

            /*if (par1World.isBlockNormalCube(par2 - 1, par3, par4))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 - 1, par3 + 1, par4);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 - 1, par3 - 1, par4);
            }

            if (par1World.isBlockNormalCube(par2 + 1, par3, par4))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 + 1, par3 + 1, par4);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 + 1, par3 - 1, par4);
            }

            if (par1World.isBlockNormalCube(par2, par3, par4 - 1))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 + 1, par4 - 1);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 - 1, par4 - 1);
            }

            if (par1World.isBlockNormalCube(par2, par3, par4 + 1))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 + 1, par4 + 1);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 - 1, par4 + 1);
            }*/
        }
    }

    /**
     * ejects contained items into the world, and notifies neighbours of an update, as appropriate
     */
    public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
    {
        super.breakBlock(par1World, par2, par3, par4, par5, par6);

        if (!par1World.isRemote)
        {
            par1World.notifyBlocksOfNeighborChange(par2, par3 + 1, par4, this.blockID);
            par1World.notifyBlocksOfNeighborChange(par2, par3 - 1, par4, this.blockID);
            this.updateAndPropagateCurrentStrength(par1World, par2, par3, par4);

            /*if (par1World.isBlockNormalCube(par2 - 1, par3, par4))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 - 1, par3 + 1, par4);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 - 1, par3 - 1, par4);
            }

            if (par1World.isBlockNormalCube(par2 + 1, par3, par4))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 + 1, par3 + 1, par4);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2 + 1, par3 - 1, par4);
            }

            if (par1World.isBlockNormalCube(par2, par3, par4 - 1))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 + 1, par4 - 1);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 - 1, par4 - 1);
            }

            if (par1World.isBlockNormalCube(par2, par3, par4 + 1))
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 + 1, par4 + 1);
            }
            else
            {
                this.notifyWireNeighborsOfNeighborChange(par1World, par2, par3 - 1, par4 + 1);
            }*/
        }
    }

    /**
     * Returns the current strength at the specified block if it is greater than the passed value, or the passed value
     * otherwise. Signature: (world, x, y, z, strength)
     */
    private int getMaxCurrentStrength(World par1World, int par2, int par3, int par4, int par5)
    {
        if (par1World.getBlockId(par2, par3, par4) != this.blockID)
        {
            return par5;
        }
        else
        {
            int i1 = par1World.getBlockMetadata(par2, par3, par4);
            return i1 > par5 ? i1 : par5;
        }
    }

    /**
     * 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)
        {
        	this.updateAndPropagateCurrentStrength(par1World, par2, par3, par4);

            super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
        }
    }
}

 

 

Redstone phaseblock (propagation of signal in all directions)

Note: it does not have an instant-off and I was unable to figure out why and just left it alone because it was good-enough for my needs.

Base class isn't really relevant here, it was just the core of how the blocks became non-solid by whatever means that they became non-solid by (e.g. something would tweak the metadata value and that would cause it to change texture and lose collision checks).

 

package draco18s.micromods.phaseblocks.blocks;

import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class RSPhaseStone extends PhaseStone {

public RSPhaseStone(int par1, Material par2Material) {
	super(par1, par2Material);
}

public void registerIcons(IconRegister iconRegister)
    {
        blockIcon = iconRegister.registerIcon("Phaseblocks:red-np");
        phasedIcon = iconRegister.registerIcon("Phaseblocks:red-p");
    }

@Override
public void updateTick(World world, int x, int y, int z, Random par5Random)
    {}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockid)
    {
        if (!world.isRemote)
        {
        	int mymeta = world.getBlockMetadata(x, y, z);
            int endMeta = 0;
            int meta;
            boolean var10 = world.isBlockIndirectlyGettingPowered(x, y, z);
            
            if (var10)
            {
            	endMeta = 15;
            }
            else
            {
            	int a = world.getBlockId(x-1, y, z);
                if(a == this.blockID) {
                	meta = world.getBlockMetadata(x-1, y, z);
                	if(endMeta < meta) {
                		endMeta = meta;
                	}
                }
                a = world.getBlockId(x+1, y, z);
                if(a == this.blockID) {
                	meta = world.getBlockMetadata(x+1, y, z);
                	if(endMeta < meta) {
                		endMeta = meta;
                	}
                }
                a = world.getBlockId(x, y, z-1);
                if(a == this.blockID) {
                	meta = world.getBlockMetadata(x, y, z-1);
                	if(endMeta < meta) {
                		endMeta = meta;
                	}
                }
                a = world.getBlockId(x, y, z+1);
                if(a == this.blockID) {
                	meta = world.getBlockMetadata(x, y, z+1);
                	if(endMeta < meta) {
                		endMeta = meta;
                	}
                }
                a = world.getBlockId(x, y-1, z);
                if(a == this.blockID) {
                	meta = world.getBlockMetadata(x, y-1, z);
                	if(endMeta < meta) {
                		endMeta = meta;
                	}
                }
                a = world.getBlockId(x, y+1, z);
                if(a == this.blockID) {
                	meta = world.getBlockMetadata(x, y+1, z);
                	if(endMeta < meta) {
                		endMeta = meta;
                	}
                }
            }
            if(endMeta > 0)
            	endMeta--;

        	world.markBlockForUpdate(x, y, z);
        	world.setBlock(x, y, z, this.blockID, endMeta, 3);
        }
    }

@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){return false;}
}

 

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

thanks :D I think I can combine your code with what I already have to make my block emit in all six directions. If I get it working, do you want the code?

 

Also, a third redstone question. Is it possible to make a block say "If the block beneath me has power, I will do something"?

 

With my traffic lights, I want them to be redstone controlled for their state. But, I don't want the redstone on show, so it'd make sense to check if the block below it is powered.

 

 

EDIT: Also, any chance I can see your "BaseRedstone" class? You have a few references to it, I wanna see what I need to change those to

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

thanks :D I think I can combine your code with what I already have to make my block emit in all six directions. If I get it working, do you want the code?

 

Nah, I'm perfectly happy with what I have and apparently everyone else is too.

 

Also, a third redstone question. Is it possible to make a block say "If the block beneath me has power, I will do something"?

 

On neighbor changed, check the block below for isSupplyingStrongPower (or isSupplyingWeakPower).

 

EDIT: Also, any chance I can see your "BaseRedstone" class? You have a few references to it, I wanna see what I need to change those to

 

Oh, that's just a config option for how far the signal can travel vertically.  Minimum is 1 (signal travels 16 blocks) default is 3 (signal travels 5 blocks).  Just because I felt like the signal shouldn't be as efficient, but left it modifiable by the user.

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.

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.