Vanish

Vanish

124k Downloads

Players can hear when vanished players pickup items

123456687548 opened this issue ยท 2 comments

commented

Seems to be clientside

commented

Found the packet: ItemPickupAnimationS2CPacket It is sent to the clients in the LivingEntity class in this method:

public void sendPickup(Entity item, int count) {
   if (!item.isRemoved() && !this.world.isClient && (item instanceof ItemEntity || item instanceof PersistentProjectileEntity || item instanceof ExperienceOrbEntity)) {
      ((ServerWorld)this.world).getChunkManager().sendToOtherNearbyPlayers(item, new ItemPickupAnimationS2CPacket(item.getId(), this.getId(), count));
   }
}

I haven't tested this, or even written it in an IDE, so it's liable to have some glaringly obvious issues, but this should fix it

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {
   @Inject(method = "sendPickup", at = @At("HEAD"), cancellable = true)
   private void removePickUpNoise(Entity item, int count, CallbackInfo ci) {
      if (this instanceof ServerPlayerEntity && isVanished(this.getEntityName())) {
         ci.cancel();
      }
   }
   
   // Might be worth adding a Vanish::isVanished method
   private boolean isVanished(String name) {
      for (VanishedPlayer vanishedPlayer : Vanish.INSTANCE.getVanishedPlayers()) {
         if (name.equals(vanishedPlayer.getName())) {
            return true;
         }
      }
      return false;
   }
}
commented

I think my suggestion in #14 could be applied here as well. With a mixin to the item pick up method, you could cancel the pick up, and then you could add those items directly into the player's inventory. Alternatively, the packet that sends that item pick up information to the clients could be canceled.