Skip to content

Commit

Permalink
Fix neoforge mixin (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 15, 2024
1 parent 9bcb1b2 commit e45698d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.izzel.arclight.common.mixin.core.server.level;

import com.google.common.collect.Lists;
import com.mojang.datafixers.util.Pair;
import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.core.world.ServerEntityBridge;
import io.izzel.arclight.common.mod.ArclightConstants;
Expand All @@ -10,13 +8,9 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket;
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
import net.minecraft.network.protocol.game.VecDeltaCodec;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerEntity;
Expand All @@ -25,9 +19,7 @@
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.entity.projectile.AbstractArrow;
Expand All @@ -46,11 +38,11 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -256,58 +248,18 @@ public void sendChanges() {
}
}

/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void sendPairingData(ServerPlayer player, final Consumer<Packet<?>> consumer) {
@Inject(method = "sendPairingData", cancellable = true, require = 0, at = @At("HEAD"))
private void arclight$returnIfRemoved(CallbackInfo ci) {
if (this.entity.isRemoved()) {
return;
}
Packet<?> packet = this.entity.getAddEntityPacket();
this.yHeadRotp = Mth.floor(this.entity.getYHeadRot() * 256.0f / 360.0f);
consumer.accept(packet);
if (this.trackedDataValues != null) {
consumer.accept(new ClientboundSetEntityDataPacket(this.entity.getId(), this.trackedDataValues));
}
boolean flag = this.trackDelta;
if (this.entity instanceof LivingEntity livingEntity) {
Collection<AttributeInstance> collection = livingEntity.getAttributes().getSyncableAttributes();
if (this.entity.getId() == player.getId()) {
((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false);
}
if (!collection.isEmpty()) {
consumer.accept(new ClientboundUpdateAttributesPacket(this.entity.getId(), collection));
}
if (livingEntity.isFallFlying()) {
flag = true;
}
}
this.ap = this.entity.getDeltaMovement();
if (flag && !(this.entity instanceof LivingEntity)) {
consumer.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap));
}
if (this.entity instanceof LivingEntity) {
ArrayList<Pair<EquipmentSlot, ItemStack>> list = Lists.newArrayList();
for (EquipmentSlot enumitemslot : EquipmentSlot.values()) {
ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(enumitemslot);
if (itemstack.isEmpty()) continue;
list.add(Pair.of(enumitemslot, itemstack.copy()));
}
if (!list.isEmpty()) {
consumer.accept(new ClientboundSetEquipmentPacket(this.entity.getId(), list));
}
((LivingEntity) this.entity).detectEquipmentUpdates();
ci.cancel();
}
if (!this.entity.getPassengers().isEmpty()) {
consumer.accept(new ClientboundSetPassengersPacket(this.entity));
}
if (this.entity.isPassenger()) {
consumer.accept(new ClientboundSetPassengersPacket(this.entity.getVehicle()));
}
if (this.entity instanceof Mob mob && mob.isLeashed()) {
consumer.accept(new ClientboundSetEntityLinkPacket(mob, mob.getLeashHolder()));
}

@Redirect(method = "sendPairingData", require = 0, at = @At(value = "INVOKE", target = "Ljava/util/Collection;isEmpty()Z"))
private boolean arclight$injectScaledHealth(Collection<AttributeInstance> instance, ServerPlayer player) {
if (this.entity.getId() == player.getId()) {
((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity().injectScaledMaxHealth(instance, false);
}
return instance.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ abstract class UploadFilesTask extends DefaultTask {
}
}
link("/arclight/branches/${branch.get()}/versions-snapshot/${version.get()}/${modloader}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/versions-snapshot/${version.get()}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/latest-snapshot", [type: 'link', value: "/arclight/branches/${branch.get()}/versions-snapshot/${version.get()}", cache_seconds: 3600])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/latest-snapshot", [type: 'link', value: "/arclight/branches/${branch.get()}/loaders/${modloader}/versions-snapshot/${version.get()}", cache_seconds: 3600])
if (!snapshot.get()) {
link("/arclight/branches/${branch.get()}/versions-stable/${version.get()}/${modloader}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/versions-stable/${version.get()}", [type: 'object', value: sha1])
link("/arclight/branches/${branch.get()}/latest-stable", [type: 'link', value: "/arclight/branches/${branch.get()}/versions-stable/${version.get()}", cache_seconds: 86400])
link("/arclight/branches/${branch.get()}/loaders/${modloader}/latest-stable", [type: 'link', value: "/arclight/branches/${branch.get()}/loaders/${modloader}/versions-stable/${version.get()}", cache_seconds: 86400])
}
}

Expand Down

0 comments on commit e45698d

Please sign in to comment.