Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 15:00:11 +01:00
Addressed review
Dieser Commit ist enthalten in:
Ursprung
8d391a63ec
Commit
d1c0eebbf1
@ -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) {
|
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.session = session;
|
||||||
this.displayName = EntityUtils.entityTypeName(definition.entityType());
|
this.displayName = standardDisplayName();
|
||||||
|
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
this.geyserId = geyserId;
|
this.geyserId = geyserId;
|
||||||
@ -435,10 +435,14 @@ public class Entity implements GeyserEntity {
|
|||||||
|
|
||||||
// if no displayName is set, use entity name (ENDER_DRAGON -> Ender Dragon)
|
// if no displayName is set, use entity name (ENDER_DRAGON -> Ender Dragon)
|
||||||
// maybe we can/should use a translatable here instead?
|
// maybe we can/should use a translatable here instead?
|
||||||
this.displayName = EntityUtils.entityTypeName(definition.entityType());
|
this.displayName = standardDisplayName();
|
||||||
setNametag(null, true);
|
setNametag(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String standardDisplayName() {
|
||||||
|
return EntityUtils.translatedEntityName(definition.entityType(), session);
|
||||||
|
}
|
||||||
|
|
||||||
protected void setNametag(@Nullable String nametag, boolean fromDisplayName) {
|
protected void setNametag(@Nullable String nametag, boolean fromDisplayName) {
|
||||||
// ensure that the team format is used when nametag changes
|
// ensure that the team format is used when nametag changes
|
||||||
if (nametag != null && fromDisplayName) {
|
if (nametag != null && fromDisplayName) {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.entity.type.living.animal;
|
package org.geysermc.geyser.entity.type.living.animal;
|
||||||
|
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.cloudburstmc.math.vector.Vector3f;
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
|
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.entity.EntityDefinition;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.session.cache.tags.ItemTag;
|
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 org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class RabbitEntity extends AnimalEntity {
|
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) {
|
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);
|
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||||
@ -46,7 +49,7 @@ public class RabbitEntity extends AnimalEntity {
|
|||||||
int variant = entityMetadata.getPrimitiveValue();
|
int variant = entityMetadata.getPrimitiveValue();
|
||||||
|
|
||||||
// Change the killer bunny to display as white since it only exists on Java Edition
|
// Change the killer bunny to display as white since it only exists on Java Edition
|
||||||
boolean isKillerBunny = variant == 99;
|
isKillerBunny = variant == 99;
|
||||||
if (isKillerBunny) {
|
if (isKillerBunny) {
|
||||||
variant = 1;
|
variant = 1;
|
||||||
}
|
}
|
||||||
@ -56,6 +59,14 @@ public class RabbitEntity extends AnimalEntity {
|
|||||||
dirtyMetadata.put(EntityDataTypes.VARIANT, variant);
|
dirtyMetadata.put(EntityDataTypes.VARIANT, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String standardDisplayName() {
|
||||||
|
if (isKillerBunny) {
|
||||||
|
return EntityUtils.translatedEntityName(Key.key("killer_bunny"), session);
|
||||||
|
}
|
||||||
|
return super.standardDisplayName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getAdultSize() {
|
protected float getAdultSize() {
|
||||||
return 0.55f;
|
return 0.55f;
|
||||||
@ -71,4 +82,4 @@ public class RabbitEntity extends AnimalEntity {
|
|||||||
protected ItemTag getFoodTag() {
|
protected ItemTag getFoodTag() {
|
||||||
return ItemTag.RABBIT_FOOD;
|
return ItemTag.RABBIT_FOOD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,10 +252,6 @@ public final class Scoreboard {
|
|||||||
return objectives.get(objectiveName);
|
return objectives.get(objectiveName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Objective> getObjectives() {
|
|
||||||
return objectives.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeObjective(Objective objective) {
|
public void removeObjective(Objective objective) {
|
||||||
objectives.remove(objective.getObjectiveName());
|
objectives.remove(objective.getObjectiveName());
|
||||||
for (DisplaySlot slot : objective.getActiveSlots()) {
|
for (DisplaySlot slot : objective.getActiveSlots()) {
|
||||||
|
@ -72,7 +72,7 @@ public final class Team {
|
|||||||
|
|
||||||
// doesn't call entity update
|
// doesn't call entity update
|
||||||
updateProperties(name, prefix, suffix, visibility, color);
|
updateProperties(name, prefix, suffix, visibility, color);
|
||||||
// calls entitity update
|
// calls entity update
|
||||||
addEntities(players);
|
addEntities(players);
|
||||||
lastUpdate = LAST_UPDATE_DEFAULT;
|
lastUpdate = LAST_UPDATE_DEFAULT;
|
||||||
}
|
}
|
||||||
@ -290,14 +290,6 @@ public final class Team {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String prefix() {
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String suffix() {
|
|
||||||
return suffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long lastUpdate() {
|
public long lastUpdate() {
|
||||||
return lastUpdate;
|
return lastUpdate;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ public class BelownameDisplaySlot extends DisplaySlot {
|
|||||||
if (numberFormat instanceof BlankFormat) {
|
if (numberFormat instanceof BlankFormat) {
|
||||||
numberString = "";
|
numberString = "";
|
||||||
} else if (numberFormat instanceof FixedFormat fixedFormat) {
|
} else if (numberFormat instanceof FixedFormat fixedFormat) {
|
||||||
numberString = MessageTranslator.convertMessage(fixedFormat.getValue());
|
numberString = MessageTranslator.convertMessage(fixedFormat.getValue(), session.locale());
|
||||||
} else if (numberFormat instanceof StyledFormat styledFormat) {
|
} else if (numberFormat instanceof StyledFormat styledFormat) {
|
||||||
NbtMapBuilder styledAmount = styledFormat.getStyle().toBuilder();
|
NbtMapBuilder styledAmount = styledFormat.getStyle().toBuilder();
|
||||||
styledAmount.putString("text", String.valueOf(score));
|
styledAmount.putString("text", String.valueOf(score));
|
||||||
|
@ -128,7 +128,6 @@ public final class SidebarDisplaySlot extends DisplaySlot {
|
|||||||
|
|
||||||
if (team != null) {
|
if (team != null) {
|
||||||
// entities are mostly removed from teams without notifying the scores.
|
// entities are mostly removed from teams without notifying the scores.
|
||||||
// Note that
|
|
||||||
if (team.shouldRemove() || !team.hasEntity(score.name())) {
|
if (team.shouldRemove() || !team.hasEntity(score.name())) {
|
||||||
score.team(null);
|
score.team(null);
|
||||||
add = true;
|
add = true;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.util;
|
package org.geysermc.geyser.util;
|
||||||
|
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
import org.cloudburstmc.math.vector.Vector3f;
|
import org.cloudburstmc.math.vector.Vector3f;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.GameType;
|
import org.cloudburstmc.protocol.bedrock.data.GameType;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
|
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.entity.type.living.animal.horse.CamelEntity;
|
||||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||||
import org.geysermc.geyser.item.Items;
|
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.Effect;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||||
@ -290,26 +293,18 @@ public final class EntityUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String entityTypeName(EntityType type) {
|
private static String translatedEntityName(String namespace, String name, GeyserSession session) {
|
||||||
var typeName = type.name();
|
return MinecraftLocale.getLocaleString("entity." + namespace + "." + name, session.locale());
|
||||||
var builder = new StringBuilder();
|
}
|
||||||
|
|
||||||
boolean upNext = true;
|
public static String translatedEntityName(Key type, GeyserSession session) {
|
||||||
for (int i = 0; i < typeName.length(); i++) {
|
return translatedEntityName(type.namespace(), type.value(), session);
|
||||||
char c = typeName.charAt(i);
|
}
|
||||||
if ('_' == c) {
|
|
||||||
upNext = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enums are upper case by default
|
public static String translatedEntityName(EntityType type, GeyserSession session) {
|
||||||
if (!upNext) {
|
// this works at least with all 1.20.5 entities, except the killer bunny since that's not an entity type.
|
||||||
c = Character.toLowerCase(c);
|
var typeName = type.name().toLowerCase(Locale.ROOT);
|
||||||
}
|
return translatedEntityName("minecraft", typeName, session);
|
||||||
builder.append(c);
|
|
||||||
upNext = false;
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityUtils() {
|
private EntityUtils() {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren