How Can I check "is player below a radius from the block"?

Started by diniboy on Mon, 04/11/2016 - 18:17

Topic category: Help with MCreator modding

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
How Can I check "is player below a radius from the block"?
Mon, 04/11/2016 - 18:17

Hi!

I tried to create some flowers with mcreator. I created a flower which can "eat" the player, but I Can't find any action to check the nearest player distance smaller than nine or something...

Is there a way to check this?

Thanks!

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
  Try something like:
Mon, 04/11/2016 - 18:27

  Try something like:

AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
     
     
        List list = this.worldObj.getEntitiesWithinAABB(EntityPlayerclass,box);
         if(!list.isEmpty()){

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:  Try something like:
Tue, 04/12/2016 - 14:57

Hi Nuparu!

 

Thanks for UR quick answer! :)

 

It tried it (pasted this to the custom code section), but it says an error...:

AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
   List list = this.worldObj.getEntitiesWithinAABB(EntityPlayerclass,box);
         if(!list.isEmpty()){
             setLightLevel(1.8F);
         }
         else{
             setLightLevel(0.0F);
         }

 

And here is the gradle log:

 

warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
                                                     ^
  symbol: variable posX
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
                                                                    ^
  symbol: variable posY
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
                                                                                  ^
  symbol: variable posZ
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
                                                                                                ^
  symbol: variable posX
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
                                                                                                               ^
  symbol: variable posY
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(this.posX - 9, this.posY -9, this.posZ -9, this.posX + 9, this.posY + 9, this.posZ + 9);
                                                                                                                              ^
  symbol: variable posZ
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:165: error: cannot find symbol
   List list = this.worldObj.getEntitiesWithinAABB(EntityPlayerclass,box);
                                                   ^
  symbol:   variable EntityPlayerclass
  location: class BlockSpecialNightLight
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_specialNightLight.java:165: error: cannot find symbol
   List list = this.worldObj.getEntitiesWithinAABB(EntityPlayerclass,box);
                   ^
  symbol: variable worldObj
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
8 errors
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Thanks!

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Oh , sorry , my mistake. It
Tue, 04/12/2016 - 17:05

Oh , sorry , my mistake. It was for entity , not block. So for block it is:
 

AxisAlignedBB box = AxisAlignedBB.getBoundingBox(pos.getX() - 9, pos.getY() -9, pos.getZ() -9, pos.getX() + 9, pos.getY() + 9, pos.getZ() + 9);
     
     
        List list = world.getEntitiesWithinAABB(EntityPlayer.class,box);
         if(!list.isEmpty()){

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Thank You very much! :) I'll
Tue, 04/12/2016 - 17:30

Thank You very much! :) I'll try it tomorrow.

2. I have a second question regarding the flower. I created a texture in GIMP (i'm using linux), but it's similar than a torch (for example). It isn't a simple block, it's just a "thin" block. But I Can't find flower in the TX options at MCreator. So How Can I insert it to the game correctly?

Thanks once again!

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Oh , sorry , my mistake. It
Wed, 04/13/2016 - 17:00

@#3 I tried Your code, but it says the following:

 

warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:\Users\Pisti\Mcreator\forge\build\sources\main\java\mod\mcreator\mcreator_flower.java:164: error: cannot find symbol
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(pos.getX() - 9, pos.getY() -9, pos.getZ() -9, pos.getX() + 9, pos.getY() + 9, pos.getZ() + 9);
                                 ^
  symbol:   method getBoundingBox(int,int,int,int,int,int)
  location: class AxisAlignedBB
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
1 warning

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

 

Thanks!

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
RE:RE:Oh , sorry , my mistake. It
Wed, 04/13/2016 - 18:53

@#3.1 Change "AxisAlignedBB.getBoundingBox" to the "new AxisAlignedBB" . The previous method is for 1.7.10

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:RE:RE:Oh , sorry , my mistake. It
Thu, 04/14/2016 - 04:39

@#3.1.1 Ok. I'm using 1.8.9 forge.

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Hi!
Thu, 04/14/2016 - 15:14

Hi!

 

I tried created a block which only lights at night and the player radius is minimum 3 blocks from the block with Your code. Now I Can compile it without any errors, but it not works if I try it...

 

Here You Can read the code:

 

public void updateTick(World world, BlockPos pos, IBlockState state, Random random){
int i = pos.getX();int j = pos.getY();int k = pos.getZ();EntityPlayer entity = Minecraft.getMinecraft().thePlayer;

if(!world.isDaytime()){
AxisAlignedBB box = new AxisAlignedBB(pos.getX() - 3, pos.getY() -3, pos.getZ() -3, pos.getX() + 3, pos.getY() + 3, pos.getZ() + 3);
     
     
        List list = world.getEntitiesWithinAABB(EntityPlayer.class,box);
         if(!list.isEmpty()){
             setLightLevel(1.5F);
         }
         else{
             setLightLevel(0.2F);
         }
}

if(world.isDaytime()){
setLightLevel(0.0F);
}

world.scheduleUpdate(new BlockPos(i, j, k), this, this.tickRate(world));
}

 

Thanks!

Last seen on 17:10, 11. Sep 2016
Joined Mar 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Hi!
Fri, 04/15/2016 - 12:48

Nobody?

Last seen on 00:21, 11. Aug 2019
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Try make this variable
Fri, 04/15/2016 - 12:59

Try make this variable:
protected static World theWorld;

And use this methods:

public void updateTick(World world, int x, int y, int z, Random par5Random) {
if(theWorld == null)
theWorld = world;  //make sure theWorld is not null
getLightValue(null, x, y, z); //force recheck of light level, probably not needed
world.scheduleBlockUpdate(x, y, z, blockID, 600);  //schedule another update
}

@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
if(theWorld != null) {

if(!world.isDaytime()){
AxisAlignedBB box = new AxisAlignedBB(pos.getX() - 3, pos.getY() -3, pos.getZ() -3, pos.getX() + 3, pos.getY() + 3, pos.getZ() + 3);
     
     
        List list = world.getEntitiesWithinAABB(EntityPlayer.class,box);
         if(!list.isEmpty()){
             return 10;
         }
         else{
             return 2;
         }
}

if(world.isDaytime()){
return 0;
}

}
else
return 2;
}