Powering Blocks With Redstone Help!!!

Discussion in 'Plugin Development' started by hammale, Aug 21, 2011.

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

    hammale

    Hi guys, im a plugin n00b but i decided to give it a try. Through all of my Google searches I have been unable to figure out how to make a block react to red stone current! To be more specific, when a sponge is touched by an ACTIVATED red stone wire i want it to do something...any help is appreciated. THANKS IN ADVANCE!​
     
  2. Offline

    sddddgjd

    I never worked with redstone,but i THINK you can check onRedstoneChange,or something similar,on all the adjacent(did i spell this right?) blocks around it!
     
  3. Offline

    hammale

    but onRedstoneChange only works with blocks that normally react to redstone right?
     
  4. Offline

    Crash

    No it should work with your sponge too.
     
  5. Offline

    hammale

    OK well heres what i have so far...unfortunately every block i power returns "Sponge Not Powered" even the sponges :( im still new to plugins so most of this code i just got from Google searches...

    redfireBlockListiner
    redfire
     
  6. Offline

    Crash

    Don't use isPowered or isIndirectlyPowered inside the blockredstone event it doesn't work.
    You want event.getNewCurrent() to check the power
     
  7. Offline

    hammale

    I changed the code to this:

    redfireBlockListener
    And it kinda worked. When I powered a dirt and a netherrack block it returned "SPONGE NOT POWERED" for both but when i powered a sponge it returned nothing. When I unpowered the sponge it did report "SPONGE NOT POWERED". It seems like this line:
    isnt working correctly...am i missing something simple?
     
  8. Offline

    DeadlyScone

    So basically
    Code:
    if (event.getNewCurrent() > event.getOldCurrent()) {
    returns the blocks that are powered. in this case i'am guessing you are using a lever or something, it will return when you give power to the lever which then if redstone is attached to it it will give power to the redstone or/then power to blocks that can receive power like pistons. that is why
    Code:
    if ((block.getType() == Material.SPONGE)){
    is not working because sponge can't be powered.
     
  9. Offline

    hammale

    o thanks, i decided to go another route so i wrote some new code...but thanks anyway
     
  10. Offline

    DeadlyScone

    Did you get it working? if so.. i have been looking for this type of code also. i dont suppose you would be nice enough to share it with me :D
     
  11. Offline

    hammale

    Well I made it so when you power a sign that says <FIREWORK> on the first line it makes a firework, heres the code for that if you want it:

    Redfire
    Code:
    package me.hammale.redfire;
    import me.hammale.redfire.RedFireBlockListener;
    import java.util.Random;
    import java.util.logging.Logger;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    public class redfire extends JavaPlugin
    {
        Random rand = new Random();
        double speed = 1.5d;
        double angle = 3.0d;
        int time = 35;
        int item = 259;
        int radius;
        public boolean UsePermissions;
      boolean oldstyle;
      Logger log = Logger.getLogger("Minecraft");
      private final RedFireBlockListener blockListener = new NetherFireBlockListener(this);
      public void onEnable()
      {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.REDSTONE_CHANGE, this.blockListener, Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal, this);
            System.out.println("REDFIRE is enabled!");
      }
    public void onDisable() {
        System.out.println("REDFIRE disabled!!");
    }}
    RedFireBlockListener
    Code:
    package me.hammale.redfire;
    
    import java.util.ArrayList;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.Sign;
    import org.bukkit.entity.TNTPrimed;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.event.block.BlockRedstoneEvent;
    import org.bukkit.util.Vector;
    
    public class RedFireBlockListener extends BlockListener
    {
      private final redfire plugin;
      ArrayList<Block> allowedBlocks = new ArrayList<Block>();
    
      public RedFireBlockListener(redfire plugin)
      {
        this.plugin = plugin;
      }
      public void onBlockRedstoneChange(BlockRedstoneEvent event)
      {
          // Get the block that was changed by the current
          Block checkBlock = event.getBlock();
    
          // Check if it's a sign
          if ((checkBlock.getType() == Material.SIGN_POST) || (checkBlock.getType() == Material.WALL_SIGN))
          {
              if (event.getNewCurrent() > 0)
              {
                    Sign s = (Sign)event.getBlock().getState();
                    if (("<FIREWORK>").equals(s.getLine(0))){
    //ITS POWERED, PUT SOMETHING USEFUL HERE!!!
                    }
                    else{
                    }
              }
              else if (event.getNewCurrent() == 0)
              {
              }
          }}}

     
  12. Offline

    DeadlyScone

    nice, ill have to check it out when i get some time... thanks a bunch!
     
  13. Offline

    hammale

    No prob :) ill release redfire soon...
     
Thread Status:
Not open for further replies.

Share This Page