Skip to content

Commit

Permalink
Hopefully fix the packet error
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Nov 19, 2024
1 parent f5d35ac commit c39264b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import eu.pb4.destroythemonument.game.data.TeamData;
import eu.pb4.destroythemonument.game.map.GameMap;
import eu.pb4.destroythemonument.items.DtmItems;
import eu.pb4.destroythemonument.mixin.LivingEntityAccessor;
import eu.pb4.destroythemonument.other.DtmResetable;
import eu.pb4.destroythemonument.game.playerclass.PlayerClass;
import eu.pb4.destroythemonument.game.playerclass.ClassRegistry;
Expand All @@ -27,6 +28,7 @@
import net.minecraft.block.Blocks;
import net.minecraft.entity.*;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerAbilities;
Expand Down Expand Up @@ -297,6 +299,7 @@ protected EventResult onServerPacket(ServerPlayerEntity player, Packet<?> packet
}
}

@SuppressWarnings("unchecked")
protected Packet<ClientPlayPacketListener> transformPacket(ServerPlayerEntity player, Packet<?> packet) {
if (packet instanceof BundleS2CPacket bundleS2CPacket) {
var list = new ArrayList<Packet<? super ClientPlayPacketListener>>();
Expand Down Expand Up @@ -336,7 +339,18 @@ protected Packet<ClientPlayPacketListener> transformPacket(ServerPlayerEntity pl
var data = this.participants.get(PlayerRef.of(player));
var data2 = this.participants.get(PlayerRef.of(target));
if (data != null && data2 != null && data.teamData.team != data2.teamData.team) {
trackerUpdateS2CPacket.trackedValues().removeIf(x -> x.id() == 9);
var list = new ArrayList<DataTracker.SerializedEntry<?>>(trackerUpdateS2CPacket.trackedValues().size());

var modified = false;
for (var entry : trackerUpdateS2CPacket.trackedValues()) {
if (entry.id() == LivingEntityAccessor.getHEALTH().id()) {
modified = true;
} else {
list.add(entry);
}
}
//noinspection ConstantValue
return modified ? PolymerEntityUtils.setEntityContext(new EntityTrackerUpdateS2CPacket(trackerUpdateS2CPacket.id(), list), target) : (Packet<ClientPlayPacketListener>) packet;
}
}
return (Packet<ClientPlayPacketListener>) packet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package eu.pb4.destroythemonument.mixin;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.data.TrackedData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(LivingEntity.class)
public interface LivingEntityAccessor {
@Accessor
static TrackedData<Float> getHEALTH() {
throw new UnsupportedOperationException();
}
}
1 change: 1 addition & 0 deletions src/main/resources/destroythemonument.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"AttributeContainerMixin",
"LivingEntityAccessor",
"ServerPlayerInteractionManagerMixin"
],
"injectors": {
Expand Down

0 comments on commit c39264b

Please sign in to comment.