[SOLVED] Detecting Chunks from a block within

Started by TechTastic on Tue, 06/29/2021 - 15:56

Topic category: Help with modding (Java Edition)

Last seen on 02:01, 27. Aug 2021
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[SOLVED] Detecting Chunks from a block within
Wed, 06/30/2021 - 04:07 (edited)

Hey so I am making a land claiming system and I wanna have a way to detect the actual chunks its protecting so I can do a No Man's Land protective "skirt" around the claimed chunks

 

If there is a way to detect chunks then please let me know!

 

EDIT:

I know I said it below in the reply section, but to fix my own errors and provide much needed links, ill post my solution here!

 

WARNING: This solution requires the ArrayLists plugin found here: https://mcreator.net/plugin/65659/arraylists

 

Array = [0, 16, 32, 48, 64, …, 37500]

Set xD = x MOD 16

If xD =/= 0

  • xChunk = (x - xD) / 16

Else

  • xChunk = x / 16

Set zD = z MOD 16

If zD =/= 0

  • zChunk = (z - zD) / 16

Else

  • zChunk = z / 16

Say "This is Chunk [" + Array[xChunk] + ", " + Array[zChunk] + "]."

 

Q&A

Q1: Why stop at 375000?

A1: That is the default world border (6,000,000) divided by 16

 

Q2: How does this work?

A2: I was testing and found out that chunks start at the North West corner (where X and Z are divisible from 16) and ran with that. Basically, it gets the location, doing MOD reveals how many blocks they are away from being divisible by 16, they move there, and then reference the array to get a chunk-based X and Z! It sounds complex but its just simple math using MOD.

Edited by TechTastic on Wed, 06/30/2021 - 04:07
Last seen on 02:01, 27. Aug 2021
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Bump!
Wed, 06/30/2021 - 00:41

Bump!

Last seen on 02:01, 27. Aug 2021
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Ok I've got a working…
Wed, 06/30/2021 - 03:40

Ok I've got a working solution that solves the detection issue. It ONLY detects chunks for now but more can be added onto

 

WARNING: This solution requires the ArrayList plugin!

 

Array = [0, 16, 32, 48, 64, …, 37500]

Set xD = x MOD 16

If xD =/= 0

  • xChunk = (x - xD)/16

Else

  • xChunk = x/16

Set zD = z MOD 16

If zD =/= 0

  • zChunk = (z - zD)/16

Else

  • zChunk = z/16

Say "This is Chunk [" + Array[x] + ", " + Array[z] + "]."

 

Q&A

Q1: Why stop at 375000?

A1: That is the default world border (6,000,000) divided by 16

 

Q2: How does this work?

A2: I was testing and found out that chunks start at the North West corner (where X and Z are divisible from 16) and ran with that. Basically, it gets the location, doing MOD reveals how many blocks they are away from being divisible by 16, they move there, and then reference the array to get a chunk-based X and Z! It sounds complex but its just simple math using MOD.

Last seen on 02:01, 27. Aug 2021
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Oops, I messed up in my jot…
Wed, 06/30/2021 - 03:58

Oops, I messed up in my jot-on-paper logic

In the Say part, replace Array[x] and Array[z] with Array[xChunk] and Array [zChunk] respectively

Last seen on 02:01, 27. Aug 2021
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
K so nevermind   This…
Wed, 06/30/2021 - 11:41

K so nevermind

 

This problem doesn't require ArrayLists, just an understanding that a chunk is 16x16 and that a new chunk starts at 16