Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = (int) 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