PlayerEquipmentFix.java
net.minecraft.util.datafix.fixes.PlayerEquipmentFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.PlayerEquipmentFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/PlayerEquipmentFix.java
- 起始行号:L11
- 继承:DataFix
- 职责:
TODO
字段/常量
SLOT_TRANSLATIONS- 类型:
Map<Integer,String> - 修饰符:
private static final - 源码定位:
L12 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public PlayerEquipmentFix(Schema outputSchema) @ L14
- 构造器名:PlayerEquipmentFix
- 源码定位:L14
- 修饰符:public
参数:
- outputSchema: Schema
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected TypeRewriteRule makeRule() @ L18
- 方法名:makeRule
- 源码定位:L18
- 返回类型:TypeRewriteRule
- 修饰符:protected
参数:
- 无
说明:
TODO
代码
public class PlayerEquipmentFix extends DataFix {
private static final Map<Integer, String> SLOT_TRANSLATIONS = Map.of(100, "feet", 101, "legs", 102, "chest", 103, "head", -106, "offhand");
public PlayerEquipmentFix(Schema outputSchema) {
super(outputSchema, true);
}
@Override
protected TypeRewriteRule makeRule() {
Type<?> oldPlayerType = this.getInputSchema().getTypeRaw(References.PLAYER);
Type<?> newPlayerType = this.getOutputSchema().getTypeRaw(References.PLAYER);
return this.writeFixAndRead("Player Equipment Fix", oldPlayerType, newPlayerType, tag -> {
Map<Dynamic<?>, Dynamic<?>> equipment = new HashMap<>();
tag = tag.update("Inventory", inventory -> inventory.createList(inventory.asStream().filter(item -> {
int inventorySlot = item.get("Slot").asInt(-1);
String equipmentSlot = SLOT_TRANSLATIONS.get(inventorySlot);
if (equipmentSlot != null) {
equipment.put(inventory.createString(equipmentSlot), item.remove("Slot"));
}
return equipmentSlot == null;
})));
return tag.set("equipment", tag.createMap(equipment));
});
}
}引用的其他类
- Schema
- 引用位置:
参数
- 引用位置: