1414import com .hypixel .hytale .server .core .universe .world .storage .ChunkStore ;
1515import org .jetbrains .annotations .NotNull ;
1616
17- import java .util .Objects ;
18-
1917/**
2018 * Represents a block in a world.
21- * Hytale doesn't appear to have a representation of a block in a world.
19+ * Hytale doesn't appear to have a representation of a block in the world.
2220 * This class provides a wrapper around Hytale's block system, allowing for easy interaction with blocks in a world.
2321 * This may be changed/removed in the future.
2422 */
2523@ SuppressWarnings ("unused" )
2624public class Block {
2725
2826 private final @ NotNull World world ;
29- private @ NotNull BlockType type ;
3027 private final @ NotNull Vector3i pos ;
3128
3229 public Block (@ NotNull World world , @ NotNull Vector3i pos ) {
3330 this .world = world ;
3431 this .pos = pos ;
35- this .type = Objects .requireNonNull (world .getBlockType (pos ));
3632 }
3733
3834 public Block (@ NotNull World world , @ NotNull Vector3i pos , @ NotNull BlockType type ) {
3935 this .world = world ;
4036 this .pos = pos ;
41- this .type = type ;
4237 }
4338
4439 public Block (@ NotNull Location location ) {
@@ -52,11 +47,11 @@ public Block(@NotNull Location location) {
5247 }
5348
5449 public @ NotNull BlockType getType () {
55- return this .type ;
50+ BlockType blockType = this .world .getBlockType (this .pos );
51+ return blockType != null ? blockType : BlockType .EMPTY ;
5652 }
5753
5854 public void setType (@ NotNull BlockType type , int settings ) {
59- this .type = type ;
6055 this .world .setBlock (this .pos .getX (), this .pos .getY (), this .pos .getZ (), type .getId (), settings );
6156 }
6257
@@ -152,15 +147,15 @@ public void breakBlock(int settings) {
152147
153148 public String toTypeString () {
154149 return String .format ("[%s] block at (%s,%s,%s) in '%s'" ,
155- this .type .getId (), this .pos .getX (), this .pos .getY (), this .pos .getZ (), this .world .getName ());
150+ this .getType () .getId (), this .pos .getX (), this .pos .getY (), this .pos .getZ (), this .world .getName ());
156151 }
157152
158153 @ Override
159154 public String toString () {
160155 return "Block{" +
161- "world=" + world .getName () +
162- ", type=" + type +
163- ", pos=" + pos +
156+ "world=" + this . world .getName () +
157+ ", type=" + this . getType () +
158+ ", pos=" + this . pos +
164159 '}' ;
165160 }
166161
0 commit comments