Skip to content

Commit 554ec8e

Browse files
committed
API world get block
1 parent 80ad1f0 commit 554ec8e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • src/main/java/com/hanprogramer/androids/entities/android/scripting

src/main/java/com/hanprogramer/androids/entities/android/scripting/WorldBridge.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.hanprogramer.androids.entities.android.scripting;
22

33
import com.hanprogramer.androids.entities.android.AndroidEntity;
4-
import com.hanprogramer.androids.util.BlockQuery;
54
import net.minecraft.block.Block;
65
import net.minecraft.block.BlockState;
7-
import net.minecraft.block.Blocks;
86
import net.minecraft.block.CropBlock;
97
import net.minecraft.registry.Registries;
108
import net.minecraft.server.world.ServerWorld;
@@ -92,6 +90,7 @@ public Value queryBlocksInAreaById(int[] area, String id) throws Exception {
9290

9391
return Value.asValue(ProxyArray.fromList(result));
9492
}
93+
9594
@HostAccess.Export
9695
public boolean blockCropIsMature(int[] pos) throws Exception {
9796
if (pos.length != 3) throw new Exception("arg1 must be a BlockPos (array of 3 integers XYZ)");
@@ -106,4 +105,17 @@ public boolean blockCropIsMature(int[] pos) throws Exception {
106105
}
107106
return false;
108107
}
108+
109+
@HostAccess.Export
110+
public String getBlockAt(int[] pos) throws Exception {
111+
var e = self.get();
112+
if (e == null) return "minecraft:air";
113+
if (pos.length != 3) throw new Exception("arg1 must be a BlockPos (array of 3 integers XYZ)");
114+
BlockPos blockPos = new BlockPos(pos[0], pos[1], pos[2]);
115+
116+
var state = e.getWorld().getBlockState(blockPos);
117+
118+
Identifier id = Registries.BLOCK.getId(state.getBlock());
119+
return id.toString(); // like "minecraft:dirt"
120+
}
109121
}

0 commit comments

Comments
 (0)