Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-27 00:22:53 +01:00
Show entity names when replaced
Dieser Commit ist enthalten in:
Ursprung
a8e81935cc
Commit
95532bcdd5
@ -20,11 +20,17 @@ import lombok.ToString;
|
|||||||
public class EntityData {
|
public class EntityData {
|
||||||
private final int id;
|
private final int id;
|
||||||
private final boolean isObject;
|
private final boolean isObject;
|
||||||
|
private String mobName;
|
||||||
|
|
||||||
private final int replacementId;
|
private final int replacementId;
|
||||||
private final int objectData;
|
private final int objectData;
|
||||||
private MetaCreator defaultMeta;
|
private MetaCreator defaultMeta;
|
||||||
|
|
||||||
|
public EntityData mobName(String name) {
|
||||||
|
this.mobName = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void spawnMetadata(MetaCreator handler) {
|
public void spawnMetadata(MetaCreator handler) {
|
||||||
this.defaultMeta = handler;
|
this.defaultMeta = handler;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,10 @@
|
|||||||
|
|
||||||
package nl.matsv.viabackwards.api.rewriters;
|
package nl.matsv.viabackwards.api.rewriters;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
import nl.matsv.viabackwards.ViaBackwards;
|
import nl.matsv.viabackwards.ViaBackwards;
|
||||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||||
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerEvent;
|
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerEvent;
|
||||||
@ -23,7 +26,9 @@ import nl.matsv.viabackwards.api.entities.types.AbstractObjectType;
|
|||||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
|
||||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||||
|
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -39,6 +44,13 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
|||||||
private final Map<AbstractObjectType, EntityData> objectTypes = new ConcurrentHashMap<>();
|
private final Map<AbstractObjectType, EntityData> objectTypes = new ConcurrentHashMap<>();
|
||||||
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
|
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
@Setter(AccessLevel.PROTECTED)
|
||||||
|
private MetaType displayNameMetaType = MetaType1_9.String;
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
@Setter(AccessLevel.PROTECTED)
|
||||||
|
private int displayNameIndex = 2;
|
||||||
|
|
||||||
protected AbstractEntityType getEntityType(UserConnection connection, int id) {
|
protected AbstractEntityType getEntityType(UserConnection connection, int id) {
|
||||||
return getEntityTracker(connection).getEntityType(id);
|
return getEntityTracker(connection).getEntityType(id);
|
||||||
}
|
}
|
||||||
@ -115,6 +127,21 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
|||||||
newList.clear();
|
newList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle Entity Name
|
||||||
|
Optional<Metadata> opMd = storage.get(getDisplayNameIndex());
|
||||||
|
if (opMd.isPresent()) {
|
||||||
|
Optional<EntityData> opEd = getEntityData(type);
|
||||||
|
if (opEd.isPresent()) {
|
||||||
|
Metadata data = opMd.get();
|
||||||
|
EntityData entData = opEd.get();
|
||||||
|
if (entData.getMobName() != null &&
|
||||||
|
(data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
|
||||||
|
data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID())
|
||||||
|
data.setValue(entData.getMobName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,10 +402,10 @@ public class EntityPackets1_11 extends EntityRewriter<Protocol1_10To1_11> {
|
|||||||
regEntType(EntityType.ZOMBIE_HORSE, EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3)));
|
regEntType(EntityType.ZOMBIE_HORSE, EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3)));
|
||||||
// New mobs
|
// New mobs
|
||||||
regEntType(EntityType.EVOCATION_FANGS, EntityType.SHULKER);
|
regEntType(EntityType.EVOCATION_FANGS, EntityType.SHULKER);
|
||||||
regEntType(EntityType.EVOCATION_ILLAGER, EntityType.VILLAGER);
|
regEntType(EntityType.EVOCATION_ILLAGER, EntityType.VILLAGER).mobName("Evoker");
|
||||||
regEntType(EntityType.VEX, EntityType.BAT);
|
regEntType(EntityType.VEX, EntityType.BAT).mobName("Vex");
|
||||||
regEntType(EntityType.VINDICATION_ILLAGER, EntityType.VILLAGER).spawnMetadata(storage -> storage.add(new Metadata(13, MetaType1_9.VarInt, 4))); // Base Profession
|
regEntType(EntityType.VINDICATION_ILLAGER, EntityType.VILLAGER).mobName("Vindicator").spawnMetadata(storage -> storage.add(new Metadata(13, MetaType1_9.VarInt, 4))); // Base Profession
|
||||||
regEntType(EntityType.LIAMA, EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1))); // TODO fix chest slots
|
regEntType(EntityType.LIAMA, EntityType.HORSE).mobName("Llama").spawnMetadata(storage -> storage.add(getHorseMetaType(1))); // TODO fix chest slots
|
||||||
regEntType(EntityType.LIAMA_SPIT, EntityType.SNOWBALL);
|
regEntType(EntityType.LIAMA_SPIT, EntityType.SNOWBALL);
|
||||||
|
|
||||||
regObjType(ObjectType.LIAMA_SPIT, ObjectType.SNOWBALL, -1);
|
regObjType(ObjectType.LIAMA_SPIT, ObjectType.SNOWBALL, -1);
|
||||||
|
@ -282,7 +282,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
|
|||||||
.repItem(new Item((short) 340, (byte) 1, (short) 0, getNamedTag("1.12 Knowledge Book"))); // TODO glow
|
.repItem(new Item((short) 340, (byte) 1, (short) 0, getNamedTag("1.12 Knowledge Book"))); // TODO glow
|
||||||
|
|
||||||
// Glazed Terracotta -> Stained Clay
|
// Glazed Terracotta -> Stained Clay
|
||||||
for (int i = 235; i < 250; i++) {
|
for (int i = 235; i < 251; i++) {
|
||||||
rewrite(i).repItem(new Item((short) 159, (byte) 1, (short) (i - 235), getNamedTag("1.12 Glazed Terracotta")))
|
rewrite(i).repItem(new Item((short) 159, (byte) 1, (short) (i - 235), getNamedTag("1.12 Glazed Terracotta")))
|
||||||
.repBlock(new Block(159, (i - 235))); // TODO color provided by name
|
.repBlock(new Block(159, (i - 235))); // TODO color provided by name
|
||||||
}
|
}
|
||||||
|
@ -359,8 +359,8 @@ public class EntityPackets1_12 extends EntityRewriter<Protocol1_11_1To1_12> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
regEntType(EntityType.PARROT, EntityType.BAT).spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
|
regEntType(EntityType.PARROT, EntityType.BAT).mobName("Parrot").spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
|
||||||
regEntType(EntityType.ILLUSION_ILLAGER, EntityType.EVOCATION_ILLAGER);
|
regEntType(EntityType.ILLUSION_ILLAGER, EntityType.EVOCATION_ILLAGER).mobName("Illusioner");
|
||||||
|
|
||||||
// Handle Illager TODO wtf does this metadata do? Is aggresive it is a bitmask?
|
// Handle Illager TODO wtf does this metadata do? Is aggresive it is a bitmask?
|
||||||
registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 12).removed();
|
registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 12).removed();
|
||||||
|
@ -365,7 +365,7 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerRewrites() {
|
protected void registerRewrites() {
|
||||||
regEntType(EntityType.POLAR_BEAR, EntityType.SHEEP);
|
regEntType(EntityType.POLAR_BEAR, EntityType.SHEEP).mobName("Polar Bear");
|
||||||
|
|
||||||
// Change the sheep color when the polar bear is standing up (index 13 -> Standing up)
|
// Change the sheep color when the polar bear is standing up (index 13 -> Standing up)
|
||||||
registerMetaHandler().filter(EntityType.POLAR_BEAR, 13).handle((e -> {
|
registerMetaHandler().filter(EntityType.POLAR_BEAR, 13).handle((e -> {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren