Skip to content

Commit 9cab0c9

Browse files
committed
Optimize memory usage for block clicks
1 parent 6bbac74 commit 9cab0c9

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/main/java/net/evmodder/evmod/listeners/BlockClickListener.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
public final class BlockClickListener{
1313
// public static BlockPos lastClickedBlock;
1414
public static UUID lastClickedBlockHash; // TODO: Ewwww public static :(
15+
private final ByteBuffer posData;
1516

16-
private static final UUID getIdForBlockPos(final World world, final BlockPos pos){
17+
private final UUID getIdForBlockPos(final World world, final BlockPos pos){
1718
final byte dim = MiscUtils.getDimensionId(world);
18-
final byte[] bytes = ByteBuffer.allocate(13).put(dim).putInt(pos.getX()).putInt(pos.getY()).putInt(pos.getZ()).array();
19-
return UUID.nameUUIDFromBytes(bytes);
19+
posData.rewind();
20+
posData.put(dim).putInt(pos.getX()).putInt(pos.getY()).putInt(pos.getZ()).array();
21+
return UUID.nameUUIDFromBytes(posData.array());
2022
}
2123

2224
public BlockClickListener(){ // TODO: currently called by ContainerOpenCloseListener
25+
posData = ByteBuffer.allocate(13);
2326
// TODO: add later phase, after ActionResult is determined to be PASS
2427
UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> {
2528
if(Configs.Generic.MAP_CACHE_BY_CONTAINER_POS.getBooleanValue()){

0 commit comments

Comments
 (0)