3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Use compute for determining if a lectern if present

Reduces having to call both containsKey and get.
Dieser Commit ist enthalten in:
Camotoy 2021-03-10 13:54:09 -05:00
Ursprung ded00dfd97
Commit 370f3c18ba
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 28 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction;
/** /**
* Used for block entities if the Java block state contains Bedrock block information. * Used for block entities if the Java block state contains Bedrock block information.
@ -199,7 +200,13 @@ public class BlockStateValues {
return FLOWER_POT_VALUES; return FLOWER_POT_VALUES;
} }
public static Int2BooleanMap getLecternBookStates() { /**
* This returns a Map interface so IntelliJ doesn't complain about {@link Int2BooleanMap#compute(int, BiFunction)}
* not returning null.
*
* @return the lectern book state map pointing to book present state
*/
public static Map<Integer, Boolean> getLecternBookStates() {
return LECTERN_BOOK_STATES; return LECTERN_BOOK_STATES;
} }

Datei anzeigen

@ -372,27 +372,30 @@ public class ChunkUtils {
} }
session.sendUpstreamPacket(waterPacket); session.sendUpstreamPacket(waterPacket);
if (BlockStateValues.getLecternBookStates().containsKey(blockState)) { BlockStateValues.getLecternBookStates().compute(blockState, (key, newLecternHasBook) -> {
boolean lecternCachedHasBook = session.getLecternCache().contains(position); // Determine if this block is a lectern
boolean newLecternHasBook = BlockStateValues.getLecternBookStates().get(blockState); if (newLecternHasBook != null) {
if (!session.getConnector().getWorldManager().shouldExpectLecternHandled() && lecternCachedHasBook != newLecternHasBook) { boolean lecternCachedHasBook = session.getLecternCache().contains(position);
// Refresh the block entirely - it either has a book or no longer has a book if (!session.getConnector().getWorldManager().shouldExpectLecternHandled() && lecternCachedHasBook != newLecternHasBook) {
NbtMap newLecternTag; // Refresh the block entirely - it either has a book or no longer has a book
if (newLecternHasBook) { NbtMap newLecternTag;
newLecternTag = session.getConnector().getWorldManager().getLecternDataAt(session, position.getX(), position.getY(), position.getZ(), false); if (newLecternHasBook) {
newLecternTag = session.getConnector().getWorldManager().getLecternDataAt(session, position.getX(), position.getY(), position.getZ(), false);
} else {
session.getLecternCache().remove(position);
newLecternTag = LecternInventoryTranslator.getBaseLecternTag(position.getX(), position.getY(), position.getZ(), 0).build();
}
BlockEntityUtils.updateBlockEntity(session, newLecternTag, position);
} else { } else {
session.getLecternCache().remove(position); // As of right now, no tag can be added asynchronously
newLecternTag = LecternInventoryTranslator.getBaseLecternTag(position.getX(), position.getY(), position.getZ(), 0).build(); session.getConnector().getWorldManager().getLecternDataAt(session, position.getX(), position.getY(), position.getZ(), false);
} }
BlockEntityUtils.updateBlockEntity(session, newLecternTag, position);
} else { } else {
// As of right now, no tag can be added asynchronously // Lectern has been destroyed, if it existed
session.getConnector().getWorldManager().getLecternDataAt(session, position.getX(), position.getY(), position.getZ(), false); session.getLecternCache().remove(position);
} }
} else { return newLecternHasBook;
// Lectern has been destroyed, if it existed });
session.getLecternCache().remove(position);
}
// Since Java stores bed colors/skull information as part of the namespaced ID and Bedrock stores it as a tag // Since Java stores bed colors/skull information as part of the namespaced ID and Bedrock stores it as a tag
// This is the only place I could find that interacts with the Java block state and block updates // This is the only place I could find that interacts with the Java block state and block updates