From ec830e57d35d66f1f056b99303e4e5357f271109 Mon Sep 17 00:00:00 2001 From: MaXFeeD Date: Sun, 4 Feb 2024 04:53:21 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20BlockSource.spawnEntity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reider745/world/BlockSourceMethods.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/reider745/world/BlockSourceMethods.java b/src/main/java/com/reider745/world/BlockSourceMethods.java index 8115231c..be11a762 100644 --- a/src/main/java/com/reider745/world/BlockSourceMethods.java +++ b/src/main/java/com/reider745/world/BlockSourceMethods.java @@ -127,7 +127,7 @@ public class BlockSourceMethods { int updateType) { Block block = level.getBlock(x, y, z); 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); } @@ -236,9 +236,12 @@ public class BlockSourceMethods { } public static long spawnEntity(Level level, int type, float x, float y, float z) { - Entity entity = Entity.createEntity(type, new Position(x, y, z)); - level.addEntity(entity); - return entity.getId(); + Entity entity = Entity.createEntity(type, new Position(x, y, z, level)); + if (entity != null) { + entity.spawnToAll(); + return entity.getId(); + } + return -1; } public static long spawnNamespacedEntity(Level level, float x, float y, float z, String str1, String str2, @@ -248,16 +251,22 @@ public class BlockSourceMethods { } // TODO: Quite BETTER name to identifier conversion! Entity entity = Entity.createEntity(str2.substring(0, 1).toUpperCase() + str2.substring(1).replace("_", ""), - new Position(x, y, z)); - level.addEntity(entity); - return entity.getId(); + new Position(x, y, z, level)); + if (entity != null) { + entity.spawnToAll(); + return entity.getId(); + } + return -1; } public static long spawnExpOrbs(Level level, float x, float y, float z, int amount) { Vector3 source = new Vector3(x, y, z); CompoundTag nbt = Entity.getDefaultNBT(source, new Vector3(0, 0, 0)); - Entity entity = Entity.createEntity("XpOrb", level.getChunk(source.getChunkX(), source.getChunkZ()), nbt); - entity.spawnToAll(); - return entity.getId(); + Entity entity = Entity.createEntity("XpOrb", new Position(x, y, z, level), nbt); + if (entity != null) { + entity.spawnToAll(); + return entity.getId(); + } + return -1; } }