mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-18 16:17:45 +01:00
Show entity names when replaced
This commit is contained in:
parent
a8e81935cc
commit
95532bcdd5
@ -20,11 +20,17 @@ import lombok.ToString;
|
||||
public class EntityData {
|
||||
private final int id;
|
||||
private final boolean isObject;
|
||||
private String mobName;
|
||||
|
||||
private final int replacementId;
|
||||
private final int objectData;
|
||||
private MetaCreator defaultMeta;
|
||||
|
||||
public EntityData mobName(String name) {
|
||||
this.mobName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void spawnMetadata(MetaCreator handler) {
|
||||
this.defaultMeta = handler;
|
||||
}
|
||||
|
@ -10,7 +10,10 @@
|
||||
|
||||
package nl.matsv.viabackwards.api.rewriters;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
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 us.myles.ViaVersion.api.Via;
|
||||
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.types.MetaType1_9;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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 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) {
|
||||
return getEntityTracker(connection).getEntityType(id);
|
||||
}
|
||||
@ -115,6 +127,21 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Rewrit
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
// New mobs
|
||||
regEntType(EntityType.EVOCATION_FANGS, EntityType.SHULKER);
|
||||
regEntType(EntityType.EVOCATION_ILLAGER, EntityType.VILLAGER);
|
||||
regEntType(EntityType.VEX, EntityType.BAT);
|
||||
regEntType(EntityType.VINDICATION_ILLAGER, EntityType.VILLAGER).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.EVOCATION_ILLAGER, EntityType.VILLAGER).mobName("Evoker");
|
||||
regEntType(EntityType.VEX, EntityType.BAT).mobName("Vex");
|
||||
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).mobName("Llama").spawnMetadata(storage -> storage.add(getHorseMetaType(1))); // TODO fix chest slots
|
||||
regEntType(EntityType.LIAMA_SPIT, EntityType.SNOWBALL);
|
||||
|
||||
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
|
||||
|
||||
// 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")))
|
||||
.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
|
||||
protected void registerRewrites() {
|
||||
regEntType(EntityType.PARROT, EntityType.BAT).spawnMetadata(storage -> storage.add(new Metadata(12, MetaType1_12.Byte, (byte) 0x00)));
|
||||
regEntType(EntityType.ILLUSION_ILLAGER, EntityType.EVOCATION_ILLAGER);
|
||||
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).mobName("Illusioner");
|
||||
|
||||
// Handle Illager TODO wtf does this metadata do? Is aggresive it is a bitmask?
|
||||
registerMetaHandler().filter(EntityType.EVOCATION_ILLAGER, true, 12).removed();
|
||||
|
@ -365,7 +365,7 @@ public class EntityPackets1_10 extends EntityRewriter<Protocol1_9_4To1_10> {
|
||||
|
||||
@Override
|
||||
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)
|
||||
registerMetaHandler().filter(EntityType.POLAR_BEAR, 13).handle((e -> {
|
||||
|
Loading…
Reference in New Issue
Block a user