3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-08-01 01:58:07 +02:00
Dieser Commit ist enthalten in:
Camotoy 2022-01-19 19:30:54 -05:00
Ursprung 001a1a7a15
Commit a6004af083
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
3 geänderte Dateien mit 12 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -41,12 +41,14 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
@Override @Override
public void translate(GeyserSession session, BlockEntityDataPacket packet) { public void translate(GeyserSession session, BlockEntityDataPacket packet) {
NbtMap tag = packet.getData(); NbtMap tag = packet.getData();
if (tag.getString("id").equals("Sign")) { String id = tag.getString("id");
if (id.equals("Sign")) {
String text = tag.getString("Text");
// This is the reason why this all works - Bedrock sends packets every time you update the sign, Java only wants the final packet // This is the reason why this all works - Bedrock sends packets every time you update the sign, Java only wants the final packet
// But Bedrock sends one final packet when you're done editing the sign, which should be equal to the last message since there's no edits // But Bedrock sends one final packet when you're done editing the sign, which should be equal to the last message since there's no edits
// So if the latest update does not match the last cached update then it's still being edited // So if the latest update does not match the last cached update then it's still being edited
if (!tag.getString("Text").equals(session.getLastSignMessage())) { if (!text.equals(session.getLastSignMessage())) {
session.setLastSignMessage(tag.getString("Text")); session.setLastSignMessage(text);
return; return;
} }
// Otherwise the two messages are identical and we can get to work deconstructing // Otherwise the two messages are identical and we can get to work deconstructing
@ -59,7 +61,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
// If it goes over the maximum, we need to start a new line to match Java // If it goes over the maximum, we need to start a new line to match Java
int widthCount = 0; int widthCount = 0;
// This converts the message into the array'd message Java wants // This converts the message into the array'd message Java wants
for (char character : tag.getString("Text").toCharArray()) { for (char character : text.toCharArray()) {
widthCount += SignUtils.getCharacterWidth(character); widthCount += SignUtils.getCharacterWidth(character);
// If we get a return in Bedrock, or go over the character width max, that signals to use the next line. // If we get a return in Bedrock, or go over the character width max, that signals to use the next line.
if (character == '\n' || widthCount > SignUtils.JAVA_CHARACTER_WIDTH_MAX) { if (character == '\n' || widthCount > SignUtils.JAVA_CHARACTER_WIDTH_MAX) {
@ -111,7 +113,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
// We set the sign text cached in the session to null to indicate there is no work-in-progress sign // We set the sign text cached in the session to null to indicate there is no work-in-progress sign
session.setLastSignMessage(null); session.setLastSignMessage(null);
} else if (tag.getString("id").equals("JigsawBlock")) { } else if (id.equals("JigsawBlock")) {
// Client has just sent a jigsaw block update // Client has just sent a jigsaw block update
Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z")); Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
String name = tag.getString("name"); String name = tag.getString("name");

Datei anzeigen

@ -245,8 +245,8 @@ public class JavaEntityEventTranslator extends PacketTranslator<ClientboundEntit
float baseX = position.getX(); float baseX = position.getX();
float baseY = position.getY(); float baseY = position.getY();
float baseZ = position.getZ(); float baseZ = position.getZ();
float height = entity.getDefinition().height(); float height = entity.getBoundingBoxHeight();
float width = entity.getDefinition().width(); float width = entity.getBoundingBoxWidth();
Random random = ThreadLocalRandom.current(); Random random = ThreadLocalRandom.current();
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
// Reconstruct the Java Edition (1.18.1) logic, but in floats // Reconstruct the Java Edition (1.18.1) logic, but in floats

Datei anzeigen

@ -169,8 +169,8 @@ public class FileUtils {
* @return The byte array of the file * @return The byte array of the file
*/ */
public static byte[] readAllBytes(File file) { public static byte[] readAllBytes(File file) {
try (InputStream inputStream = new FileInputStream(file)) { try (InputStream stream = new FileInputStream(file)) {
return readAllBytes(inputStream); return stream.readAllBytes();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Cannot read " + file); throw new RuntimeException("Cannot read " + file);
} }
@ -182,30 +182,12 @@ public class FileUtils {
*/ */
public static byte[] readAllBytes(String resource) { public static byte[] readAllBytes(String resource) {
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(resource)) { try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(resource)) {
return readAllBytes(stream); return stream.readAllBytes();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Error while trying to read internal input stream!", e); throw new RuntimeException("Error while trying to read internal input stream!", e);
} }
} }
/**
* @param stream the InputStream to read off of
* @return the byte array of an InputStream
*/
public static byte[] readAllBytes(InputStream stream) {
try {
int size = stream.available();
byte[] bytes = new byte[size];
try (BufferedInputStream buf = new BufferedInputStream(stream)) {
//noinspection ResultOfMethodCallIgnored
buf.read(bytes, 0, bytes.length);
}
return bytes;
} catch (IOException e) {
throw new RuntimeException("Error while trying to read input stream!", e);
}
}
/** /**
* Read the lines of a file and return it as a stream * Read the lines of a file and return it as a stream
* *