mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-14 10:55:20 +01:00
More entity rewriter cleanup
This commit is contained in:
parent
a4ed18f59b
commit
d6fe7914e8
@ -10,20 +10,22 @@
|
||||
|
||||
package nl.matsv.viabackwards.api.entities.storage;
|
||||
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
|
||||
public class EntityData {
|
||||
private final int id;
|
||||
private final boolean isObject;
|
||||
private String mobName;
|
||||
|
||||
private final int replacementId;
|
||||
private final int objectData;
|
||||
private String mobName;
|
||||
private MetaCreator defaultMeta;
|
||||
|
||||
public EntityData(int id, boolean isObject, int replacementId, int objectData) {
|
||||
public EntityData(int id, int replacementId) {
|
||||
this.id = id;
|
||||
this.isObject = isObject;
|
||||
this.replacementId = replacementId;
|
||||
this.objectData = objectData;
|
||||
}
|
||||
|
||||
public EntityData jsonName(String name) {
|
||||
this.mobName = ChatRewriter.legacyTextToJson(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityData mobName(String name) {
|
||||
@ -43,10 +45,6 @@ public class EntityData {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
return isObject;
|
||||
}
|
||||
|
||||
public String getMobName() {
|
||||
return mobName;
|
||||
}
|
||||
@ -55,28 +53,31 @@ public class EntityData {
|
||||
return replacementId;
|
||||
}
|
||||
|
||||
public int getObjectData() {
|
||||
return objectData;
|
||||
}
|
||||
|
||||
public MetaCreator getDefaultMeta() {
|
||||
return defaultMeta;
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getObjectData() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityData{" +
|
||||
"id=" + id +
|
||||
", isObject=" + isObject +
|
||||
", mobName='" + mobName + '\'' +
|
||||
", replacementId=" + replacementId +
|
||||
", objectData=" + objectData +
|
||||
", defaultMeta=" + defaultMeta +
|
||||
'}';
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MetaCreator {
|
||||
|
||||
void handle(MetaStorage storage);
|
||||
void createMeta(MetaStorage storage);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package nl.matsv.viabackwards.api.entities.storage;
|
||||
|
||||
public class EntityObjectData extends EntityData {
|
||||
private final boolean isObject;
|
||||
private final int objectData;
|
||||
|
||||
public EntityObjectData(int id, boolean isObject, int replacementId, int objectData) {
|
||||
super(id, replacementId);
|
||||
this.isObject = isObject;
|
||||
this.objectData = objectData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObject() {
|
||||
return isObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getObjectData() {
|
||||
return objectData;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package nl.matsv.viabackwards.api.entities.storage.object;
|
||||
package nl.matsv.viabackwards.api.entities.storage;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
@ -3,6 +3,7 @@ package nl.matsv.viabackwards.api.rewriters;
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
@ -16,11 +17,11 @@ import java.util.List;
|
||||
public abstract class EntityRewriter<T extends BackwardsProtocol> extends EntityRewriterBase<T> {
|
||||
|
||||
protected EntityRewriter(T protocol) {
|
||||
super(protocol, MetaType1_14.OptChat, 2, true);
|
||||
super(protocol, MetaType1_14.OptChat, 2);
|
||||
}
|
||||
|
||||
protected EntityRewriter(T protocol, MetaType displayType) {
|
||||
super(protocol, displayType, 2, true);
|
||||
super(protocol, displayType, 2);
|
||||
}
|
||||
|
||||
public void registerSpawnTrackerWithData(int oldPacketId, int newPacketId, EntityType fallingBlockType, ItemRewriter itemRewriter) {
|
||||
@ -37,15 +38,7 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
|
||||
map(Type.BYTE); // 7 - Yaw
|
||||
map(Type.INT); // 8 - Data
|
||||
handler(wrapper -> {
|
||||
int typeId = wrapper.get(Type.VAR_INT, 1);
|
||||
EntityType entityType = getTypeFromId(typeId);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
int oldTypeId = getOldEntityId(entityType.getId());
|
||||
if (typeId != oldTypeId) {
|
||||
wrapper.set(Type.VAR_INT, 1, oldTypeId);
|
||||
}
|
||||
|
||||
EntityType entityType = setOldEntityId(wrapper);
|
||||
if (entityType == fallingBlockType) {
|
||||
int blockState = wrapper.get(Type.INT, 0);
|
||||
wrapper.set(Type.INT, 0, itemRewriter.toClientRewriter.rewrite(blockState));
|
||||
@ -62,20 +55,24 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.UUID); // 1 - Entity UUID
|
||||
map(Type.VAR_INT); // 2 - Entity Type
|
||||
handler(wrapper -> {
|
||||
int typeId = wrapper.get(Type.VAR_INT, 1);
|
||||
EntityType entityType = getTypeFromId(typeId);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
int oldTypeId = getOldEntityId(entityType.getId());
|
||||
if (typeId != oldTypeId) {
|
||||
wrapper.set(Type.VAR_INT, 1, oldTypeId);
|
||||
}
|
||||
});
|
||||
handler(wrapper -> setOldEntityId(wrapper));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private EntityType setOldEntityId(PacketWrapper wrapper) throws Exception {
|
||||
int typeId = wrapper.get(Type.VAR_INT, 1);
|
||||
EntityType entityType = getTypeFromId(typeId);
|
||||
addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), entityType);
|
||||
|
||||
int oldTypeId = getOldEntityId(entityType.getId());
|
||||
if (typeId != oldTypeId) {
|
||||
wrapper.set(Type.VAR_INT, 1, oldTypeId);
|
||||
}
|
||||
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to handle a metadata list packet and its full initial meta rewrite.
|
||||
*/
|
||||
@ -97,9 +94,10 @@ public abstract class EntityRewriter<T extends BackwardsProtocol> extends Entity
|
||||
handleMeta(wrapper.user(), entityId, storage);
|
||||
|
||||
EntityData entityData = getEntityData(type);
|
||||
//TODO only do this once for a first meta packet?
|
||||
if (entityData != null) {
|
||||
if (entityData.hasBaseMeta()) {
|
||||
entityData.getDefaultMeta().handle(storage);
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nl.matsv.viabackwards.api.rewriters;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import nl.matsv.viabackwards.api.entities.meta.MetaHandlerEvent;
|
||||
@ -20,31 +21,28 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Rewriter<T> {
|
||||
private final Map<EntityType, EntityData> entityTypes = new ConcurrentHashMap<>();
|
||||
private final Map<EntityType, EntityData> entityTypes = new HashMap<>();
|
||||
private final List<MetaHandlerSettings> metaHandlers = new ArrayList<>();
|
||||
private final MetaType displayNameMetaType;
|
||||
private final int displayNameIndex;
|
||||
private final boolean isDisplayNameJson;
|
||||
|
||||
protected EntityRewriterBase(T protocol) {
|
||||
this(protocol, MetaType1_9.String, 2, false);
|
||||
this(protocol, MetaType1_9.String, 2);
|
||||
}
|
||||
|
||||
protected EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex, boolean isDisplayNameJson) {
|
||||
protected EntityRewriterBase(T protocol, MetaType displayNameMetaType, int displayNameIndex) {
|
||||
super(protocol);
|
||||
this.displayNameMetaType = displayNameMetaType;
|
||||
this.displayNameIndex = displayNameIndex;
|
||||
this.isDisplayNameJson = isDisplayNameJson;
|
||||
}
|
||||
|
||||
protected EntityType getEntityType(UserConnection connection, int id) {
|
||||
@ -64,7 +62,10 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
}
|
||||
|
||||
protected EntityData mapEntity(EntityType oldType, EntityType replacement) {
|
||||
EntityData data = new EntityData(oldType.getId(), false, replacement.getId(), -1);
|
||||
Preconditions.checkArgument(oldType.getClass() == replacement.getClass());
|
||||
|
||||
// Already rewrite the id here
|
||||
EntityData data = new EntityData(oldType.getId(), getOldEntityId(replacement.getId()));
|
||||
entityTypes.put(oldType, data);
|
||||
return data;
|
||||
}
|
||||
@ -137,11 +138,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
if (entityData.getMobName() != null &&
|
||||
(data.getValue() == null || ((String) data.getValue()).isEmpty()) &&
|
||||
data.getMetaType().getTypeID() == displayNameMetaType.getTypeID()) {
|
||||
String mobName = entityData.getMobName();
|
||||
if (isDisplayNameJson) {
|
||||
mobName = ChatRewriter.legacyTextToJson(mobName);
|
||||
}
|
||||
data.setValue(mobName);
|
||||
data.setValue(entityData.getMobName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package nl.matsv.viabackwards.api.rewriters;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.BackwardsProtocol;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityObjectData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.entities.ObjectType;
|
||||
@ -12,23 +14,24 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends EntityRewriterBase<T> {
|
||||
private final Map<ObjectType, EntityData> objectTypes = new ConcurrentHashMap<>();
|
||||
private final Map<ObjectType, EntityData> objectTypes = new HashMap<>();
|
||||
|
||||
protected LegacyEntityRewriter(T protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
||||
protected LegacyEntityRewriter(T protocol, MetaType displayType, boolean isDisplayJson) {
|
||||
super(protocol, displayType, 2, isDisplayJson);
|
||||
protected LegacyEntityRewriter(T protocol, MetaType displayType) {
|
||||
super(protocol, displayType, 2);
|
||||
}
|
||||
|
||||
protected EntityData mapObjectType(ObjectType oldObjectType, ObjectType replacement, int data) {
|
||||
EntityData entData = new EntityData(oldObjectType.getId(), true, replacement.getId(), data);
|
||||
protected EntityObjectData mapObjectType(ObjectType oldObjectType, ObjectType replacement, int data) {
|
||||
EntityObjectData entData = new EntityObjectData(oldObjectType.getId(), true, replacement.getId(), data);
|
||||
objectTypes.put(oldObjectType, entData);
|
||||
return entData;
|
||||
}
|
||||
@ -70,10 +73,9 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
|
||||
EntityData entityData = getEntityData(type);
|
||||
if (entityData != null) {
|
||||
int replacementId = getOldEntityId(entityData.getReplacementId());
|
||||
wrapper.set(Type.VAR_INT, 1, replacementId);
|
||||
wrapper.set(Type.VAR_INT, 1, entityData.getReplacementId());
|
||||
if (entityData.hasBaseMeta()) {
|
||||
entityData.getDefaultMeta().handle(storage);
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,6 +98,24 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
};
|
||||
}
|
||||
|
||||
protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGetter) {
|
||||
return wrapper -> {
|
||||
ObjectType type = objectGetter.apply(wrapper.get(Type.BYTE, 0));
|
||||
if (type == null) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
EntityData data = getObjectData(type);
|
||||
if (data != null) {
|
||||
wrapper.set(Type.BYTE, 0, (byte) data.getReplacementId());
|
||||
if (data.getObjectData() != -1) {
|
||||
wrapper.set(Type.INT, 0, data.getObjectData());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected EntityType getObjectTypeFromId(int typeId) {
|
||||
return getTypeFromId(typeId);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
@ -20,7 +19,6 @@ import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
@ -81,26 +79,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
|
||||
// Track Entity
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Optional<Entity1_11Types.ObjectType> type = Entity1_11Types.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
|
||||
if (type.isPresent()) {
|
||||
EntityData data = getObjectData(type.get());
|
||||
if (data != null) {
|
||||
wrapper.set(Type.BYTE, 0, ((Integer) data.getReplacementId()).byteValue());
|
||||
if (data.getObjectData() != -1)
|
||||
wrapper.set(Type.INT, 0, data.getObjectData());
|
||||
}
|
||||
} else {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
handler(getObjectRewriter(id -> Entity1_11Types.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
// Handle FallingBlock blocks
|
||||
handler(new PacketHandler() {
|
||||
@ -168,7 +147,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
if (entityData != null) {
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.getReplacementId());
|
||||
if (entityData.hasBaseMeta()) {
|
||||
entityData.getDefaultMeta().handle(storage);
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,10 +239,10 @@ public class EntityPackets1_11 extends LegacyEntityRewriter<Protocol1_10To1_11>
|
||||
// Guardian
|
||||
mapEntity(Entity1_11Types.EntityType.ELDER_GUARDIAN, Entity1_11Types.EntityType.GUARDIAN);
|
||||
// Skeletons
|
||||
mapEntity(Entity1_11Types.EntityType.WITHER_SKELETON, Entity1_11Types.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1)));
|
||||
mapEntity(Entity1_11Types.EntityType.STRAY, Entity1_11Types.EntityType.SKELETON).spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2)));
|
||||
mapEntity(Entity1_11Types.EntityType.WITHER_SKELETON, Entity1_11Types.EntityType.SKELETON).mobName("Wither Skeleton").spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(1)));
|
||||
mapEntity(Entity1_11Types.EntityType.STRAY, Entity1_11Types.EntityType.SKELETON).mobName("Stray").spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2)));
|
||||
// Zombies
|
||||
mapEntity(Entity1_11Types.EntityType.HUSK, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 6));
|
||||
mapEntity(Entity1_11Types.EntityType.HUSK, Entity1_11Types.EntityType.ZOMBIE).mobName("Husk").spawnMetadata(storage -> handleZombieType(storage, 6));
|
||||
mapEntity(Entity1_11Types.EntityType.ZOMBIE_VILLAGER, Entity1_11Types.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1));
|
||||
// Horses
|
||||
mapEntity(Entity1_11Types.EntityType.HORSE, Entity1_11Types.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(0))); // Nob able to ride the horse without having the MetaType sent.
|
||||
|
@ -10,8 +10,6 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
|
||||
@ -19,7 +17,6 @@ import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ParrotStorage;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.data.ShoulderTracker;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
@ -57,26 +54,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter<Protocol1_11_1To1_12
|
||||
|
||||
// Track Entity
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Optional<Entity1_12Types.ObjectType> type = Entity1_12Types.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
|
||||
if (type.isPresent()) {
|
||||
EntityData data = getObjectData(type.get());
|
||||
if (data != null) {
|
||||
wrapper.set(Type.BYTE, 0, ((Integer) data.getReplacementId()).byteValue());
|
||||
if (data.getObjectData() != -1)
|
||||
wrapper.set(Type.INT, 0, data.getObjectData());
|
||||
}
|
||||
} else {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
handler(getObjectRewriter(id -> Entity1_12Types.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
// Handle FallingBlock blocks
|
||||
handler(new PacketHandler() {
|
||||
|
@ -10,22 +10,15 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11_1> {
|
||||
|
||||
public EntityPackets1_11_1(Protocol1_11To1_11_1 protocol) {
|
||||
@ -50,26 +43,7 @@ public class EntityPackets1_11_1 extends LegacyEntityRewriter<Protocol1_11To1_11
|
||||
|
||||
// Track Entity
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Optional<Entity1_11Types.ObjectType> type = Entity1_11Types.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
|
||||
if (type.isPresent()) {
|
||||
EntityData data = getObjectData(type.get());
|
||||
if (data != null) {
|
||||
wrapper.set(Type.BYTE, 0, ((Integer) data.getReplacementId()).byteValue());
|
||||
if (data.getObjectData() != -1)
|
||||
wrapper.set(Type.INT, 0, data.getObjectData());
|
||||
}
|
||||
} else {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
handler(getObjectRewriter(id -> Entity1_11Types.ObjectType.findById(id).orElse(null)));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage;
|
||||
|
||||
import nl.matsv.viabackwards.api.entities.storage.object.PlayerPositionStorage;
|
||||
import nl.matsv.viabackwards.api.entities.storage.PlayerPositionStorage;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
|
||||
public class PlayerPositionStorage1_13 extends PlayerPositionStorage {
|
||||
|
@ -34,7 +34,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
private EntityPositionHandler positionHandler;
|
||||
|
||||
public EntityPackets1_14(Protocol1_13_2To1_14 protocol) {
|
||||
super(protocol, MetaType1_13_2.OptChat, true);
|
||||
super(protocol, MetaType1_13_2.OptChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -315,13 +315,13 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
|
||||
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
mapEntity(Entity1_14Types.EntityType.CAT, Entity1_14Types.EntityType.OCELOT).mobName("Cat");
|
||||
mapEntity(Entity1_14Types.EntityType.TRADER_LLAMA, Entity1_14Types.EntityType.LLAMA).mobName("Trader Llama");
|
||||
mapEntity(Entity1_14Types.EntityType.FOX, Entity1_14Types.EntityType.WOLF).mobName("Fox");
|
||||
mapEntity(Entity1_14Types.EntityType.PANDA, Entity1_14Types.EntityType.POLAR_BEAR).mobName("Panda");
|
||||
mapEntity(Entity1_14Types.EntityType.PILLAGER, Entity1_14Types.EntityType.VILLAGER).mobName("Pillager");
|
||||
mapEntity(Entity1_14Types.EntityType.WANDERING_TRADER, Entity1_14Types.EntityType.VILLAGER).mobName("Wandering Trader");
|
||||
mapEntity(Entity1_14Types.EntityType.RAVAGER, Entity1_14Types.EntityType.COW).mobName("Ravager");
|
||||
mapEntity(Entity1_14Types.EntityType.CAT, Entity1_14Types.EntityType.OCELOT).jsonName("Cat");
|
||||
mapEntity(Entity1_14Types.EntityType.TRADER_LLAMA, Entity1_14Types.EntityType.LLAMA).jsonName("Trader Llama");
|
||||
mapEntity(Entity1_14Types.EntityType.FOX, Entity1_14Types.EntityType.WOLF).jsonName("Fox");
|
||||
mapEntity(Entity1_14Types.EntityType.PANDA, Entity1_14Types.EntityType.POLAR_BEAR).jsonName("Panda");
|
||||
mapEntity(Entity1_14Types.EntityType.PILLAGER, Entity1_14Types.EntityType.VILLAGER).jsonName("Pillager");
|
||||
mapEntity(Entity1_14Types.EntityType.WANDERING_TRADER, Entity1_14Types.EntityType.VILLAGER).jsonName("Wandering Trader");
|
||||
mapEntity(Entity1_14Types.EntityType.RAVAGER, Entity1_14Types.EntityType.COW).jsonName("Ravager");
|
||||
|
||||
registerMetaHandler().handle(e -> {
|
||||
Metadata meta = e.getData();
|
||||
|
@ -230,7 +230,7 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
registerMetaHandler().filter(Entity1_15Types.EntityType.BEE, 15).removed();
|
||||
registerMetaHandler().filter(Entity1_15Types.EntityType.BEE, 16).removed();
|
||||
|
||||
mapEntity(Entity1_15Types.EntityType.BEE, Entity1_15Types.EntityType.PUFFER_FISH).mobName("Bee").spawnMetadata(storage -> {
|
||||
mapEntity(Entity1_15Types.EntityType.BEE, Entity1_15Types.EntityType.PUFFER_FISH).jsonName("Bee").spawnMetadata(storage -> {
|
||||
storage.add(new Metadata(14, MetaType1_14.Boolean, false));
|
||||
storage.add(new Metadata(15, MetaType1_14.VarInt, 2));
|
||||
});
|
||||
|
@ -3,6 +3,7 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
|
||||
import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_15Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_16Types;
|
||||
import us.myles.ViaVersion.api.entities.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
@ -57,7 +58,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
Metadata meta = e.getData();
|
||||
MetaType type = meta.getMetaType();
|
||||
if (type == MetaType1_14.Slot) {
|
||||
meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
|
||||
meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue()));
|
||||
} else if (type == MetaType1_14.BlockID) {
|
||||
meta.setValue(Protocol1_15_2To1_16.getNewBlockStateId((int) meta.getValue()));
|
||||
} else if (type == MetaType1_14.PARTICLE) {
|
||||
@ -67,7 +68,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
return meta;
|
||||
});
|
||||
|
||||
mapEntity(Entity1_16Types.EntityType.HOGLIN, Entity1_16Types.EntityType.COW).mobName("Hoglin");
|
||||
mapEntity(Entity1_16Types.EntityType.HOGLIN, Entity1_16Types.EntityType.COW).jsonName("Hoglin");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,8 +78,8 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
|
||||
@Override
|
||||
protected int getOldEntityId(int newId) {
|
||||
if (newId == 100) {
|
||||
return Entity1_16Types.EntityType.COW.getId();
|
||||
if (newId == Entity1_16Types.EntityType.HOGLIN.getId()) {
|
||||
return Entity1_15Types.EntityType.COW.getId();
|
||||
}
|
||||
return newId;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
package nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.packets;
|
||||
|
||||
import nl.matsv.viabackwards.ViaBackwards;
|
||||
import nl.matsv.viabackwards.api.entities.storage.EntityData;
|
||||
import nl.matsv.viabackwards.api.entities.storage.MetaStorage;
|
||||
import nl.matsv.viabackwards.api.exceptions.RemovedValueException;
|
||||
@ -18,7 +17,6 @@ import nl.matsv.viabackwards.api.rewriters.LegacyEntityRewriter;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
|
||||
import nl.matsv.viabackwards.utils.Block;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
@ -57,26 +55,7 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
|
||||
// Track Entity
|
||||
handler(getObjectTrackerHandler());
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Optional<Entity1_11Types.ObjectType> type = Entity1_11Types.ObjectType.findById(wrapper.get(Type.BYTE, 0));
|
||||
|
||||
if (type.isPresent()) {
|
||||
EntityData data = getObjectData(type.get());
|
||||
if (data != null) {
|
||||
wrapper.set(Type.BYTE, 0, ((Integer) data.getReplacementId()).byteValue());
|
||||
if (data.getObjectData() != -1)
|
||||
wrapper.set(Type.INT, 0, data.getObjectData());
|
||||
}
|
||||
} else {
|
||||
if (Via.getManager().isDebug()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Could not find Entity Type" + wrapper.get(Type.BYTE, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
handler(getObjectRewriter(id -> Entity1_11Types.ObjectType.findById(id).orElse(null)));
|
||||
|
||||
// Handle FallingBlock blocks
|
||||
handler(new PacketHandler() {
|
||||
@ -144,7 +123,7 @@ public class EntityPackets1_10 extends LegacyEntityRewriter<Protocol1_9_4To1_10>
|
||||
if (entityData != null) {
|
||||
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.getReplacementId());
|
||||
if (entityData.hasBaseMeta())
|
||||
entityData.getDefaultMeta().handle(storage);
|
||||
entityData.getDefaultMeta().createMeta(storage);
|
||||
}
|
||||
|
||||
// Rewrite Metadata
|
||||
|
@ -5517,10 +5517,10 @@
|
||||
"block.bone_block.place": "block.lantern.place",
|
||||
"block.bone_block.step": "block.lantern.step",
|
||||
"block.roots.break": "block.crop.break",
|
||||
"block.roots.step": "block.crop.step",
|
||||
"block.roots.place": "block.crop.place",
|
||||
"block.roots.hit": "block.crop.hit",
|
||||
"block.roots.fall": "block.crop.fall",
|
||||
"block.roots.step": "block.grass.step",
|
||||
"block.roots.place": "block.grass.place",
|
||||
"block.roots.hit": "block.grass.hit",
|
||||
"block.roots.fall": "block.grass.fall",
|
||||
"block.nether_bricks.break": "block.metal.break",
|
||||
"block.nether_bricks.step": "block.metal.step",
|
||||
"block.nether_bricks.place": "block.metal.place",
|
||||
@ -5542,10 +5542,10 @@
|
||||
"block.nether_sprouts.hit": "block.sand.hit",
|
||||
"block.nether_sprouts.fall": "block.sand.fall",
|
||||
"block.fungi.break": "block.grass.break",
|
||||
"block.fungi.step": "block.sweet_berry_bush.step",
|
||||
"block.fungi.place": "block.sweet_berry_bush.place",
|
||||
"block.fungi.hit": "block.sweet_berry_bush.hit",
|
||||
"block.fungi.fall": "block.sweet_berry_bush.fall",
|
||||
"block.fungi.step": "block.grass.step",
|
||||
"block.fungi.place": "block.grass.place",
|
||||
"block.fungi.hit": "block.grass.hit",
|
||||
"block.fungi.fall": "block.grass.fall",
|
||||
"block.weeping_vines.break": "block.wet_grass.break",
|
||||
"block.weeping_vines.step": "block.wet_grass.step",
|
||||
"block.weeping_vines.place": "block.wet_grass.place",
|
||||
|
Loading…
Reference in New Issue
Block a user