Jump to content

Recommended Posts

Posted

Hey Guys,

 

I'm fairly new to modding minecraft with forge.

 

I want to check if the player is in a cave or not...

I figured this would be possible to check because there are lots of minecraft cave map mods and such.

 

Only problem, I have no idea where to start  :-[

 

Help is greatly appreciated, thanks in advance!  :)

Posted

The typical way to go about it is to check if the player can see the sky or not.

 

The problem with that is how do you differentiate being under a tree or in a house vs. in a cave? So you have to decide how would you even define a 'cave'? Should it be mostly stone blocks? What about dirt? Sandstone? Mineshafts?

 

Once you decide that, you can get fancier and check surrounding blocks, but that will slow your algorithm down exponentially with the search radius. To make it faster, you could only check the first non-air block above the player and see if it's in your whitelist of acceptable 'cave' blocks, but then you still get false positives if a player makes a house of stone, for example.

 

Anyway, there isn't any surefire way that I know of to say with 100% certainty a player is in a cave, so you have to figure out what is an acceptable level of error for your purposes.

Posted

If you don't mind missing caves high in hillsides, you could look at the player's Y coordinate to see if it is <62. Overworld and subterranean y and no sky and not wet is probably a cave (or mine, or stronghold, or the player's underground lair).

 

Also decide what you want to do about dimensions besides the overworld.

 

What are you trying to accomplish? Depending on your objective, you might also look at light-level to rule-out houses, deep bases, and well-civilized caves.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Well, the goal is to have a item that plays music at its position, when the player has the item in his inventory it will play the music on the position of the player, so far so good all of that is already implemented.

 

Now to the advanced stuff, I want to let the player specify a group of music (a playlist) and bind it to certain things in the game.

This bindings being:

  - Day

  - Night

  - Cave

  - Combat

  - etc.

 

Day & night was easy and is already implemented.

Posted

  - Combat

You have a few ways to handle this one.

You could use the LivingEntityHurt event (I think), and check if it's the player being hurt or hurting something. If there's an event for the swinging of an item, you could check if it's a sword that a player is holding, and play the music then.

Posted

Doesn't Minecraft already play spooky sounds when you go into a cave? How does it determine that?

The ambient sounds emerge from dark air with no sky. You can hear them even if there's stone between you and the darkness.

 

Yes, it would be worth looking at the test for ambient sound.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

  • 1 month later...
Posted

Thanks for all the answers so far!

 

@jeffryfisher How would I check for wetness and light-level on blocks?

 

I already got that far to check for the players Y position and if the first non air block above the player is exposed to the sun or if there even is one.

 

Can anybody tell me how deep and high the minecraft world is?

 

Thanks again for your help.

Posted

Check if their sunlight is below a certain threshold (I would say about 10). However, being inside would trigger it. You may have to do other checks, such as Y-level (if you can, base it off sea level) and checking their surroundings (you would only need to do this once per second at most).

Posted

The survival overworld has Y-coords 0..255, with bedrock filling the lowermost few and sea-level at 63.

 

I think there's a world method "isWet", but what I meant was not swimming in an ocean. Just being in air should suffice.

 

There are several light levels (including the luminosity of each block type), but now I'm not sure that would help you. You want a trigger in lit caves also, right? I think you want to find the method "canSeeTheSky" (or something like that).

 

BTW, One can never see sky in the End and Nether, so you might want to trap those first (and maybe make different sounds for them).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

isWet is a boolean based on whether or not the entity was recently (or still is) swimming, that's it.  It's not even close to what you'd have to do to check for caves.

 

As for sky_light, that absolutely helps, and more so than canSeeTheSky.  canSeeTheSky checks only the vertical column of blocks at the current location.  sky_light can reach up to 15 blocks underneath an overhang.  Sky_light is also tracked independently of block_light, so lit caves will still register as caves.

 

The problem is figuring out whether or not the material blocking out the light is made of stone, as opposed to wood, dirt, water, or other block type.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • 2 months later...
Posted

In 1.10 the method is called "getLightFor(EnumSkyBlock, BlockPos)" (that's the environemtn I have open at the moment). I can't recall the 1.7.10 name off the top of my head ("getSavedLightValue?"), but it's named pretty similarly and takes an

EnumSkyBlock

parameter (which has two values:

BLOCK

meaning torches, etc. and

SKY

meaning the sun).

 

It doesn't check day/night (that's "getSkylightSubtracted").  But yeah, any "cave" location is going to have 0 sunlight.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.