So i am trying to make a rain detector in the same sense of a daylight detector and output a redstone signal depending if it is raining or not. I can't successfully detect if it is raining and before it was working I wasn't able to update the redstone signal until my block gets a block update. How would I make it update automatically?
package com.RainChecker.mod.blocks;
import java.util.Random;
import com.RainChecker.mod.BaseClass;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityDaylightDetector;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class RainDetector extends BaseBlock {
@SideOnly(Side.CLIENT)
private IIcon iconSide;
@SideOnly(Side.CLIENT)
private IIcon iconBottom;
private int redstoneOut = 0;
public RainDetector()
{
super();
this.setHardness(.3F);
this.setResistance(.5F);
this.setStepSound(soundTypeStone);
this.setHarvestLevel("pickaxe", 1);
this.setBlockName("RainDetector");
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.375F, 1.0F);
}
//speed
/* public int tickRate(World world)
{
return 1;
}*/
public void setBlockBoundsBasedOnState(IBlockAccess IBlockAccess, int x, int y, int z)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.375F, 1.0F);
}
public void updateTick(World world, int x, int y, int z, Random rand) {
if(world.canLightningStrikeAt(x, y, z)){
redstoneOut = 15;
}else if(!world.canLightningStrikeAt(x, y, z)){
redstoneOut = 0;
}
}
public int isProvidingWeakPower(IBlockAccess IBlockAccess, int x, int y, int z, int io)
{
return redstoneOut;
}
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighborBlock) {
updateTick(world, x, y, z, null);
}
public void onBlockAdded(World world, int x, int y, int z) {
world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));
}
public void func_149957_e(World world, int x, int y, int z)
{
updateTick(world, x, y, z, null);
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean canProvidePower()
{
return true;
}
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
{
return new TileEntityRainDetector();
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int i, int j)
{// top bottom SIDE
return i == 1 ? this.blockIcon : (i == 0 ? this.iconBottom : this.iconSide);
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
String name = String.format("%s", getUnwrappedUnlocalizedName(this.getUnlocalizedName()));
blockIcon = iconRegister.registerIcon(name+ "_Top1");
iconSide = iconRegister.registerIcon(name + "_Side");
iconBottom = iconRegister.registerIcon(name + "_Bottom");
//iconTopFullcooked = iconRegister.registerIcon(Reference.MODID.toLowerCase() + ":dryerFullDry");
}
}
Now the block actually outputs a redstone level but does not output automatically (still requires a block update).
Edit: I've made the block change its texture and will change its texture successfully based on the internal redstoneOut value but does not actually change the redstone output ingame. How would I call the "public int isProvidingWeakPower" ?
Now the block actually outputs a redstone level but does not output automatically (still requires a block update).Edit: I've made the block change its texture and will change its texture successfully based on the internal redstoneOut value but does not actually change the redstone output ingame. How would I call the "public int isProvidingWeakPower" ?