Map first float of 1.21.4 custom model data as int for 1.21.3 clients (#942)

This commit is contained in:
EnZaXD 2024-12-20 09:21:14 +01:00 committed by GitHub
parent 0dc7b471b8
commit b214235c04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 0 deletions

View File

@ -37,6 +37,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
private boolean bedrockAtY0;
private boolean sculkShriekersToCryingObsidian;
private boolean mapDarknessEffect;
private boolean mapCustomModelData;
private boolean suppressEmulationWarnings;
public ViaBackwardsConfig(File configFile, Logger logger) {
@ -59,6 +60,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
bedrockAtY0 = getBoolean("bedrock-at-y-0", false);
sculkShriekersToCryingObsidian = getBoolean("sculk-shriekers-to-crying-obsidian", false);
mapDarknessEffect = getBoolean("map-darkness-effect", true);
mapCustomModelData = getBoolean("map-custom-model-data", true);
suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false);
}
@ -107,6 +109,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
return mapDarknessEffect;
}
@Override
public boolean mapCustomModelData() {
return mapCustomModelData;
}
@Override
public boolean suppressEmulationWarnings() {
return suppressEmulationWarnings;

View File

@ -85,6 +85,13 @@ public interface ViaBackwardsConfig extends Config {
*/
boolean mapDarknessEffect();
/**
* If enabled, 1.21.3 clients will receive the first float of 1.21.4+ custom model data as int. Disable if you handle this change yourself.
*
* @return true if enabled
*/
boolean mapCustomModelData();
/**
* Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
*

View File

@ -22,6 +22,7 @@ import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
import com.viaversion.viabackwards.protocol.v1_21_4to1_21_2.Protocol1_21_4To1_21_2;
import com.viaversion.viaversion.api.connection.UserConnection;
@ -95,6 +96,11 @@ public final class BlockItemPacketRewriter1_21_4 extends BackwardsStructuredItem
final CustomModelData1_21_4 modelData = dataContainer.get(StructuredDataKey.CUSTOM_MODEL_DATA1_21_4);
if (modelData != null) {
saveTag(createCustomTag(item), customModelDataToTag(modelData), "custom_model_data");
if (ViaBackwards.getConfig().mapCustomModelData() && modelData.floats().length > 0) {
// Put first float as old custom model data as this is the most common replacement
final int data = (int) modelData.floats()[0];
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5, data);
}
}
downgradeItemData(item);

View File

@ -31,5 +31,8 @@ sculk-shriekers-to-crying-obsidian: true
# Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers.
map-darkness-effect: true
#
# If enabled, 1.21.3 clients will receive the first float of 1.21.4+ custom model data as int. Disable if you handle this change yourself.
map-custom-model-data: true
#
# Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
suppress-emulation-warnings: false