I'm looking to make a block that will detect rain and output redstone signal when it does. the problem is i dont know how to get my block to check if it is raining or it might be i dont know how to output the redstone signal when it does rain. either way here is my code
package net.minecraft.src;
import java.util.Random;
// Referenced classes of package net.minecraft.src:
// Block, Material, World, IBlockAccess,
// AxisAlignedBB, EntityPlayer
public class DB_BlockRainDetector extends Block
{
protected DB_BlockRainDetector(int i, int j)
{
super(i, j, Material.iron);
}
public int idDropped(int i, Random random)
{
return mod_DarksBlocks.DGlowStone.blockID;
}
public void updateTick(World world, int i, int j, int k, Random random)
{
if(world.isRaining() != false && world.isRaining() == true)
{
blockActivated( world, i, j, k, null);
}
if(world.multiplayerWorld)
{
return;
}
int l = world.getBlockMetadata(i, j, k);
if((l & 8) == 0)
{
return;
}
world.setBlockMetadataWithNotify(i, j, k, l & 7);
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
int i1 = l & 7;
if(i1 == 1)
{
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
} else
if(i1 == 2)
{
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
} else
if(i1 == 3)
{
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
} else
if(i1 == 4)
{
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
} else
{
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
}
world.playSoundEffect((double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, "random.click", 0.3F, 0.5F);
world.markBlocksDirty(i, j, k, i, j, k);
}
public void onBlockPlaced(World world, int i, int j, int k, int l)
{
int i1 = world.getBlockMetadata(i, j, k);
int j1 = i1 & 8;
i1 &= 7;
i1 = -1;
if(l == 1 && world.isBlockNormalCube(i, j - 1, k))
{
i1 = 5 + world.rand.nextInt(2);
}
if(l == 2 && world.isBlockNormalCube(i, j, k + 1))
{
i1 = 4;
}
if(l == 3 && world.isBlockNormalCube(i, j, k - 1))
{
i1 = 3;
}
if(l == 4 && world.isBlockNormalCube(i + 1, j, k))
{
i1 = 2;
}
if(l == 5 && world.isBlockNormalCube(i - 1, j, k))
{
i1 = 1;
}
if(i1 == -1)
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
world.setBlockWithNotify(i, j, k, 0);
return;
} else
{
world.setBlockMetadataWithNotify(i, j, k, i1 + j1);
return;
}
}
public void onNeighborBlockChange(World world, int i, int j, int k, int l)
{
int i1 = world.getBlockMetadata(i, j, k) & 7;
boolean flag = false;
if(!world.isBlockNormalCube(i - 1, j, k) && i1 == 1)
{
flag = true;
}
if(!world.isBlockNormalCube(i + 1, j, k) && i1 == 2)
{
flag = true;
}
if(!world.isBlockNormalCube(i, j, k - 1) && i1 == 3)
{
flag = true;
}
if(!world.isBlockNormalCube(i, j, k + 1) && i1 == 4)
{
flag = true;
}
if(!world.isBlockNormalCube(i, j - 1, k) && i1 == 5)
{
flag = true;
}
if(!world.isBlockNormalCube(i, j - 1, k) && i1 == 6)
{
flag = true;
}
if(flag)
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
world.setBlockWithNotify(i, j, k, 0);
}
}
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
{
if(world.multiplayerWorld)
{
return true;
}
int l = world.getBlockMetadata(i, j, k);
int i1 = l & 7;
int j1 = 8 - (l & 8);
world.setBlockMetadataWithNotify(i, j, k, i1 + j1);
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
if(i1 == 1)
{
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
} else
if(i1 == 2)
{
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
} else
if(i1 == 3)
{
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
} else
if(i1 == 4)
{
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
} else
{
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
}
return true;
}
public void onBlockRemoval(World world, int i, int j, int k)
{
int l = world.getBlockMetadata(i, j, k);
if((l & 8) > 0)
{
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
int i1 = l & 7;
if(i1 == 1)
{
world.notifyBlocksOfNeighborChange(i - 1, j, k, blockID);
} else
if(i1 == 2)
{
world.notifyBlocksOfNeighborChange(i + 1, j, k, blockID);
} else
if(i1 == 3)
{
world.notifyBlocksOfNeighborChange(i, j, k - 1, blockID);
} else
if(i1 == 4)
{
world.notifyBlocksOfNeighborChange(i, j, k + 1, blockID);
} else
{
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
}
}
super.onBlockRemoval(world, i, j, k);
}
public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
return (iblockaccess.getBlockMetadata(i, j, k) & 8) > 0;
}
public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l)
{
int i1 = world.getBlockMetadata(i, j, k);
if((i1 & 8) == 0)
{
return false;
}
int j1 = i1 & 7;
if(j1 == 6 && l == 1)
{
return true;
}
if(j1 == 5 && l == 1)
{
return true;
}
if(j1 == 4 && l == 2)
{
return true;
}
if(j1 == 3 && l == 3)
{
return true;
}
if(j1 == 2 && l == 4)
{
return true;
}
return j1 == 1 && l == 5;
}
public boolean canProvidePower()
{
return true;
}
}
i basicly copied one of the redstone item's class and changed the activation to if world.israining which is as far as my guessing to modding could figure out at the moment.
Any help would be nice since i'm new to modding still. even if it is just to point me at where in notch's code does it tell things it is raining. Also if you could explain how some of the code works. For example how redstonetorch or button output redstone signal would be nice. For those that ask why i want to make this block? it is to work with the rainCollector machine from mineFactory and to be able to tell my engines from buildCraft to run the collector only when it rains.
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
I almost yelled at you for not being able to tell when it's raining. I'm glad I started reading first.
Have you tried a simple debug to see if it works yet? Try running the current code and using something like SPC to make it rain.
Rollback Post to RevisionRollBack
[quote=Badgerz]You have to keep in mind that people are stupid.
[quote=Catelite]Just because you don't understand how something works, doesn't make it broken or pointless. >_<
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
I almost yelled at you for not being able to tell when it's raining. I'm glad I started reading first.
Have you tried a simple debug to see if it works yet? Try running the current code and using something like SPC to make it rain.
i might need to change the title you might not be the only one thinking i cant tell if it is raining.Also i have not tried spc to do it but it is a good ideal if i can get it running without having to reob my code each time. i however did do a test using my block and redstone memory circuit to see if it ever turned on. according to the circuit it never did even though i could hear it rain from my other pc where i left the test running.
Edit. I made a block to make it rain which should make testing easier but I still have no luck at getting it to work
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
ok i got my block working on my own. it is quit sad how these types of posts get little help or even comments. even though i thank NeoSpecter for giving me the ideal to make something to cause the rain.
here is my working code for anyone else to use as long as you give me credit.
/ Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
package net.minecraft.src;
import java.util.List;
import java.util.Random;
// Referenced classes of package net.minecraft.src:
// Block, World, EnumMobType, AxisAlignedBB,
// EntityLiving, EntityPlayer, IBlockAccess, Material,
// Entity
public class DB_BlockRainPlate extends Block
{
//copy of pressure plate block class converted to rain detector
protected DB_BlockRainPlate(int i, int j)
{
super(i, j, Material.ground);
setTickOnLoad(true);
float f = 0.0625F;
setBlockBounds(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f);
}
// 1 second update rate
public int tickRate()
{
return 20;
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)
{
return null;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
public boolean canPlaceBlockAt(World world, int i, int j, int k)
{
return world.isBlockNormalCube(i, j - 1, k) || world.getBlockId(i, j - 1, k) == Block.fence.blockID;
}
public void onBlockAdded(World world, int i, int j, int k)
{
}
public void onNeighborBlockChange(World world, int i, int j, int k, int l)
{
boolean flag = false;
if(!world.isBlockNormalCube(i, j - 1, k) && world.getBlockId(i, j - 1, k) != Block.fence.blockID)
{
flag = true;
}
if(flag)
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k));
world.setBlockWithNotify(i, j, k, 0);
}
}
// updater
public void updateTick(World world, int i, int j, int k, Random random)
{
setStateIfRaining(world, i, j, k);
return;
}
// check if it raining class
private void setStateIfRaining(World world, int i, int j, int k)
{
boolean flag = world.getBlockMetadata(i, j, k) == 1;
boolean flag1 = false;
float f = 0.125F;
//check if it is raining in the world
if(world.isRaining() == true)
{
flag1 = true;
//ModLoader.getMinecraftInstance().thePlayer.addChatMessage("raining");
}
else
{
flag1 = false;
//ModLoader.getMinecraftInstance().thePlayer.addChatMessage("not raining");
}
//if it is raining output redstone 1
if(flag1 && !flag)
{
world.setBlockMetadataWithNotify(i, j, k, 1);
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
//ModLoader.getMinecraftInstance().thePlayer.addChatMessage("1");
}
//if it is not raining output redstone 0
if(!flag1 && flag)
{
world.setBlockMetadataWithNotify(i, j, k, 0);
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
// ModLoader.getMinecraftInstance().thePlayer.addChatMessage("0");
}
if(flag1)
{
world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
}
}
// tells blocks it has been removed
public void onBlockRemoval(World world, int i, int j, int k)
{
int l = world.getBlockMetadata(i, j, k);
if(l > 0)
{
world.notifyBlocksOfNeighborChange(i, j, k, blockID);
world.notifyBlocksOfNeighborChange(i, j - 1, k, blockID);
}
super.onBlockRemoval(world, i, j, k);
}
public void setBlockBoundsBasedOnState(IBlockAccess iblockaccess, int i, int j, int k)
{
boolean flag = iblockaccess.getBlockMetadata(i, j, k) == 1;
float f = 0.0625F;
if(flag)
{
setBlockBounds(f, 0.0F, f, 1.0F - f, 0.03125F, 1.0F - f);
} else
{
setBlockBounds(f, 0.0F, f, 1.0F - f, 0.0625F, 1.0F - f);
}
}
// check if power is supplied
public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
return iblockaccess.getBlockMetadata(i, j, k) > 0;
}
//check if indirect power is supplied
public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l)
{
if(world.getBlockMetadata(i, j, k) == 0)
{
return false;
} else
{
return l == 1;
}
}
// can it power anything
public boolean canProvidePower()
{
return true;
}
//render for item look
public void setBlockBoundsForItemRender()
{
float f = 0.5F;
float f1 = 0.125F;
float f2 = 0.5F;
setBlockBounds(0.5F - f, 0.5F - f1, 0.5F - f2, 0.5F + f, 0.5F + f1, 0.5F + f2);
}
public int getMobilityFlag()
{
return 1;
}
//set to drop item block
public int idDropped(int i, Random random)
{
return mod_DarksBlocks.DRainDetector.blockID;
}
}
the code is quit simple being a pressure plate code with the collision detection replaced with world.isRaining. the block that makes it rain is simple a block with on click method and world.worldInfo.setIsRaining(true)
Rollback Post to RevisionRollBack
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
The world can be raining, but you may not even see it because it only rains in specific spots, sometimes if you move far enough you can still hear it, but the rain is not visible. If you could find a way to detect if rain is falling on that specific block, instead of anywhere in the world then it would be even better.
The world can be raining, but you may not even see it because it only rains in specific spots, sometimes if you move far enough you can still hear it, but the rain is not visible. If you could find a way to detect if rain is falling on that specific block, instead of anywhere in the world then it would be even better.
it would be nicer to get if it is raining on the block but for now i can deal with it working anywhere. although the only thing i need to do too get make it look as if it is detecting rain on the block is too see if the block can see sky. then if it rains the rain will come all the way to the block and activate it. if it is under something and cant see sky then it will not activate if it is raining.
Rollback Post to RevisionRollBack
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
it would be nicer to get if it is raining on the block but for now i can deal with it working anywhere. although the only thing i need to do too get make it look as if it is detecting rain on the block is too see if the block can see sky. then if it rains the rain will come all the way to the block and activate it. if it is under something and cant see sky then it will not activate if it is raining.
To check if it is actually raining for a block you would need something like this.
Basically it checks if a lightning bolt can be spawned at that block. if so it also means it can rain on that block. If isRaining is true any block that can spawn a lightingbolt in the loaded world will also have rain hitting it. ;-)
Basically it checks if a lightning bolt can be spawned at that block. if so it also means it can rain on that block. If isRaining is true any block that can spawn a lightingbolt in the loaded world will also have rain hitting it. ;-)
Basically it checks if a lightning bolt can be spawned at that block. if so it also means it can rain on that block. If isRaining is true any block that can spawn a lightingbolt in the loaded world will also have rain hitting it. ;-)
that is clever as the other guy said and also thanks i'm going to have to try that out.
Rollback Post to RevisionRollBack
Author of Fluid Mechanics, Assembly Line, ICBM, Come Closer, and Artillects. Including Java Freelancer for hire specializing in creating and fixing minecraft mods.
i basicly copied one of the redstone item's class and changed the activation to if world.israining which is as far as my guessing to modding could figure out at the moment.
Have you tried a simple debug to see if it works yet? Try running the current code and using something like SPC to make it rain.
[quote=Badgerz]You have to keep in mind that people are stupid.
[quote=Catelite]Just because you don't understand how something works, doesn't make it broken or pointless. >_<
why did you add a link to stopFinger.com selling an android
i might need to change the title you might not be the only one thinking i cant tell if it is raining.Also i have not tried spc to do it but it is a good ideal if i can get it running without having to reob my code each time. i however did do a test using my block and redstone memory circuit to see if it ever turned on. according to the circuit it never did even though i could hear it rain from my other pc where i left the test running.
Edit. I made a block to make it rain which should make testing easier but I still have no luck at getting it to work
Sorry,i said this,i am wrong.
here is my working code for anyone else to use as long as you give me credit.
it would be nicer to get if it is raining on the block but for now i can deal with it working anywhere. although the only thing i need to do too get make it look as if it is detecting rain on the block is too see if the block can see sky. then if it rains the rain will come all the way to the block and activate it. if it is under something and cant see sky then it will not activate if it is raining.
To check if it is actually raining for a block you would need something like this.
Were j,k are your Coords.
Basically it checks if a lightning bolt can be spawned at that block. if so it also means it can rain on that block. If isRaining is true any block that can spawn a lightingbolt in the loaded world will also have rain hitting it. ;-)
Very clever.
Thanks
Yeah it is similar to the same code that renders the rain fx
that is clever as the other guy said and also thanks i'm going to have to try that out.