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

fix(hud): SynchedEntityData update fixed via forcing set method #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
@@ -1,12 +1,7 @@
package vice.sol_valheim.accessors;

import com.mojang.authlib.minecraft.client.MinecraftClient;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import vice.sol_valheim.ValheimFoodData;

public interface PlayerEntityMixinDataAccessor
{
public interface PlayerEntityMixinDataAccessor {
ValheimFoodData sol_valheim$getFoodData();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package vice.sol_valheim.extenders;

import net.minecraft.network.syncher.EntityDataAccessor;

public interface SynchedEntityDataExtender {
<T> void set(EntityDataAccessor<T> key, T value, boolean force);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import vice.sol_valheim.accessors.FoodDataPlayerAccessor;
import vice.sol_valheim.accessors.PlayerEntityMixinDataAccessor;
import vice.sol_valheim.ValheimFoodData;
import vice.sol_valheim.extenders.SynchedEntityDataExtender;

import java.util.ArrayList;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -166,7 +167,7 @@ private void onReadCustomData(CompoundTag nbt, CallbackInfo info) {
private void sol_valheim$trackData() {

#if PRE_CURRENT_MC_1_19_2
this.entityData.set(sol_valheim$DATA_ACCESSOR, sol_valheim$food_data);
((SynchedEntityDataExtender) this.entityData).set(sol_valheim$DATA_ACCESSOR, sol_valheim$food_data, true);
#elif POST_CURRENT_MC_1_20_1
this.entityData.set(sol_valheim$DATA_ACCESSOR, sol_valheim$food_data, true);
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package vice.sol_valheim.mixin;

import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
import org.apache.commons.lang3.ObjectUtils;
import org.spongepowered.asm.mixin.Mixin;
import vice.sol_valheim.extenders.SynchedEntityDataExtender;

@Mixin(SynchedEntityData.class)
public abstract class SynchedEntityDataMixin implements SynchedEntityDataExtender {
#if PRE_CURRENT_MC_1_19_2

@Override
public <T> void set(EntityDataAccessor<T> key, T value, boolean force) {
SynchedEntityData thisObject = (SynchedEntityData)(Object)this;

SynchedEntityData.DataItem<T> dataItem = thisObject.getItem(key);
if (force || ObjectUtils.notEqual(value, dataItem.getValue())) {
dataItem.setValue(value);
thisObject.entity.onSyncedDataUpdated(key);
dataItem.setDirty(true);
thisObject.isDirty = true;
}
}
#endif
}
5 changes: 4 additions & 1 deletion common/src/main/resources/1_19_2.sol_valheim.aw
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
accessWidener v2 named
accessWidener v2 named
accessible method net/minecraft/network/syncher/SynchedEntityData getItem (Lnet/minecraft/network/syncher/EntityDataAccessor;)Lnet/minecraft/network/syncher/SynchedEntityData$DataItem;
accessible field net/minecraft/network/syncher/SynchedEntityData entity Lnet/minecraft/world/entity/Entity;
accessible field net/minecraft/network/syncher/SynchedEntityData isDirty Z
3 changes: 2 additions & 1 deletion common/src/main/resources/sol_valheim-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"LivingEntityDamageAccessor",
"PlayerEntityMixin",
"ServerLevelMixin",
"ServerPlayerMixin"
"ServerPlayerMixin",
"SynchedEntityDataMixin"
],
"client": [
"LocalPlayerMixin"
Expand Down
8 changes: 6 additions & 2 deletions common/src/main/resources/sol_valheim.accesswidener
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
accessWidener v2 named
accessWidener v2 named
accessible method net/minecraft/network/syncher/SynchedEntityData getItem (Lnet/minecraft/network/syncher/EntityDataAccessor;)Lnet/minecraft/network/syncher/SynchedEntityData$DataItem;
accessible field net/minecraft/network/syncher/SynchedEntityData entity Lnet/minecraft/world/entity/Entity;
accessible field net/minecraft/network/syncher/SynchedEntityData isDirty Z

# DO NOT EDIT
# Generated by the build script. Edit 1_20_1.sol_valheim.aw instead!
# Generated by the build script. Edit 1_19_2.sol_valheim.aw instead!