3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 15:00:11 +01:00

Addressed review

Dieser Commit ist enthalten in:
Tim203 2024-09-24 21:14:10 +02:00
Ursprung 8d391a63ec
Commit d1c0eebbf1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
7 geänderte Dateien mit 34 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -132,7 +132,7 @@ public class Entity implements GeyserEntity {
public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
this.session = session;
this.displayName = EntityUtils.entityTypeName(definition.entityType());
this.displayName = standardDisplayName();
this.entityId = entityId;
this.geyserId = geyserId;
@ -435,10 +435,14 @@ public class Entity implements GeyserEntity {
// if no displayName is set, use entity name (ENDER_DRAGON -> Ender Dragon)
// maybe we can/should use a translatable here instead?
this.displayName = EntityUtils.entityTypeName(definition.entityType());
this.displayName = standardDisplayName();
setNametag(null, true);
}
protected String standardDisplayName() {
return EntityUtils.translatedEntityName(definition.entityType(), session);
}
protected void setNametag(@Nullable String nametag, boolean fromDisplayName) {
// ensure that the team format is used when nametag changes
if (nametag != null && fromDisplayName) {

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.entity.type.living.animal;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
@ -32,11 +33,13 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.geyser.util.EntityUtils;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import java.util.UUID;
public class RabbitEntity extends AnimalEntity {
private boolean isKillerBunny;
public RabbitEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@ -46,7 +49,7 @@ public class RabbitEntity extends AnimalEntity {
int variant = entityMetadata.getPrimitiveValue();
// Change the killer bunny to display as white since it only exists on Java Edition
boolean isKillerBunny = variant == 99;
isKillerBunny = variant == 99;
if (isKillerBunny) {
variant = 1;
}
@ -56,6 +59,14 @@ public class RabbitEntity extends AnimalEntity {
dirtyMetadata.put(EntityDataTypes.VARIANT, variant);
}
@Override
protected String standardDisplayName() {
if (isKillerBunny) {
return EntityUtils.translatedEntityName(Key.key("killer_bunny"), session);
}
return super.standardDisplayName();
}
@Override
protected float getAdultSize() {
return 0.55f;

Datei anzeigen

@ -252,10 +252,6 @@ public final class Scoreboard {
return objectives.get(objectiveName);
}
public Collection<Objective> getObjectives() {
return objectives.values();
}
public void removeObjective(Objective objective) {
objectives.remove(objective.getObjectiveName());
for (DisplaySlot slot : objective.getActiveSlots()) {

Datei anzeigen

@ -72,7 +72,7 @@ public final class Team {
// doesn't call entity update
updateProperties(name, prefix, suffix, visibility, color);
// calls entitity update
// calls entity update
addEntities(players);
lastUpdate = LAST_UPDATE_DEFAULT;
}
@ -290,14 +290,6 @@ public final class Team {
return color;
}
public String prefix() {
return prefix;
}
public String suffix() {
return suffix;
}
public long lastUpdate() {
return lastUpdate;
}

Datei anzeigen

@ -162,7 +162,7 @@ public class BelownameDisplaySlot extends DisplaySlot {
if (numberFormat instanceof BlankFormat) {
numberString = "";
} else if (numberFormat instanceof FixedFormat fixedFormat) {
numberString = MessageTranslator.convertMessage(fixedFormat.getValue());
numberString = MessageTranslator.convertMessage(fixedFormat.getValue(), session.locale());
} else if (numberFormat instanceof StyledFormat styledFormat) {
NbtMapBuilder styledAmount = styledFormat.getStyle().toBuilder();
styledAmount.putString("text", String.valueOf(score));

Datei anzeigen

@ -128,7 +128,6 @@ public final class SidebarDisplaySlot extends DisplaySlot {
if (team != null) {
// entities are mostly removed from teams without notifying the scores.
// Note that
if (team.shouldRemove() || !team.hasEntity(score.name())) {
score.team(null);
add = true;

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.util;
import net.kyori.adventure.key.Key;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.GameType;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
@ -38,6 +39,8 @@ import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
import org.geysermc.geyser.entity.type.living.animal.horse.CamelEntity;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
@ -290,26 +293,18 @@ public final class EntityUtils {
};
}
public static String entityTypeName(EntityType type) {
var typeName = type.name();
var builder = new StringBuilder();
boolean upNext = true;
for (int i = 0; i < typeName.length(); i++) {
char c = typeName.charAt(i);
if ('_' == c) {
upNext = true;
continue;
private static String translatedEntityName(String namespace, String name, GeyserSession session) {
return MinecraftLocale.getLocaleString("entity." + namespace + "." + name, session.locale());
}
// enums are upper case by default
if (!upNext) {
c = Character.toLowerCase(c);
public static String translatedEntityName(Key type, GeyserSession session) {
return translatedEntityName(type.namespace(), type.value(), session);
}
builder.append(c);
upNext = false;
}
return builder.toString();
public static String translatedEntityName(EntityType type, GeyserSession session) {
// this works at least with all 1.20.5 entities, except the killer bunny since that's not an entity type.
var typeName = type.name().toLowerCase(Locale.ROOT);
return translatedEntityName("minecraft", typeName, session);
}
private EntityUtils() {