|
52 | 52 |
|
53 | 53 | public class TileComponentConfig implements ITileComponent, ISpecificContainerTracker { |
54 | 54 |
|
| 55 | + public static final String LEGACY_ITEM_EJECT_KEY = SerializationConstants.EJECT + TransmissionType.ITEM.getLegacyOrdinal(); |
| 56 | + public static final String LEGACY_ITEM_CONFIG_KEY = SerializationConstants.CONFIG + TransmissionType.ITEM.getLegacyOrdinal(); |
55 | 57 | public final TileEntityMekanism tile; |
56 | 58 | private final Map<TransmissionType, ConfigInfo> configInfo = new EnumMap<>(TransmissionType.class); |
57 | 59 | private final Map<TransmissionType, List<Consumer<Direction>>> configChangeListeners = new EnumMap<>(TransmissionType.class); |
@@ -297,23 +299,39 @@ public static void read(CompoundTag configNBT, Map<TransmissionType, ConfigInfo> |
297 | 299 | } |
298 | 300 |
|
299 | 301 | public static void read(CompoundTag configNBT, Map<TransmissionType, ConfigInfo> configInfo, BiConsumer<TransmissionType, RelativeSide> onChange) { |
| 302 | + //todo 1.22 remove backcompat - check for old ITEM ordinal, switch to legacy ordinals if found |
| 303 | + boolean isLegacyData = configNBT.contains(LEGACY_ITEM_CONFIG_KEY) || configNBT.contains(LEGACY_ITEM_EJECT_KEY); |
300 | 304 | for (Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) { |
301 | 305 | TransmissionType type = entry.getKey(); |
302 | 306 | ConfigInfo info = entry.getValue(); |
303 | | - NBTUtils.setBooleanIfPresent(configNBT, SerializationConstants.EJECT + type.ordinal(), info::setEjecting); |
304 | | - String configKey = SerializationConstants.CONFIG + type.ordinal(); |
| 307 | + int ordinalToUse = isLegacyData ? type.getLegacyOrdinal() : type.ordinal(); |
| 308 | + NBTUtils.setBooleanIfPresent(configNBT, SerializationConstants.EJECT + ordinalToUse, info::setEjecting); |
| 309 | + String configKey = SerializationConstants.CONFIG + ordinalToUse; |
305 | 310 | if (configNBT.contains(configKey, Tag.TAG_INT_ARRAY)) { |
306 | | - int[] sideData = configNBT.getIntArray(configKey); |
307 | | - for (int i = 0; i < sideData.length && i < EnumUtils.SIDES.length; i++) { |
308 | | - RelativeSide side = EnumUtils.SIDES[i]; |
309 | | - if (info.setDataType(DataType.BY_ID.apply(sideData[i]), side)) { |
310 | | - onChange.accept(type, side); |
| 311 | + readConfigSides(configNBT, onChange, configKey, info, type); |
| 312 | + } else if (isLegacyData && type == TransmissionType.CHEMICAL) { |
| 313 | + //fallback to try load other types in case a machine didn't have GAS |
| 314 | + for (int legacyOrdinal = TransmissionType.CHEMICAL.getLegacyOrdinal() + 1; legacyOrdinal < TransmissionType.ITEM.getLegacyOrdinal(); legacyOrdinal++) { |
| 315 | + configKey = SerializationConstants.CONFIG + legacyOrdinal; |
| 316 | + if (configNBT.contains(configKey, Tag.TAG_INT_ARRAY)) { |
| 317 | + readConfigSides(configNBT, onChange, configKey, info, type); |
| 318 | + break; |
311 | 319 | } |
312 | 320 | } |
313 | 321 | } |
314 | 322 | } |
315 | 323 | } |
316 | 324 |
|
| 325 | + private static void readConfigSides(CompoundTag configNBT, BiConsumer<TransmissionType, RelativeSide> onChange, String configKey, ConfigInfo info, TransmissionType type) { |
| 326 | + int[] sideData = configNBT.getIntArray(configKey); |
| 327 | + for (int i = 0; i < sideData.length && i < EnumUtils.SIDES.length; i++) { |
| 328 | + RelativeSide side = EnumUtils.SIDES[i]; |
| 329 | + if (info.setDataType(DataType.BY_ID.apply(sideData[i]), side)) { |
| 330 | + onChange.accept(type, side); |
| 331 | + } |
| 332 | + } |
| 333 | + } |
| 334 | + |
317 | 335 | @Override |
318 | 336 | public CompoundTag serialize(HolderLookup.Provider provider) { |
319 | 337 | return write(configInfo, true); |
|
0 commit comments