Make a normal block act as a redstone current source

Discussion in 'Plugin Development' started by 2rockon, Jan 23, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    2rockon

    I am currently developing a plugin, and in order for it to work I need a method to make a normal block (glass) give of redstone current. I have managed to do it by checking for redstone wire next to the block and setting its data to 15, but whenever I place another piece of wire next to that piece it resets the current. I could probably do it by checking if a wire it placed next to the powered wire, and setting it again on the first wire, but this would be a bit hacky and I have multiple glass blocks to check so it would get quite messy.

    Has anyone got any other ideas on how I can do this?

    2rockon
     
  2. Offline

    Snowl

    From
    http://forums.bukkit.org/threads/redstone-for-non-redstone-implementors.1523/#post-19734
    Code:
    /**
         ** Returns true if the block at the given x, y, z coordinates is indirectly powered
         ** @param x coordinate
         ** @param y coordinate
         ** @param z coordinate
         **/
        public static boolean isBlockIndirectlyPowered(int x, int y, int z) {
            return isBlockPowered(x+1, y, z) || isBlockPowered(x-1, y, z) || isBlockPowered(x, y, z+1) || isBlockPowered(x, y, z-1) || isBlockPowered(x, y-1, z);
        }
        /**
         ** Returns true if the block at the given x, y, z coordinates is directly powered
         ** @param x coordinate
         ** @param y coordinate
         ** @param z coordinate
         **/
        public static boolean isBlockPowered(int x, int y, int z) {
            MaterialData md = getWorld().getBlockAt(x, y, z).getState().getData();
            if (md instanceof Redstone) {
                return ((Redstone) md).isPowered();
            }
            return false;
        }
    but make it always "return ((Redstone) md).isPowered();" instead of false.
    I think. i'm probably wrong :p
     
  3. Offline

    2rockon

    Nice try but what I need is the opposite of this. I don't want a block to detect power going in to it, I need a block to act as a power source (it gives of power). I may not have worded my question very well.

    2rockon
     
  4. Offline

    Snowl

    Code:
        public static boolean isBlockPowered(int x, int y, int z) {
            MaterialData md = getWorld().getBlockAt(x, y, z).getState().getData();
                return ((Redstone) md).isPowered();
        }
    then isBlockPowered
    and it should power the block, making it a power source. Unless i'm just being stupid :p

    Of course, i'm being stupid. Ignore me -.-
     
Thread Status:
Not open for further replies.

Share This Page