feat: Реализация BlockSource.spawnEntity

This commit is contained in:
MaXFeeD
2024-02-13 15:21:52 +03:00
parent e62a885a98
commit ec830e57d3
@@ -127,7 +127,7 @@ public class BlockSourceMethods {
int updateType) { int updateType) {
Block block = level.getBlock(x, y, z); Block block = level.getBlock(x, y, z);
defDestroy(level, block); defDestroy(level, block);
level.setBlock(x, y, z, Block.get(id, data).clone(), false, allowUpdate); level.setBlock(x, y, z, Block.get(id, data), false, allowUpdate);
sendBlock(level, x, y, z, 0); sendBlock(level, x, y, z, 0);
} }
@@ -236,10 +236,13 @@ public class BlockSourceMethods {
} }
public static long spawnEntity(Level level, int type, float x, float y, float z) { public static long spawnEntity(Level level, int type, float x, float y, float z) {
Entity entity = Entity.createEntity(type, new Position(x, y, z)); Entity entity = Entity.createEntity(type, new Position(x, y, z, level));
level.addEntity(entity); if (entity != null) {
entity.spawnToAll();
return entity.getId(); return entity.getId();
} }
return -1;
}
public static long spawnNamespacedEntity(Level level, float x, float y, float z, String str1, String str2, public static long spawnNamespacedEntity(Level level, float x, float y, float z, String str1, String str2,
String str3) { String str3) {
@@ -248,16 +251,22 @@ public class BlockSourceMethods {
} }
// TODO: Quite BETTER name to identifier conversion! // TODO: Quite BETTER name to identifier conversion!
Entity entity = Entity.createEntity(str2.substring(0, 1).toUpperCase() + str2.substring(1).replace("_", ""), Entity entity = Entity.createEntity(str2.substring(0, 1).toUpperCase() + str2.substring(1).replace("_", ""),
new Position(x, y, z)); new Position(x, y, z, level));
level.addEntity(entity); if (entity != null) {
entity.spawnToAll();
return entity.getId(); return entity.getId();
} }
return -1;
}
public static long spawnExpOrbs(Level level, float x, float y, float z, int amount) { public static long spawnExpOrbs(Level level, float x, float y, float z, int amount) {
Vector3 source = new Vector3(x, y, z); Vector3 source = new Vector3(x, y, z);
CompoundTag nbt = Entity.getDefaultNBT(source, new Vector3(0, 0, 0)); CompoundTag nbt = Entity.getDefaultNBT(source, new Vector3(0, 0, 0));
Entity entity = Entity.createEntity("XpOrb", level.getChunk(source.getChunkX(), source.getChunkZ()), nbt); Entity entity = Entity.createEntity("XpOrb", new Position(x, y, z, level), nbt);
if (entity != null) {
entity.spawnToAll(); entity.spawnToAll();
return entity.getId(); return entity.getId();
} }
return -1;
}
} }