Jump to content

Recommended Posts

Posted

Hey guys,

 

Having some issues with a block I'm trying to make.

Basically, what it should do is pass on a redstone signal that it receives, in any direction. I don't mind if it refreshes the current or anything, that doesn't really matter. So, in a simple term what I need is "if block is receiving power, emit power".

I can't understand why, but I'm having quite a bit of trouble with doing this, so I was hoping someone could help me. I've tried numerous ways, gave up on it for a while but now I'm determined to make it work!

 

The first issue I'm having, is that if I stack the blocks, when I remove the current source, it doesn't turn off the block.

 

I place the block, wire each side. It's off, this is good.

51f1234473e2a.jpg

 

I place a redstone torch on one side. Both wires get power, so the block is passing on current as it should. This is also good.

51f1235116541.jpg

 

If I remove the torch now, the current will turn off, which is good.

However, if I place a second pole on top of the block, like so (as this is part of their plan)

51f1240a50d1c.jpg

 

Then, when I remove the torch, the redstone stays on.

51f124126a557.jpg

 

 

How can I set it so when the power source is removed, all the vertical poles are disabled? It's probably something pretty simple but I can't figure it out. Here is my class:

 

package co.uk.silvania.roads.block;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

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.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Direction;
import net.minecraft.util.ReportedException;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;

public class PowerPoleMedium extends Block {
    private final boolean powered;
    public static int powerValue;

public PowerPoleMedium(int id, boolean par2) {
	super(id, Material.iron);
	this.powered = par2;
	this.setCreativeTab(Roads.tabRoads);
        this.setBlockBounds(0.45F, 0.0F, 0.45F, 0.55F, 1.0F, 0.55F);
    }

public int getRenderType() {
    	return 0;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }
    
public boolean renderAsNormalBlock() {
	return false;
}

    public int isProvidingWeakPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
    	if (this.powered) {
    		return 15;
    	}
      	return 0;
    }
    
    public boolean canProvidePower() {
   		return true;
    }
    
    
    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        if (!par1World.isRemote)
        {
            if (this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlock(par2, par3, par4, Roads.powerPole.blockID, 0, 2);
            }
            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlock(par2, par3, par4, Roads.powerPoleOn.blockID, 0, 2);
            }
        }
    }

    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.setBlock(par2, par3, par4, Roads.powerPole.blockID, 0, 2);
            }
            else if (!this.powered && par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
            {
                par1World.setBlock(par2, par3, par4, Roads.powerPoleOn.blockID, 0, 2);
            }
        }
    }

    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (!par1World.isRemote && this.powered && !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
        {
            par1World.setBlock(par2, par3, par4, Roads.powerPole.blockID, 0, 2);
        }
    }

    public void registerIcons(IconRegister iconRegister) {
    	blockIcon = iconRegister.registerIcon("Roads:PowerPole");
    }
}

Right now I'm just using two blocks; "on" and "off". Is that the best approach?

 

(Also, if you know a better way of doing this i'm all ears. All the pole needs to do is emit redstone in all directions when powered, and stop emitting when power is removed. I've got it working only horizontally and only vertically before, but never all 6 directions.)

width=463 height=200

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

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Probably the poles are providing power to each other in an infinite loop...

I think you should "notifyBlockOfNeighbourChange(args)" in your onBlockAdded and onNeighborBlockChange, that should eventually get rid of the issue.

Posted

you don't need to create two blocks for this; i'm pretty sure this would work already:

 

    public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side)
    {
        return world.isBlockProvidingPowerTo(x, y + 1, z, whateverthecorrectvalueforthesideis) || world.isBlockProvidingPowerTo(x, y - 1, z, whateverthecorrectvalueforthesideis) || checkanotherside || checkanotherside || blablablab;
    }

 

regarding the not shutting off thing, your poles are powering each other up most likely. and i don't think what gotolink suggested will work. not sure, but give it a try though. if it doesn't, then you're probably gonna need more checks like "is this pole getting powered?" then "if it is, is it getting powered by something that isn't being powered by this pole?"

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.