Skip to content

Commit

Permalink
Map first float of 1.21.4 custom model data as int for 1.21.3 clients
Browse files Browse the repository at this point in the history
Closes #939
  • Loading branch information
FlorianMichael committed Dec 19, 2024
1 parent 0dc7b47 commit fccee1f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -59,6 +60,7 @@ private void loadFields() {
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);
}

Expand Down Expand Up @@ -107,6 +109,11 @@ public boolean mapDarknessEffect() {
return mapDarknessEffect;
}

@Override
public boolean mapCustomModelData() {
return mapCustomModelData;
}

@Override
public boolean suppressEmulationWarnings() {
return suppressEmulationWarnings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -95,6 +96,11 @@ public Item handleItemToClient(final UserConnection connection, final Item item)
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 = Float.floatToIntBits(modelData.floats()[0]);
dataContainer.set(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5, data);
}
}

downgradeItemData(item);
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/resources/assets/viabackwards/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fccee1f

Please sign in to comment.