Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1154 from creeper123123321/dev
not tested villager metadata rewriting
Dieser Commit ist enthalten in:
Commit
e60447ecd2
@ -0,0 +1,12 @@
|
||||
package us.myles.ViaVersion.api.minecraft;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class VillagerData {
|
||||
private int type;
|
||||
private int profession;
|
||||
private int level;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package us.myles.ViaVersion.api.minecraft.metadata.types;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum MetaType1_14 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
VarInt(1, Type.VAR_INT),
|
||||
Float(2, Type.FLOAT),
|
||||
String(3, Type.STRING),
|
||||
Chat(4, Type.STRING),
|
||||
OptChat(5, Type.OPTIONAL_CHAT),
|
||||
Slot(6, Type.FLAT_VAR_INT_ITEM),
|
||||
Boolean(7, Type.BOOLEAN),
|
||||
Vector3F(8, Type.ROTATION),
|
||||
Position(9, Type.POSITION),
|
||||
OptPosition(10, Type.OPTIONAL_POSITION),
|
||||
Direction(11, Type.VAR_INT),
|
||||
OptUUID(12, Type.OPTIONAL_UUID),
|
||||
BlockID(13, Type.VAR_INT),
|
||||
NBTTag(14, Type.NBT),
|
||||
PARTICLE(15, Protocol1_13_2To1_13_1.PARTICLE_TYPE),
|
||||
VillagerData(16, Type.VILLAGER_DATA),
|
||||
Discontinued(99, null);
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
||||
public static MetaType1_14 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
}
|
@ -3,10 +3,7 @@ package us.myles.ViaVersion.api.type;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
||||
import us.myles.ViaVersion.api.minecraft.EulerAngle;
|
||||
import us.myles.ViaVersion.api.minecraft.Position;
|
||||
import us.myles.ViaVersion.api.minecraft.Vector;
|
||||
import us.myles.ViaVersion.api.minecraft.*;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.type.types.*;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.*;
|
||||
@ -75,6 +72,8 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<BlockChangeRecord> BLOCK_CHANGE_RECORD = new BlockChangeRecordType();
|
||||
public static final Type<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD);
|
||||
|
||||
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
||||
|
||||
/* 1.13 Flat Item (no data) */
|
||||
public static final Type<Item> FLAT_ITEM = new FlatItemType();
|
||||
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
|
||||
|
@ -0,0 +1,23 @@
|
||||
package us.myles.ViaVersion.api.type.types.minecraft;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
public class VillagerDataType extends Type<VillagerData> {
|
||||
public VillagerDataType() {
|
||||
super(VillagerData.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VillagerData read(ByteBuf buffer) throws Exception {
|
||||
return new VillagerData(Type.VAR_INT.read(buffer), Type.VAR_INT.read(buffer), Type.VAR_INT.read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, VillagerData object) throws Exception {
|
||||
Type.VAR_INT.write(buffer, object.getType());
|
||||
Type.VAR_INT.write(buffer, object.getProfession());
|
||||
Type.VAR_INT.write(buffer, object.getLevel());
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package us.myles.ViaVersion.api.type.types.version;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
|
||||
|
||||
public class Metadata1_14Type extends MetaTypeTemplate {
|
||||
@Override
|
||||
public Metadata read(ByteBuf buffer) throws Exception {
|
||||
short index = buffer.readUnsignedByte();
|
||||
|
||||
if (index == 0xff) return null; //End of metadata
|
||||
MetaType1_14 type = MetaType1_14.byId(buffer.readByte());
|
||||
|
||||
return new Metadata(index, type, type.getType().read(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, Metadata object) throws Exception {
|
||||
if (object == null) {
|
||||
buffer.writeByte(255);
|
||||
} else {
|
||||
buffer.writeByte(object.getId());
|
||||
buffer.writeByte(object.getMetaType().getTypeID());
|
||||
object.getMetaType().getType().write(buffer, object.getValue());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package us.myles.ViaVersion.api.type.types.version;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.MetaListTypeTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataList1_14Type extends MetaListTypeTemplate {
|
||||
@Override
|
||||
public List<Metadata> read(ByteBuf buffer) throws Exception {
|
||||
List<Metadata> list = new ArrayList<>();
|
||||
Metadata meta;
|
||||
do {
|
||||
meta = Types1_14.METADATA.read(buffer);
|
||||
if (meta != null)
|
||||
list.add(meta);
|
||||
} while (meta != null);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, List<Metadata> object) throws Exception {
|
||||
for (Metadata m : object)
|
||||
Types1_14.METADATA.write(buffer, m);
|
||||
|
||||
// Write end of list
|
||||
Types1_14.METADATA.write(buffer, null);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package us.myles.ViaVersion.api.type.types.version;
|
||||
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Types1_14 {
|
||||
/**
|
||||
* Metadata list type for 1.14
|
||||
*/
|
||||
public static final Type<List<Metadata>> METADATA_LIST = new MetadataList1_14Type();
|
||||
|
||||
/**
|
||||
* Metadata type for 1.14
|
||||
*/
|
||||
public static final Type<Metadata> METADATA = new Metadata1_14Type();
|
||||
}
|
@ -3,9 +3,11 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.minecraft.VillagerData;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -30,6 +32,20 @@ public class MetadataRewriter {
|
||||
int data = (int) metadata.getValue();
|
||||
metadata.setValue(Protocol1_14To1_13_2.getNewBlockStateId(data));
|
||||
}
|
||||
|
||||
if (type.is(Entity1_14Types.EntityType.VILLAGER)) {
|
||||
if (metadata.getId() == 13) {
|
||||
// plains
|
||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.ZOMBIE_VILLAGER)) {
|
||||
if (metadata.getId() == 17) {
|
||||
// plains
|
||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
@ -41,4 +57,24 @@ public class MetadataRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getNewProfessionId(int old) {
|
||||
// profession -> career
|
||||
switch (old) {
|
||||
case 0: // farmer
|
||||
return 5;
|
||||
case 1: // librarian
|
||||
return 9;
|
||||
case 2: // priest
|
||||
return 4; // cleric
|
||||
case 3: // blacksmith
|
||||
return 1; // armorer
|
||||
case 4: // butcher
|
||||
return 2;
|
||||
case 5: // nitwit
|
||||
return 11;
|
||||
default:
|
||||
return 0; // none
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren