Skip to content

Commit

Permalink
fix: getIdByNameId, sendBlock
Browse files Browse the repository at this point in the history
- исправлен getIdByNameId
- добавлена отправка блоков, которые устанавливаются с помощью BlockSource
  • Loading branch information
Reider745 committed Dec 15, 2023
1 parent 4794804 commit 8fbd6c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/reider745/world/BlockSourceMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.reider745.hooks.ItemUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

public class BlockSourceMethods {
Expand All @@ -34,6 +35,17 @@ private static void defDestroy(Level level, Block target) {
}
}

private static void sendBlock(Level level, int x, int y, int z){
final int X = x/16, Z = z/16;
final ArrayList<Player> players = new ArrayList<>();

for(int xo = -1;xo <= 1;xo++)
for(int zo = -1;zo <= 1;zo++)
players.addAll(level.getChunkPlayers(X+xo, Z+zo).values());

level.sendBlocks(players.toArray(new Player[0]), new Vector3[]{new Vector3(x, y, z)});
}

public static Level getLevelForDimension(int dimension) {
if (dimension >= 0 && dimension <= 2) {
return InnerCoreServer.server.getLevelByName(switch (dimension) {
Expand Down Expand Up @@ -62,6 +74,7 @@ public static void destroyBlock(Level pointer, int x, int y, int z, boolean drop
}
defDestroy(pointer, block);
pointer.setBlock(x, y, z, Block.get(0), false, update);
sendBlock(pointer, x, y, z);
}

public static int getBlockId(Level pointer, int x, int y, int z) {
Expand Down Expand Up @@ -129,6 +142,7 @@ public static void setBlock(Level pointer, int x, int y, int z, int id, int data
Block block = pointer.getBlock(x, y, z);
defDestroy(pointer, block);
pointer.setBlock(x, y, z, Block.get(id, data).clone(), false, allowUpdate);
sendBlock(pointer, x, y, z);
}

public static void setBlockByRuntimeId(Level pointer, int x, int y, int z, int runtimeId, boolean allowUpdate,
Expand All @@ -141,6 +155,7 @@ public static void setBlockByRuntimeId(Level pointer, int x, int y, int z, int r
public static void setExtraBlock(Level pointer, int x, int y, int z, int id, int data, boolean allowUpdate,
int updateType) {
pointer.setBlockExtraDataAt(x, y, z, id, data);
sendBlock(pointer, x, y, z);
}

public static void setExtraBlockByRuntimeId(Level pointer, int x, int y, int z, int runtimeId, boolean allowUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ static void putId(String name, int id) {
}

public static int getIdByNameId(String id) {
System.out.println(id);
if (id.startsWith("item_")) {
return CustomItem.getIdForText(id.replace("item_", ""));
return CustomItem.getIdForText(id);
}
return CustomBlock.getIdForText(id.replace("block_", ""));
return CustomBlock.getIdForText(id);
}

static boolean isOccupied(int id) {
Expand Down

0 comments on commit 8fbd6c2

Please sign in to comment.