EDIT: Looking back on this, I may make the blocks TileEntities so that they can tick at an equal rate and not use tickRandomly because as it states, it's random and I need an equal tick rate.
Don't want to give away too many spoilers, but I need to check if a player is standing on a block and if they are, give them a potion effect.
I have been using this code in the blocks class file:
public void onEntityWalking(World world, int par2, int par3, int par4, Entity entity) { if(entity instanceof EntityLivingBase){ ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.blindness.getId(), 20, 10)); } }
However, this only runs the code when the event, 'onEntityWalking' occurs - so when an entity moves(player, mob etc) I'd like the code to continuously refresh the potion effect whilst the player is standing on the block.
A loop that runs, but breaks when they move to a different block, problem is; how does one loop in java!?
I understand loops and how they work, but I really don't understand how forge handles the game. Does every function run once through the MainRegistry class or is it continuously ran?
Anyway! My next attempt at the code also in the block class:
public void onEntityCollidedWithBlock(World world, int par2, int par3, int par4, Entity entity){
System.out.println("Ran Function!");
int x = MathHelper.floor_double(entity.posX);
int y = MathHelper.floor_double(entity.posY-0.2D - (double)entity.yOffset);
int z = MathHelper.floor_double(entity.posZ);
System.out.println(entity.worldObj.getBlock(x, y, z));
EDIT: Looking back on this, I may make the blocks TileEntities so that they can tick at an equal rate and not use tickRandomly because as it states, it's random and I need an equal tick rate.
Don't want to give away too many spoilers, but I need to check if a player is standing on a block and if they are, give them a potion effect.
I have been using this code in the blocks class file:
public void onEntityWalking(World world, int par2, int par3, int par4, Entity entity) {
if(entity instanceof EntityLivingBase){
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.blindness.getId(), 20, 10));
}
}
However, this only runs the code when the event, 'onEntityWalking' occurs - so when an entity moves(player, mob etc) I'd like the code to continuously refresh the potion effect whilst the player is standing on the block.
A loop that runs, but breaks when they move to a different block, problem is; how does one loop in java!?
I understand loops and how they work, but I really don't understand how forge handles the game. Does every function run once through the MainRegistry class or is it continuously ran?
Anyway! My next attempt at the code also in the block class:
public void onEntityCollidedWithBlock(World world, int par2, int par3, int par4, Entity entity){
System.out.println("Ran Function!");
int x = MathHelper.floor_double(entity.posX);
int y = MathHelper.floor_double(entity.posY-0.2D - (double)entity.yOffset);
int z = MathHelper.floor_double(entity.posZ);
System.out.println(entity.worldObj.getBlock(x, y, z));
if (entity.worldObj.getBlock(x, y, z) != null){
Block blindnessPotionBlock = Mblocks.blindnessPotionBlock;
if (entity.worldObj.getBlock(x, y, z) == blindnessPotionBlock ){
if(entity instanceof EntityLivingBase){
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.blindness.getId(), 20, 10));
}
}
}
}
Couldn't find the code button.....if there is one.